Skip to content

Commit

Permalink
Merge pull request #13 from hammingweight/add-more-object-tests
Browse files Browse the repository at this point in the history
Add more SynkObject tests.
  • Loading branch information
hammingweight authored Jan 12, 2025
2 parents 1a4dde5 + f2996ac commit eb1ad6b
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion rest/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ limitations under the License.

package rest

import "testing"
import (
"encoding/json"
"testing"
)

func TestExtractOk(t *testing.T) {
o := SynkObject{}
Expand Down Expand Up @@ -49,3 +52,35 @@ func TestNoSuchKey(t *testing.T) {
t.Error("no SynkObject should have been returned")
}
}

func TestGet(t *testing.T) {
o := SynkObject{"foo": 3, "bar": "baz"}
v, ok := o.Get("foo")
if !ok {
t.Error("Couldn't retrieve key foo")
}
if v != 3 {
t.Errorf("Expected value 3, got %d", v)
}
_, ok = o.Get("baz")
if ok {
t.Error("Retrieved non-existent key baz")
}
}

func TestString(t *testing.T) {
// Test that the String method returns valid JSON
s := SynkObject{"foo": 3, "bar": "baz"}.String()
data := map[string]any{}
err := json.Unmarshal([]byte(s), &data)
if err != nil {
t.Fatal(err)
}
if len(data) != 2 {
t.Errorf("Expected 2 keys, got %d", len(data))
}
_, ok := data["foo"]
if !ok {
t.Error("Couldn't retrieve key foo")
}
}

0 comments on commit eb1ad6b

Please sign in to comment.