Skip to content

Commit

Permalink
chore: Add first unit tests (#124)
Browse files Browse the repository at this point in the history
* Adding first unit tests

* Run CI on every push

* Suppress unusedresult in the test

* Fixing gofmt error

* Addressing PR comment
  • Loading branch information
Gmerold committed Jan 26, 2024
1 parent 4ca9c5a commit 4e53c05
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
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

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

0 comments on commit 4e53c05

Please sign in to comment.