From 8c0635b512b81b45bb7e0f3edb6860b7a1471846 Mon Sep 17 00:00:00 2001 From: Matthew F Leader Date: Mon, 15 Jan 2024 13:17:09 -0500 Subject: [PATCH] remove reserialization --- schema/any_test.go | 14 ++++++-------- schema/bool_test.go | 8 -------- schema/list_test.go | 6 +----- schema/map_test.go | 6 +----- schema/object_test.go | 18 +++--------------- schema/scope_test.go | 20 ++++---------------- schema/string_test.go | 3 --- schema/util_test.go | 9 --------- 8 files changed, 15 insertions(+), 69 deletions(-) diff --git a/schema/any_test.go b/schema/any_test.go index 808c5b8..2d6f6d2 100644 --- a/schema/any_test.go +++ b/schema/any_test.go @@ -111,23 +111,21 @@ func TestAny(t *testing.T) { anyType := schema.NewAnySchema() for name, val := range validValues { + testCase := val t.Run(name, func(t *testing.T) { - unserialized, err := anyType.Unserialize(val.input) + unserialized, err := anyType.Unserialize(testCase.input) assert.NoError(t, err) - assert.Equals(t, unserialized, val.unserialized) - err = anyType.Validate(val.unserialized) + assert.Equals(t, unserialized, testCase.unserialized) + err = anyType.Validate(testCase.unserialized) assert.NoError(t, err) - serialized, err := anyType.Serialize(val.unserialized) + serialized, err := anyType.Serialize(testCase.unserialized) assert.NoError(t, err) - assert.Equals(t, serialized, val.serialized) + assert.Equals(t, serialized, testCase.serialized) unserialized2, err := anyType.Unserialize(serialized) assert.NoError(t, err) - serialized2, err := anyType.Serialize(unserialized2) - assert.NoError(t, err) // test unserialize and serialize are reversible assert.Equals(t, unserialized2, unserialized) - assert.Equals(t, serialized2, serialized) }) } diff --git a/schema/bool_test.go b/schema/bool_test.go index b8e0b7c..bca40e0 100644 --- a/schema/bool_test.go +++ b/schema/bool_test.go @@ -176,14 +176,6 @@ func TestBoolSerializationCycle(t *testing.T) { if serialized != output { t.Fatalf("Invalid value after serialization: %v", serialized) } - - unserialized2, err := boolType.Unserialize(serialized) - assert.NoError(t, err) - serialized2, err := boolType.Serialize(unserialized2) - assert.NoError(t, err) - // test unserialize and serialize are reversible - assert.Equals(t, unserialized2, output) - assert.Equals(t, serialized2, serialized) }) } } diff --git a/schema/list_test.go b/schema/list_test.go index 088ccba..704ebe6 100644 --- a/schema/list_test.go +++ b/schema/list_test.go @@ -199,10 +199,6 @@ func TestList_UnSerialize_Reversible(t *testing.T) { assert.NoError(t, err) unserialized2, err := listType.Unserialize(serialized) assert.NoError(t, err) - serialized2, err := listType.Serialize(unserialized2) - assert.NoError(t, err) - - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, unserialized) - assert.Equals(t, serialized2, serialized) } diff --git a/schema/map_test.go b/schema/map_test.go index 226372c..e26cbae 100644 --- a/schema/map_test.go +++ b/schema/map_test.go @@ -359,10 +359,6 @@ func TestMap_UnSerialize_Reversible(t *testing.T) { assert.NoError(t, err) unserialized2, err := mapType.Unserialize(serialized) assert.NoError(t, err) - serialized2, err := mapType.Serialize(unserialized2) - assert.NoError(t, err) - - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, unserialized) - assert.Equals(t, serialized2, serialized) } diff --git a/schema/object_test.go b/schema/object_test.go index b9a3fc8..b72a347 100644 --- a/schema/object_test.go +++ b/schema/object_test.go @@ -368,31 +368,22 @@ func TestTypedString(t *testing.T) { result, err := o.Unserialize(map[string]any{"t1": "Hello world!"}) assert.NoError(t, err) assert.Equals(t, result.(testStruct).T1, "Hello world!") - serialized, err := o.Serialize(result) assert.NoError(t, err) unserialized2, err := o.Unserialize(serialized) assert.NoError(t, err) - serialized2, err := o.Serialize(result) - assert.NoError(t, err) - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, result) - assert.Equals(t, serialized2, serialized) result, err = o.Unserialize(map[string]any{"t2": "Hello world!"}) assert.NoError(t, err) assert.Equals(t, *result.(testStruct).T2, "Hello world!") - serialized, err = o.Serialize(result) assert.NoError(t, err) unserialized2, err = o.Unserialize(serialized) assert.NoError(t, err) - serialized2, err = o.Serialize(result) - assert.NoError(t, err) - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, result) - assert.Equals(t, serialized2, serialized) - } func TestNonDefaultSerialization(t *testing.T) { @@ -423,10 +414,7 @@ func TestNonDefaultSerialization(t *testing.T) { assert.NoError(t, err) serialized2, err := s.Serialize(unserialized) assert.NoError(t, err) - unserialized2, err := s.Unserialize(serialized2) - assert.NoError(t, err) - // test unserialize and serialize are reversible - assert.Equals(t, unserialized2, unserialized) + // test reversiblity assert.Equals(t, serialized2, serializedData) } diff --git a/schema/scope_test.go b/schema/scope_test.go index 6f2b5e9..aa98ec1 100644 --- a/schema/scope_test.go +++ b/schema/scope_test.go @@ -189,11 +189,8 @@ func TestUnserialization(t *testing.T) { assert.NoError(t, err) unserialized2, err := scopeTestObjectAType.Unserialize(serialized) assert.NoError(t, err) - serialized2, err := scopeTestObjectAType.Serialize(result) - assert.NoError(t, err) - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, result) - assert.Equals(t, serialized2, serialized) // Now as a ptr resultPtr, err := scopeTestObjectATypePtr.Unserialize(input) @@ -204,11 +201,8 @@ func TestUnserialization(t *testing.T) { assert.NoError(t, err) unserialized2, err = scopeTestObjectATypePtr.Unserialize(serialized) assert.NoError(t, err) - serialized2, err = scopeTestObjectATypePtr.Serialize(resultPtr) - assert.NoError(t, err) - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, resultPtr) - assert.Equals(t, serialized2, serialized) // Test empty object data = `{}` @@ -220,11 +214,8 @@ func TestUnserialization(t *testing.T) { assert.NoError(t, err) unserialized2, err = scopeTestObjectEmptySchema.Unserialize(serialized) assert.NoError(t, err) - serialized2, err = scopeTestObjectEmptySchema.Serialize(result) - assert.NoError(t, err) - // test unserialize and serialize are reversible + // test reversiblity assert.Equals(t, unserialized2, result) - assert.Equals(t, serialized2, serialized) } func TestValidation(t *testing.T) { @@ -309,11 +300,8 @@ func TestSerialization(t *testing.T) { assert.NoError(t, err) serialized2, err := scopeTestObjectAType.Serialize(unserialized) assert.NoError(t, err) - unserialized2, err := scopeTestObjectAType.Unserialize(serialized2) - assert.NoError(t, err) - // test unserialize and serialize are reversible - assert.Equals(t, unserialized2, unserialized) + // test reversiblity assert.Equals(t, serialized2, serialized) } diff --git a/schema/string_test.go b/schema/string_test.go index fddc6a3..c2f74ee 100644 --- a/schema/string_test.go +++ b/schema/string_test.go @@ -154,11 +154,8 @@ func testStringSerialization( unserialized2, err := stringType.Unserialize(val2) assert.NoError(t, err) - serialized2, err := stringType.Serialize(unserialized2) - assert.NoError(t, err) // test unserialize and serialize are reversible assert.Equals(t, unserialized2, val) - assert.Equals(t, serialized2, val2) } func TestStringParameters(t *testing.T) { diff --git a/schema/util_test.go b/schema/util_test.go index d1600da..b1dafae 100644 --- a/schema/util_test.go +++ b/schema/util_test.go @@ -1,7 +1,6 @@ package schema_test import ( - "go.arcalot.io/assert" "testing" "go.flow.arcalot.io/pluginsdk/schema" @@ -55,14 +54,6 @@ func performSerializationTest[T any]( serialized, ) } - - serialized2, err := typeUnderTest.SerializeType(unserialized) - assert.NoError(t, err) - unserialized2, err := typeUnderTest.UnserializeType(serialized2) - assert.NoError(t, err) - // test unserialize and serialize are reversible - assert.Equals(t, unserialized2, unserialized) - assert.Equals(t, serialized2, serialized) }) } }