Skip to content

Commit 606b516

Browse files
committed
Add tests for FsSizeGB in MachineRootfs
1 parent 74e8356 commit 606b516

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

machine_types_test.go

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ func TestMachineRootfsJSON(t *testing.T) {
320320
input: MachineConfig{Rootfs: &MachineRootfs{Persist: MachinePersistRootfsRestart}},
321321
output: `{"init":{},"rootfs":{"persist":"restart"}}`,
322322
},
323+
{
324+
name: "rootfs with fs_size_gb",
325+
input: MachineConfig{Rootfs: &MachineRootfs{Persist: MachinePersistRootfsAlways, SizeGB: 10, FsSizeGB: 20}},
326+
output: `{"init":{},"rootfs":{"persist":"always","size_gb":10,"fs_size_gb":20}}`,
327+
},
328+
{
329+
name: "rootfs with fs_size_gb only",
330+
input: MachineConfig{Rootfs: &MachineRootfs{FsSizeGB: 15}},
331+
output: `{"init":{},"rootfs":{"fs_size_gb":15}}`,
332+
},
323333
{
324334
name: "nil rootfs omitted",
325335
input: MachineConfig{},
@@ -338,23 +348,26 @@ func TestMachineRootfsJSON(t *testing.T) {
338348

339349
t.Run("unmarshal", func(t *testing.T) {
340350
cases := []struct {
341-
name string
342-
input string
343-
persist MachinePersistRootfs
344-
sizeGB uint64
351+
name string
352+
input string
353+
persist MachinePersistRootfs
354+
sizeGB uint64
355+
fsSizeGB uint64
345356
}{
346-
{"persist and size", `{"rootfs":{"persist":"always","size_gb":10}}`, MachinePersistRootfsAlways, 10},
347-
{"persist only", `{"rootfs":{"persist":"restart"}}`, MachinePersistRootfsRestart, 0},
348-
{"size only", `{"rootfs":{"size_gb":5}}`, MachinePersistRootfsNone, 5},
349-
{"no rootfs", `{}`, MachinePersistRootfsNone, 0},
357+
{"persist and size", `{"rootfs":{"persist":"always","size_gb":10}}`, MachinePersistRootfsAlways, 10, 0},
358+
{"persist only", `{"rootfs":{"persist":"restart"}}`, MachinePersistRootfsRestart, 0, 0},
359+
{"size only", `{"rootfs":{"size_gb":5}}`, MachinePersistRootfsNone, 5, 0},
360+
{"fs_size_gb only", `{"rootfs":{"fs_size_gb":8}}`, MachinePersistRootfsNone, 0, 8},
361+
{"all fields", `{"rootfs":{"persist":"always","size_gb":10,"fs_size_gb":20}}`, MachinePersistRootfsAlways, 10, 20},
362+
{"no rootfs", `{}`, MachinePersistRootfsNone, 0, 0},
350363
}
351364
for _, tc := range cases {
352365
var mc MachineConfig
353366
if err := json.Unmarshal([]byte(tc.input), &mc); err != nil {
354367
t.Errorf("%s: unexpected error: %v", tc.name, err)
355368
continue
356369
}
357-
if tc.persist == MachinePersistRootfsNone && tc.sizeGB == 0 {
370+
if tc.persist == MachinePersistRootfsNone && tc.sizeGB == 0 && tc.fsSizeGB == 0 {
358371
if mc.Rootfs != nil {
359372
t.Errorf("%s: expected nil rootfs, got %+v", tc.name, mc.Rootfs)
360373
}
@@ -370,6 +383,9 @@ func TestMachineRootfsJSON(t *testing.T) {
370383
if mc.Rootfs.SizeGB != tc.sizeGB {
371384
t.Errorf("%s: size_gb got %d, want %d", tc.name, mc.Rootfs.SizeGB, tc.sizeGB)
372385
}
386+
if mc.Rootfs.FsSizeGB != tc.fsSizeGB {
387+
t.Errorf("%s: fs_size_gb got %d, want %d", tc.name, mc.Rootfs.FsSizeGB, tc.fsSizeGB)
388+
}
373389
}
374390
})
375391
}

0 commit comments

Comments
 (0)