Skip to content

Commit a57fe45

Browse files
committed
simplify utils tests
1 parent 878718c commit a57fe45

File tree

1 file changed

+28
-74
lines changed

1 file changed

+28
-74
lines changed

aks-node-controller/pkg/nodeconfigutils/utils_test.go

Lines changed: 28 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,6 @@ func TestUnmarshalConfigurationV1(t *testing.T) {
6161
},
6262
wantErr: true,
6363
},
64-
{
65-
name: "string is assigned with a boolean value",
66-
data: []byte(`{
67-
"version": "v1",
68-
"linux_admin_username": true,
69-
"auth_config": {
70-
"subscription_id": "test-subscription"
71-
}
72-
}`),
73-
want: &aksnodeconfigv1.Configuration{
74-
Version: "v1",
75-
AuthConfig: &aksnodeconfigv1.AuthConfig{
76-
SubscriptionId: "test-subscription",
77-
},
78-
},
79-
wantErr: true,
80-
},
8164
{
8265
name: "unknown field should be ignored",
8366
data: []byte(`{
@@ -131,63 +114,6 @@ func TestUnmarshalConfigurationV1(t *testing.T) {
131114
},
132115
wantErr: false,
133116
},
134-
{
135-
name: "repeated string field with wrong type is ignored",
136-
data: []byte(`{
137-
"version": "v1",
138-
"auth_config": {
139-
"subscription_id": "test-subscription"
140-
},
141-
"custom_ca_certs": "not-an-array"
142-
}`),
143-
want: &aksnodeconfigv1.Configuration{
144-
Version: "v1",
145-
AuthConfig: &aksnodeconfigv1.AuthConfig{
146-
SubscriptionId: "test-subscription",
147-
},
148-
},
149-
wantErr: true,
150-
},
151-
{
152-
name: "repeated string field with mixed types parses valid elements",
153-
data: []byte(`{
154-
"version": "v1",
155-
"auth_config": {
156-
"subscription_id": "test-subscription"
157-
},
158-
"custom_ca_certs": ["valid-cert", 123, true]
159-
}`),
160-
want: &aksnodeconfigv1.Configuration{
161-
Version: "v1",
162-
AuthConfig: &aksnodeconfigv1.AuthConfig{
163-
SubscriptionId: "test-subscription",
164-
},
165-
CustomCaCerts: []string{"valid-cert"},
166-
},
167-
wantErr: true,
168-
},
169-
{
170-
name: "map field with wrong value type is ignored",
171-
data: []byte(`{
172-
"version": "v1",
173-
"auth_config": {
174-
"subscription_id": "test-subscription"
175-
},
176-
"kubelet_config": {
177-
"kubelet_flags": {
178-
"key1": "value1",
179-
"key2": 123
180-
}
181-
}
182-
}`),
183-
want: &aksnodeconfigv1.Configuration{
184-
Version: "v1",
185-
AuthConfig: &aksnodeconfigv1.AuthConfig{
186-
SubscriptionId: "test-subscription",
187-
},
188-
},
189-
wantErr: true,
190-
},
191117
{
192118
name: "optional int32 field with string value is ignored",
193119
data: []byte(`{
@@ -277,3 +203,31 @@ func TestMarsalConfiguratioV1(t *testing.T) {
277203
require.NoError(t, err)
278204
require.JSONEq(t, `{"version":"v1","auth_config":{"subscription_id":"test-subscription"}, "workload_runtime":"WORKLOAD_RUNTIME_OCI_CONTAINER"}`, string(data))
279205
}
206+
207+
func TestMarshalUnmarshalWithPopulatedConfig(t *testing.T) {
208+
t.Run("fully populated config marshals to >100 bytes", func(t *testing.T) {
209+
cfg := &aksnodeconfigv1.Configuration{}
210+
PopulateAllFields(cfg)
211+
212+
marshaled, err := MarshalConfigurationV1(cfg)
213+
require.NoError(t, err)
214+
assert.Greater(t, len(marshaled), 100, "Fully populated config should marshal to >100 bytes")
215+
t.Logf("Marshaled %d bytes", len(marshaled))
216+
})
217+
218+
t.Run("marshal and unmarshal round-trip preserves data", func(t *testing.T) {
219+
original := &aksnodeconfigv1.Configuration{}
220+
PopulateAllFields(original)
221+
222+
// Marshal
223+
marshaled, err := MarshalConfigurationV1(original)
224+
require.NoError(t, err)
225+
226+
// Unmarshal
227+
restored, err := UnmarshalConfigurationV1(marshaled)
228+
require.NoError(t, err)
229+
230+
// Verify key fields preserved
231+
assert.Equal(t, original, restored)
232+
})
233+
}

0 commit comments

Comments
 (0)