step/providers/session/session_test.go

63 lines
1.1 KiB
Go

package session
import "io"
import "reflect"
import "testing"
import "git.tebibyte.media/sashakoshka/step"
func TestEnsafenValue (test *testing.T) {
items := []any {
"hello",
123,
934.3298,
'o',
[]any {
"asljdkasd",
"90iur3e",
},
map[string] any {
"asdkiasd": 34,
"jdjjdfj": '-',
},
nil,
}
for index, item := range items {
safe, err := ensafenValue(item)
if err != nil { test.Fatal(index, err) }
test.Logf("%d: %v --> %v", index, item, safe)
if !reflect.DeepEqual(item, safe) {
test.Fatal("not equal")
}
switch item := item.(type) {
case []any, map[string] any:
if reflect.ValueOf(item).Pointer() == reflect.ValueOf(safe).Pointer() {
test.Fatal("memory wasn't duplicated")
}
}
}
}
func TestEnsafenValueErrTypeMismatch (test *testing.T) {
items := []any {
[]any {
"asljdkasd",
&struct { } { },
"90iur3e",
},
io.EOF,
[]string {
"hello",
},
map[string] any {
"asdkiasd": 34,
"jdjjdfj": struct { } { },
},
}
for index, item := range items {
safe, err := ensafenValue(item)
if err != step.ErrTypeMismatch {
test.Fatalf("%d: no error, produced %v", index, safe)
}
}
}