diff --git a/internal/action/action_test.go b/internal/action/action_test.go index 74ac55c..d06f461 100644 --- a/internal/action/action_test.go +++ b/internal/action/action_test.go @@ -116,14 +116,16 @@ func TestDefaultActionExecutor(t *testing.T) { }, } for _, subtest := range subtests { - dae := &DefaultActionExecutor{ - read: subtest.Read, - } - a := &MockAction{ - execute: func() error { return subtest.Error }, - mode: subtest.Mode, - } - err := dae.Execute([]Action{a}) - utils.CheckError("dae.Execute()", t, subtest.ExpectedErr, err) + t.Run(subtest.Name, func(t *testing.T) { + dae := &DefaultActionExecutor{ + read: subtest.Read, + } + a := &MockAction{ + execute: func() error { return subtest.Error }, + mode: subtest.Mode, + } + err := dae.Execute([]Action{a}) + utils.CheckError("dae.Execute()", t, subtest.ExpectedErr, err) + }) } } diff --git a/internal/config/modifier_test.go b/internal/config/modifier_test.go index 04bcedc..301cac6 100644 --- a/internal/config/modifier_test.go +++ b/internal/config/modifier_test.go @@ -109,14 +109,15 @@ func TestAwsNitroNVMeModifier(t *testing.T) { ExpectedErr: fmt.Errorf("🔴 lsblk: Could not retrieve block devices"), }, } - for _, subtest := range subtests { - ds.StubGetBlockDevices = subtest.GetBlockDevices - ns.StubGetBlockDeviceMapping = subtest.GetBlockDeviceMapping + t.Run(subtest.Name, func(t *testing.T) { + ds.StubGetBlockDevices = subtest.GetBlockDevices + ns.StubGetBlockDeviceMapping = subtest.GetBlockDeviceMapping - andm := NewAwsNVMeDriverModifier(ns, ds) - err := andm.Modify(subtest.Config) - utils.CheckError("andm.Modify()", t, subtest.ExpectedErr, err) - utils.CheckOutput("andm.Modify()", t, subtest.ExpectedOutput, subtest.Config, cmp.AllowUnexported(Config{})) + andm := NewAwsNVMeDriverModifier(ns, ds) + err := andm.Modify(subtest.Config) + utils.CheckError("andm.Modify()", t, subtest.ExpectedErr, err) + utils.CheckOutput("andm.Modify()", t, subtest.ExpectedOutput, subtest.Config, cmp.AllowUnexported(Config{})) + }) } } diff --git a/internal/config/validator_test.go b/internal/config/validator_test.go index 3beff74..09fbcb9 100644 --- a/internal/config/validator_test.go +++ b/internal/config/validator_test.go @@ -381,12 +381,14 @@ func TestOwnerValidator(t *testing.T) { }, } for _, subtest := range subtests { - os.StubGetUser = subtest.GetUser - os.StubGetGroup = subtest.GetGroup + t.Run(subtest.Name, func(t *testing.T) { + os.StubGetUser = subtest.GetUser + os.StubGetGroup = subtest.GetGroup - ov := NewOwnerValidator(os) - err := ov.Validate(subtest.Config) - utils.CheckError("ov.Validate()", t, subtest.ExpectedErr, err) + ov := NewOwnerValidator(os) + err := ov.Validate(subtest.Config) + utils.CheckError("ov.Validate()", t, subtest.ExpectedErr, err) + }) } } @@ -454,8 +456,10 @@ func TestResizeThresholdValidator(t *testing.T) { }, } for _, subtest := range subtests { - rtv := NewResizeThresholdValidator() - err := rtv.Validate(subtest.Config) - utils.CheckError("rtv.Validate()", t, subtest.ExpectedErr, err) + t.Run(subtest.Name, func(t *testing.T) { + rtv := NewResizeThresholdValidator() + err := rtv.Validate(subtest.Config) + utils.CheckError("rtv.Validate()", t, subtest.ExpectedErr, err) + }) } } diff --git a/internal/model/action_test.go b/internal/model/action_test.go index 38ab266..6903e37 100644 --- a/internal/model/action_test.go +++ b/internal/model/action_test.go @@ -9,7 +9,6 @@ import ( func TestParseMode(t *testing.T) { subtests := []struct { - Name string Mode string ExpectedOutput Mode ExpectedError error @@ -41,8 +40,10 @@ func TestParseMode(t *testing.T) { }, } for _, subtest := range subtests { - m, err := ParseMode(subtest.Mode) - utils.CheckError("ParseMode()", t, subtest.ExpectedError, err) - utils.CheckOutput("ParseMode()", t, subtest.ExpectedOutput, m) + t.Run(subtest.Mode, func(t *testing.T) { + m, err := ParseMode(subtest.Mode) + utils.CheckError("ParseMode()", t, subtest.ExpectedError, err) + utils.CheckOutput("ParseMode()", t, subtest.ExpectedOutput, m) + }) } } diff --git a/internal/model/device_test.go b/internal/model/device_test.go index 21c497f..a8d999a 100644 --- a/internal/model/device_test.go +++ b/internal/model/device_test.go @@ -54,10 +54,10 @@ func TestShouldResize(t *testing.T) { ResizeThreshold: 85, FileSystemSize: 90, BlockDeviceSize: 100, - ExpectedOutput: true, + ExpectedOutput: false, }, { - Name: "Resize=❌", + Name: "Resize=❌ ", ResizeThreshold: 100, FileSystemSize: 100, BlockDeviceSize: 100, @@ -65,11 +65,13 @@ func TestShouldResize(t *testing.T) { }, } for _, subtest := range subtests { - bdm := &BlockDeviceMetrics{ - subtest.FileSystemSize, - subtest.BlockDeviceSize, - } - sr := bdm.ShouldResize(subtest.ResizeThreshold) - utils.CheckOutput("bdm.ShouldResize()", t, subtest.ExpectedOutput, sr) + t.Run(subtest.Name, func(t *testing.T) { + bdm := &BlockDeviceMetrics{ + subtest.FileSystemSize, + subtest.BlockDeviceSize, + } + sr := bdm.ShouldResize(subtest.ResizeThreshold) + utils.CheckOutput("bdm.ShouldResize()", t, subtest.ExpectedOutput, sr) + }) } } diff --git a/internal/model/file_test.go b/internal/model/file_test.go index 3d777b5..9ff83be 100644 --- a/internal/model/file_test.go +++ b/internal/model/file_test.go @@ -48,10 +48,12 @@ func TestUnmarshalYAML(t *testing.T) { }, } for _, subtest := range subtests { - var fp FilePermissions - err := yaml.Unmarshal(subtest.Yaml, &fp) - utils.CheckError("yaml.Unmarshal()", t, subtest.ExpectedErr, err) - utils.CheckOutput("yaml.Unmarshal()", t, subtest.ExpectedOutput, fp) + t.Run(subtest.Name, func(t *testing.T) { + var fp FilePermissions + err := yaml.Unmarshal(subtest.Yaml, &fp) + utils.CheckError("yaml.Unmarshal()", t, subtest.ExpectedErr, err) + utils.CheckOutput("yaml.Unmarshal()", t, subtest.ExpectedOutput, fp) + }) } } @@ -68,6 +70,8 @@ func TestPerm(t *testing.T) { }, } for _, subtest := range subtests { - utils.CheckOutput("FilePermission.Perm()", t, subtest.ExpectedOutput, subtest.FilePermission.Perm()) + t.Run(subtest.Name, func(t *testing.T) { + utils.CheckOutput("FilePermission.Perm()", t, subtest.ExpectedOutput, subtest.FilePermission.Perm()) + }) } } diff --git a/internal/model/filesystem_test.go b/internal/model/filesystem_test.go index c876947..3f0a4ac 100644 --- a/internal/model/filesystem_test.go +++ b/internal/model/filesystem_test.go @@ -36,8 +36,10 @@ func TestParseFileSystem(t *testing.T) { }, } for _, subtest := range subtests { - fs, err := ParseFileSystem(subtest.FileSystem) - utils.CheckError("ParseFileSystem()", t, subtest.ExpectedError, err) - utils.CheckOutput("ParseFileSystem()", t, subtest.ExpectedOutput, fs) + t.Run(subtest.FileSystem, func(t *testing.T) { + fs, err := ParseFileSystem(subtest.FileSystem) + utils.CheckError("ParseFileSystem()", t, subtest.ExpectedError, err) + utils.CheckOutput("ParseFileSystem()", t, subtest.ExpectedOutput, fs) + }) } } diff --git a/internal/service/device_test.go b/internal/service/device_test.go index e8a6409..e0a183a 100644 --- a/internal/service/device_test.go +++ b/internal/service/device_test.go @@ -51,11 +51,13 @@ func TestGetSize(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - lds := NewLinuxDeviceService(mrf) - size, err := lds.GetSize(subtest.Device) - utils.CheckError("lds.GetSize()", t, subtest.ExpectedError, err) - utils.CheckOutput("lds.GetSize()", t, subtest.ExpectedOutput, size) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + lds := NewLinuxDeviceService(mrf) + size, err := lds.GetSize(subtest.Device) + utils.CheckError("lds.GetSize()", t, subtest.ExpectedError, err) + utils.CheckOutput("lds.GetSize()", t, subtest.ExpectedOutput, size) + }) } } @@ -101,11 +103,13 @@ func TestGetBlockDevices(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - lds := NewLinuxDeviceService(mrf) - size, err := lds.GetBlockDevices() - utils.CheckErrorGlob("lds.GetBlockDevices()", t, subtest.ExpectedError, err) - utils.CheckOutput("lds.GetBlockDevices()", t, subtest.ExpectedOutput, size) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + lds := NewLinuxDeviceService(mrf) + size, err := lds.GetBlockDevices() + utils.CheckErrorGlob("lds.GetBlockDevices()", t, subtest.ExpectedError, err) + utils.CheckOutput("lds.GetBlockDevices()", t, subtest.ExpectedOutput, size) + }) } } @@ -230,11 +234,13 @@ func TestGetBlockDevice(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - lds := NewLinuxDeviceService(mrf) - size, err := lds.GetBlockDevice(subtest.Device) - utils.CheckErrorGlob("lds.GetBlockDevice()", t, subtest.ExpectedError, err) - utils.CheckOutput("lds.GetBlockDevice()", t, subtest.ExpectedOutput, size) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + lds := NewLinuxDeviceService(mrf) + size, err := lds.GetBlockDevice(subtest.Device) + utils.CheckErrorGlob("lds.GetBlockDevice()", t, subtest.ExpectedError, err) + utils.CheckOutput("lds.GetBlockDevice()", t, subtest.ExpectedOutput, size) + }) } } @@ -277,10 +283,12 @@ func TestMount(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - lds := NewLinuxDeviceService(mrf) - err := lds.Mount(subtest.Source, subtest.Target, subtest.Fs, subtest.Options) - utils.CheckErrorGlob("lds.Mount()", t, subtest.ExpectedError, err) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + lds := NewLinuxDeviceService(mrf) + err := lds.Mount(subtest.Source, subtest.Target, subtest.Fs, subtest.Options) + utils.CheckErrorGlob("lds.Mount()", t, subtest.ExpectedError, err) + }) } } @@ -317,9 +325,11 @@ func TestUmount(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - lds := NewLinuxDeviceService(mrf) - err := lds.Umount(subtest.Source, subtest.Target) - utils.CheckErrorGlob("lds.Umount()", t, subtest.ExpectedError, err) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + lds := NewLinuxDeviceService(mrf) + err := lds.Umount(subtest.Source, subtest.Target) + utils.CheckErrorGlob("lds.Umount()", t, subtest.ExpectedError, err) + }) } } diff --git a/internal/service/file_test.go b/internal/service/file_test.go index af6a09c..ec7cf77 100644 --- a/internal/service/file_test.go +++ b/internal/service/file_test.go @@ -56,9 +56,11 @@ func TestGetFile(t *testing.T) { }, } for _, subtest := range subtests { - output, err := ufs.GetFile(subtest.Path) - utils.ExpectErr("ufs.GetFile()", t, subtest.ShouldExpectErr, err) - utils.CheckOutput("ufs.GetFile()", t, subtest.ExpectedOutput, output) + t.Run(subtest.Name, func(t *testing.T) { + output, err := ufs.GetFile(subtest.Path) + utils.ExpectErr("ufs.GetFile()", t, subtest.ShouldExpectErr, err) + utils.CheckOutput("ufs.GetFile()", t, subtest.ExpectedOutput, output) + }) } } diff --git a/internal/service/filesystem_test.go b/internal/service/filesystem_test.go index bbfc2c1..33810b9 100644 --- a/internal/service/filesystem_test.go +++ b/internal/service/filesystem_test.go @@ -43,9 +43,11 @@ func TestFileSystemFactory(t *testing.T) { }, } for _, subtest := range subtests { - fss, err := fssf.Select(subtest.FileSystem) - utils.CheckError("fssf.Select()", t, subtest.ExpectedErr, err) - utils.CheckOutput("fssf.Select()", t, subtest.ExpectedOutput, fss, cmpopts.IgnoreUnexported(subtest.IgnoreUnexported)) + t.Run(subtest.Name, func(t *testing.T) { + fss, err := fssf.Select(subtest.FileSystem) + utils.CheckError("fssf.Select()", t, subtest.ExpectedErr, err) + utils.CheckOutput("fssf.Select()", t, subtest.ExpectedOutput, fss, cmpopts.IgnoreUnexported(subtest.IgnoreUnexported)) + }) } } @@ -94,10 +96,12 @@ mkfs.xfs: Use the -f option to force overwrite.`), }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - fss := subtest.FileSystemService(mrf) - err := fss.Format(subtest.Device) - utils.CheckError("fss.Format()", t, subtest.ExpectedError, err) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + fss := subtest.FileSystemService(mrf) + err := fss.Format(subtest.Device) + utils.CheckError("fss.Format()", t, subtest.ExpectedError, err) + }) } } @@ -148,10 +152,12 @@ func TestLabel(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - fss := subtest.FileSystemService(mrf) - err := fss.Label(subtest.Device, subtest.Label) - utils.CheckError("fss.Label()", t, subtest.ExpectedError, err) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + fss := subtest.FileSystemService(mrf) + err := fss.Label(subtest.Device, subtest.Label) + utils.CheckError("fss.Label()", t, subtest.ExpectedError, err) + }) } } func TestResize(t *testing.T) { @@ -197,10 +203,12 @@ func TestResize(t *testing.T) { }, } for _, subtest := range subtests { - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) - fss := subtest.FileSystemService(mrf) - err := fss.Resize(subtest.Device) - utils.CheckError("fss.Resize()", t, subtest.ExpectedError, err) + t.Run(subtest.Name, func(t *testing.T) { + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, subtest.RunnerOutput, subtest.RunnerError) + fss := subtest.FileSystemService(mrf) + err := fss.Resize(subtest.Device) + utils.CheckError("fss.Resize()", t, subtest.ExpectedError, err) + }) } } @@ -223,8 +231,10 @@ func TestGetFileSystem(t *testing.T) { }, } for _, subtest := range subtests { - fs := subtest.FileSystemService.GetFileSystem() - utils.CheckOutput("fss.GetFileSystem()", t, subtest.ExpectedOutput, fs) + t.Run(subtest.Name, func(t *testing.T) { + fs := subtest.FileSystemService.GetFileSystem() + utils.CheckOutput("fss.GetFileSystem()", t, subtest.ExpectedOutput, fs) + }) } } @@ -247,8 +257,10 @@ func TestGetMaximumLabelLength(t *testing.T) { }, } for _, subtest := range subtests { - fs := subtest.FileSystemService.GetMaximumLabelLength() - utils.CheckOutput("fss.GetMaximumLabelLength()", t, subtest.ExpectedOutput, fs) + t.Run(subtest.Name, func(t *testing.T) { + fs := subtest.FileSystemService.GetMaximumLabelLength() + utils.CheckOutput("fss.GetMaximumLabelLength()", t, subtest.ExpectedOutput, fs) + }) } } @@ -271,8 +283,10 @@ func TestResizeRequireMount(t *testing.T) { }, } for _, subtest := range subtests { - fs := subtest.FileSystemService.DoesResizeRequireMount() - utils.CheckOutput("fss.DoesResizeRequireMount()", t, subtest.ExpectedOutput, fs) + t.Run(subtest.Name, func(t *testing.T) { + fs := subtest.FileSystemService.DoesResizeRequireMount() + utils.CheckOutput("fss.DoesResizeRequireMount()", t, subtest.ExpectedOutput, fs) + }) } } @@ -295,8 +309,10 @@ func TestLabelRequireUnmount(t *testing.T) { }, } for _, subtest := range subtests { - fs := subtest.FileSystemService.DoesLabelRequireUnmount() - utils.CheckOutput("fss.DoesLabelRequireUnmount()", t, subtest.ExpectedOutput, fs) + t.Run(subtest.Name, func(t *testing.T) { + fs := subtest.FileSystemService.DoesLabelRequireUnmount() + utils.CheckOutput("fss.DoesLabelRequireUnmount()", t, subtest.ExpectedOutput, fs) + }) } } @@ -359,19 +375,21 @@ func TestGetFileSystemSize(t *testing.T) { }, } for _, subtest := range subtests { - var runnerOutput string - if len(subtest.RunnerOutputFile) > 0 { - data, err := os.ReadFile(subtest.RunnerOutputFile) - utils.ExpectErr("os.ReadFile()", t, false, err) - runnerOutput = string(data) - } else { - runnerOutput = subtest.RunnerOutput - } + t.Run(subtest.Name, func(t *testing.T) { + var runnerOutput string + if len(subtest.RunnerOutputFile) > 0 { + data, err := os.ReadFile(subtest.RunnerOutputFile) + utils.ExpectErr("os.ReadFile()", t, false, err) + runnerOutput = string(data) + } else { + runnerOutput = subtest.RunnerOutput + } - mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, runnerOutput, subtest.RunnerError) - fss := subtest.FileSystemService(mrf) - size, err := fss.GetSize(subtest.Device) - utils.CheckError("fss.GetSize()", t, subtest.ExpectedError, err) - utils.CheckOutput("fss.GetSize()", t, subtest.ExpectedOutput, size) + mrf := utils.NewMockRunnerFactory(subtest.RunnerBinary, subtest.RunnerArgs, runnerOutput, subtest.RunnerError) + fss := subtest.FileSystemService(mrf) + size, err := fss.GetSize(subtest.Device) + utils.CheckError("fss.GetSize()", t, subtest.ExpectedError, err) + utils.CheckOutput("fss.GetSize()", t, subtest.ExpectedOutput, size) + }) } } diff --git a/internal/service/owner_test.go b/internal/service/owner_test.go index 207b44d..b670ff6 100644 --- a/internal/service/owner_test.go +++ b/internal/service/owner_test.go @@ -61,9 +61,11 @@ func TestGetUser(t *testing.T) { }, } for _, subtest := range subtests { - user, err := uos.GetUser(subtest.User) - utils.CheckError("uos.GetUser()", t, subtest.ExpectedErr, err) - utils.CheckOutput("uos.GetUser()", t, subtest.ExpectedOutput, user) + t.Run(subtest.Name, func(t *testing.T) { + user, err := uos.GetUser(subtest.User) + utils.CheckError("uos.GetUser()", t, subtest.ExpectedErr, err) + utils.CheckOutput("uos.GetUser()", t, subtest.ExpectedOutput, user) + }) } } @@ -111,9 +113,11 @@ func TestGetGroup(t *testing.T) { }, } for _, subtest := range subtests { - user, err := uos.GetGroup(subtest.Group) - utils.CheckError("uos.GetGroup()", t, subtest.ExpectedErr, err) - utils.CheckOutput("uos.GetGroup()", t, subtest.ExpectedOutput, user) + t.Run(subtest.Name, func(t *testing.T) { + user, err := uos.GetGroup(subtest.Group) + utils.CheckError("uos.GetGroup()", t, subtest.ExpectedErr, err) + utils.CheckOutput("uos.GetGroup()", t, subtest.ExpectedOutput, user) + }) } }