1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-18 01:50:50 +00:00
strimertul/utils/json_test.go

38 lines
757 B
Go
Raw Normal View History

package utils
import (
"git.sr.ht/~hamcha/containers/sync"
jsoniter "github.com/json-iterator/go"
"testing"
)
func TestLoadJSONToWrapped(t *testing.T) {
// Create test struct and object
type test struct {
TestValue string
}
testObj := test{
TestValue: "test",
}
// Encode test object to JSON
testStr, err := jsoniter.ConfigFastest.MarshalToString(testObj)
if err != nil {
t.Fatal(err)
}
// Create a wrapped instance of the test object
wrapped := sync.NewSync[test](test{})
// Load JSON to wrapped
err = LoadJSONToWrapped[test](testStr, wrapped)
if err != nil {
t.Fatal(err)
}
// Get the wrapped value and compare to original
if wrapped.Get().TestValue != testObj.TestValue {
t.Fatal("JSON was not loaded correctly")
}
}