mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-30 02:40:33 +00:00
38 lines
718 B
Go
38 lines
718 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"git.sr.ht/~ashkeel/containers/sync"
|
|
)
|
|
|
|
func TestLoadJSONToWrapped(t *testing.T) {
|
|
// Create test struct and object
|
|
type test struct {
|
|
TestValue string
|
|
}
|
|
testObj := test{
|
|
TestValue: "test",
|
|
}
|
|
|
|
// Encode test object to JSON
|
|
testByt, err := json.Marshal(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](string(testByt), 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")
|
|
}
|
|
}
|