-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding first unit tests * Run CI on every push * Suppress unusedresult in the test * Fixing gofmt error * Addressing PR comment
- Loading branch information
Showing
4 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ on: | |
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,9 @@ | |
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
.idea/ | ||
.vscode/ | ||
|
||
*.log | ||
|
||
vendor* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters