|
6 | 6 |
|
7 | 7 | "github.com/google/go-cmp/cmp" |
8 | 8 | v1 "k8s.io/api/core/v1" |
| 9 | + "k8s.io/apimachinery/pkg/api/resource" |
9 | 10 | ) |
10 | 11 |
|
11 | 12 | func TestFlattenTolerations(t *testing.T) { |
@@ -298,6 +299,54 @@ func TestExpandSecretVolumeSource(t *testing.T) { |
298 | 299 | } |
299 | 300 | } |
300 | 301 |
|
| 302 | +func TestFlattenEmptyDirVolumeSource(t *testing.T) { |
| 303 | + size, _ := resource.ParseQuantity("64Mi") |
| 304 | + |
| 305 | + cases := []struct { |
| 306 | + Input *v1.EmptyDirVolumeSource |
| 307 | + ExpectedOutput []interface{} |
| 308 | + }{ |
| 309 | + { |
| 310 | + &v1.EmptyDirVolumeSource{ |
| 311 | + Medium: v1.StorageMediumMemory, |
| 312 | + }, |
| 313 | + []interface{}{ |
| 314 | + map[string]interface{}{ |
| 315 | + "medium": "Memory", |
| 316 | + }, |
| 317 | + }, |
| 318 | + }, |
| 319 | + { |
| 320 | + &v1.EmptyDirVolumeSource{ |
| 321 | + Medium: v1.StorageMediumMemory, |
| 322 | + SizeLimit: &size, |
| 323 | + }, |
| 324 | + []interface{}{ |
| 325 | + map[string]interface{}{ |
| 326 | + "medium": "Memory", |
| 327 | + "size_limit": "64Mi", |
| 328 | + }, |
| 329 | + }, |
| 330 | + }, |
| 331 | + { |
| 332 | + &v1.EmptyDirVolumeSource{}, |
| 333 | + []interface{}{ |
| 334 | + map[string]interface{}{ |
| 335 | + "medium": "", |
| 336 | + }, |
| 337 | + }, |
| 338 | + }, |
| 339 | + } |
| 340 | + |
| 341 | + for _, tc := range cases { |
| 342 | + output := flattenEmptyDirVolumeSource(tc.Input) |
| 343 | + if !reflect.DeepEqual(output, tc.ExpectedOutput) { |
| 344 | + t.Fatalf("Unexpected output from flattener.\nExpected: %#v\nGiven: %#v", |
| 345 | + tc.ExpectedOutput, output) |
| 346 | + } |
| 347 | + } |
| 348 | +} |
| 349 | + |
301 | 350 | func TestFlattenConfigMapVolumeSource(t *testing.T) { |
302 | 351 | cases := []struct { |
303 | 352 | Input *v1.ConfigMapVolumeSource |
|
0 commit comments