Initial commit
This commit is contained in:
29
utils/shortcuts_test.go
Normal file
29
utils/shortcuts_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func testType[T any]( t *testing.T, name string, fallback T ) T {
|
||||
got := TryGetEnv( "ABC", fallback )
|
||||
a := reflect.TypeOf( got ).Kind()
|
||||
b := reflect.TypeOf( fallback ).Kind()
|
||||
if a != b {
|
||||
t.Errorf( "%s is not of type %s", any( got ), b )
|
||||
}
|
||||
return got
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
testType( t, "ABC", "Test" )
|
||||
testType( t, "ABC", 11 )
|
||||
|
||||
os.Setenv( "ABC", "22" )
|
||||
got := testType( t, "ABC", 11 )
|
||||
if got != 22 {
|
||||
t.Errorf( "Expected 22, got %d", got )
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user