Skip to content

Commit

Permalink
remove reserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleader committed Jan 15, 2024
1 parent 7564b29 commit 8c0635b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 69 deletions.
14 changes: 6 additions & 8 deletions schema/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
8 changes: 0 additions & 8 deletions schema/bool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down
6 changes: 1 addition & 5 deletions schema/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 1 addition & 5 deletions schema/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 3 additions & 15 deletions schema/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down
20 changes: 4 additions & 16 deletions schema/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 = `{}`
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 0 additions & 3 deletions schema/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions schema/util_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package schema_test

import (
"go.arcalot.io/assert"
"testing"

"go.flow.arcalot.io/pluginsdk/schema"
Expand Down Expand Up @@ -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)
})
}
}

0 comments on commit 8c0635b

Please sign in to comment.