@@ -28,10 +28,12 @@ import (
28
28
29
29
const (
30
30
// Expect IP addresses to be marshalled as strings in dotted quad format.
31
- testAddressMarshaled = `"192.168.0.1"`
31
+ testAddressMarshaled = `"192.168.0.1"`
32
+ testAddressUnstructured = "192.168.0.1"
32
33
33
34
// Expect IP prefixes to be marshalled as strings in dotted quad CIDR format.
34
- testPrefixMarshaled = `"192.168.0.0/16"`
35
+ testPrefixMarshaled = `"192.168.0.0/16"`
36
+ testPrefixUnstructured = "192.168.0.0/16"
35
37
)
36
38
37
39
var (
@@ -51,6 +53,7 @@ func TestSemanticVersionCanonical(t *testing.T) {
51
53
t .Parallel ()
52
54
53
55
jsonSemver := `"1.2.3-foo+bar"`
56
+ unstructuredSemver := "1.2.3-foo+bar"
54
57
55
58
out := & v1alpha1.SemanticVersion {}
56
59
@@ -62,6 +65,9 @@ func TestSemanticVersionCanonical(t *testing.T) {
62
65
marshalled , err := out .MarshalJSON ()
63
66
require .NoError (t , err )
64
67
require .Equal (t , jsonSemver , string (marshalled ))
68
+
69
+ unstructured := out .ToUnstructured ()
70
+ require .Equal (t , unstructuredSemver , unstructured )
65
71
}
66
72
67
73
func TestSemanticVersion (t * testing.T ) {
@@ -111,13 +117,8 @@ func TestIPv4AddressUnmarshal(t *testing.T) {
111
117
112
118
output := & v1alpha1.IPv4Address {}
113
119
114
- if err := output .UnmarshalJSON (input ); err != nil {
115
- t .Fatal (err )
116
- }
117
-
118
- if ! output .Equal (testAddressUnmarshaled ) {
119
- t .Fatal ("address mismatch" )
120
- }
120
+ require .NoError (t , output .UnmarshalJSON (input ))
121
+ require .Equal (t , testAddressUnmarshaled , output .IP )
121
122
}
122
123
123
124
func TestIPv4AddressMarshal (t * testing.T ) {
@@ -126,13 +127,12 @@ func TestIPv4AddressMarshal(t *testing.T) {
126
127
input := & v1alpha1.IPv4Address {IP : testAddressUnmarshaled }
127
128
128
129
output , err := input .MarshalJSON ()
129
- if err != nil {
130
- t .Fatal ()
131
- }
130
+ require .NoError (t , err )
132
131
133
- if string (output ) != testAddressMarshaled {
134
- t .Fatal ("address mismatch" )
135
- }
132
+ require .Equal (t , testAddressMarshaled , string (output ))
133
+
134
+ unstructured := input .ToUnstructured ()
135
+ require .Equal (t , testAddressUnstructured , unstructured )
136
136
}
137
137
138
138
func TestIPv4PrefixUnmarshal (t * testing.T ) {
@@ -142,13 +142,8 @@ func TestIPv4PrefixUnmarshal(t *testing.T) {
142
142
143
143
output := & v1alpha1.IPv4Prefix {}
144
144
145
- if err := output .UnmarshalJSON (input ); err != nil {
146
- t .Fatal (nil )
147
- }
148
-
149
- if output .String () != testPrefixUnmarshaled .String () {
150
- t .Fatal ("prefix mismatch" )
151
- }
145
+ require .NoError (t , output .UnmarshalJSON (input ))
146
+ require .Equal (t , testPrefixUnmarshaled .String (), output .String ())
152
147
}
153
148
154
149
func TestIPv4PrefixMarshal (t * testing.T ) {
@@ -157,11 +152,9 @@ func TestIPv4PrefixMarshal(t *testing.T) {
157
152
input := & v1alpha1.IPv4Prefix {IPNet : testPrefixUnmarshaled }
158
153
159
154
output , err := input .MarshalJSON ()
160
- if err != nil {
161
- t .Fatal (err )
162
- }
155
+ require .NoError (t , err )
156
+ require .Equal (t , testPrefixMarshaled , string (output ))
163
157
164
- if string (output ) != testPrefixMarshaled {
165
- t .Fatal ("prefix mismatch" )
166
- }
158
+ unstructured := input .ToUnstructured ()
159
+ require .Equal (t , testPrefixUnstructured , unstructured )
167
160
}
0 commit comments