forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Katrina Rogan
authored
Mar 13, 2021
1 parent
d110778
commit 4f22a59
Showing
6 changed files
with
268 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package utils | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/go-test/deep" | ||
structpb "github.com/golang/protobuf/ptypes/struct" | ||
"github.com/stretchr/testify/assert" | ||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestUnmarshalStructToObj(t *testing.T) { | ||
t.Run("no nil structs allowed", func(t *testing.T) { | ||
var podSpec v1.PodSpec | ||
err := UnmarshalStructToObj(nil, &podSpec) | ||
assert.EqualError(t, err, "nil Struct Object passed") | ||
}) | ||
podSpec := v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "a container", | ||
}, | ||
{ | ||
Name: "another container", | ||
}, | ||
}, | ||
} | ||
|
||
b, err := json.Marshal(podSpec) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
structObj := &structpb.Struct{} | ||
if err := json.Unmarshal(b, structObj); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
t.Run("no nil pointers as obj allowed", func(t *testing.T) { | ||
var nilPodspec *v1.PodSpec | ||
err := UnmarshalStructToObj(structObj, nilPodspec) | ||
assert.EqualError(t, err, "json: Unmarshal(nil *v1.PodSpec)") | ||
}) | ||
|
||
t.Run("happy case", func(t *testing.T) { | ||
var podSpecObj v1.PodSpec | ||
err := UnmarshalStructToObj(structObj, &podSpecObj) | ||
assert.NoError(t, err) | ||
if diff := deep.Equal(podSpecObj, podSpec); diff != nil { | ||
t.Errorf("UnmarshalStructToObj() got = %v, want %v, diff: %v", podSpecObj, podSpec, diff) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters