Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add first unit tests #124

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
branches:
- main
push:
branches:
- main
gab-arrobo marked this conversation as resolved.
Show resolved Hide resolved

jobs:
build:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
#
# SPDX-License-Identifier: Apache-2.0

.idea/
.vscode/

*.log

vendor*
40 changes: 40 additions & 0 deletions common/events_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2024 Canonical Ltd.
//
// SPDX-License-Identifier: Apache-2.0
package common

import (
"bytes"
"fmt"
"testing"

"github.com/omec-project/gnbsim/logger"
"github.com/stretchr/testify/assert"
)

func TestString_ValidEventTypeReturnsEventTypeString(t *testing.T) {
for event_type, event_type_str := range evtStrMap {
t.Run(
fmt.Sprintf("Testing [%v]", event_type),
func(t *testing.T) {
out := event_type.String()
if out != event_type_str {
t.Errorf("Invalid event string %v for %v", out, event_type)
}
},
)
}
}

func TestString_InvalidEventTypeExitsWithLogMsg(t *testing.T) {
var INVALID_EVENT EventType = 0x0
var logBuf bytes.Buffer
assert := assert.New(t)
patchedExit := func(int) { panic("Dummy exit function") }

logger.AppLog.Logger.SetOutput(&logBuf)
logger.AppLog.Logger.ExitFunc = patchedExit

assert.Panics(func() { _ = INVALID_EVENT.String() })
assert.Contains(logBuf.String(), "Invalid Event ID: 0x0")
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/omec-project/ngap v1.1.0
github.com/omec-project/openapi v1.1.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/urfave/cli v1.22.14
github.com/yerden/go-util v1.1.4
golang.org/x/net v0.20.0
Expand All @@ -36,6 +37,7 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand All @@ -61,6 +63,7 @@ require (
github.com/omec-project/util_3gpp v1.1.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.26.0 // indirect
Expand Down
Loading