internal/blueprints: filesystem TOML tests
Move the filesystem customization tests into their own file. Additionally add tests for unmarshalling filesystem customizations from TOML, since we have added a new `minsize` tag to ensure consistency with the json tag. The new tests check the validation of the TOML input and ensures that either one or both of the `minsize` and `size` inputs are set. If both are set, the input is checked to ensure that both match.
This commit is contained in:
parent
4ddb2c300b
commit
fdf1364bb5
2 changed files with 159 additions and 62 deletions
|
|
@ -311,68 +311,6 @@ func TestNilGetTimezoneSettings(t *testing.T) {
|
|||
assert.Nil(t, retNTPServers)
|
||||
}
|
||||
|
||||
func TestGetFilesystems(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1024,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystems := TestCustomizations.GetFilesystems()
|
||||
|
||||
assert.ElementsMatch(t, expectedFilesystems, retFilesystems)
|
||||
}
|
||||
|
||||
func TestGetFilesystemsMinSize(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1024,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
{
|
||||
MinSize: 4096,
|
||||
Mountpoint: "/var",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystemsSize := TestCustomizations.GetFilesystemsMinSize()
|
||||
|
||||
assert.EqualValues(t, uint64(5120), retFilesystemsSize)
|
||||
}
|
||||
|
||||
func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1025,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
{
|
||||
MinSize: 4097,
|
||||
Mountpoint: "/var",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystemsSize := TestCustomizations.GetFilesystemsMinSize()
|
||||
|
||||
assert.EqualValues(t, uint64(5632), retFilesystemsSize)
|
||||
}
|
||||
|
||||
func TestGetOpenSCAPConfig(t *testing.T) {
|
||||
|
||||
expectedOscap := OpenSCAPCustomization{
|
||||
|
|
|
|||
159
internal/blueprint/filesystem_customizations_test.go
Normal file
159
internal/blueprint/filesystem_customizations_test.go
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
package blueprint
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetFilesystems(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1024,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystems := TestCustomizations.GetFilesystems()
|
||||
|
||||
assert.ElementsMatch(t, expectedFilesystems, retFilesystems)
|
||||
}
|
||||
|
||||
func TestGetFilesystemsMinSize(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1024,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
{
|
||||
MinSize: 4096,
|
||||
Mountpoint: "/var",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystemsSize := TestCustomizations.GetFilesystemsMinSize()
|
||||
|
||||
assert.EqualValues(t, uint64(5120), retFilesystemsSize)
|
||||
}
|
||||
|
||||
func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {
|
||||
|
||||
expectedFilesystems := []FilesystemCustomization{
|
||||
{
|
||||
MinSize: 1025,
|
||||
Mountpoint: "/",
|
||||
},
|
||||
{
|
||||
MinSize: 4097,
|
||||
Mountpoint: "/var",
|
||||
},
|
||||
}
|
||||
|
||||
TestCustomizations := Customizations{
|
||||
Filesystem: expectedFilesystems,
|
||||
}
|
||||
|
||||
retFilesystemsSize := TestCustomizations.GetFilesystemsMinSize()
|
||||
|
||||
assert.EqualValues(t, uint64(5632), retFilesystemsSize)
|
||||
}
|
||||
|
||||
func TestGetFilesystemsMinSizeTOML(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
Name string
|
||||
TOML string
|
||||
Want []FilesystemCustomization
|
||||
Error bool
|
||||
}{
|
||||
{
|
||||
Name: "size set, no minsize",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
size = 1024
|
||||
`,
|
||||
Want: []FilesystemCustomization{{MinSize: 1024, Mountpoint: "/var"}},
|
||||
Error: false,
|
||||
},
|
||||
{
|
||||
Name: "size set (string), no minsize",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
size = "1KiB"
|
||||
`,
|
||||
Want: []FilesystemCustomization{{MinSize: 1024, Mountpoint: "/var"}},
|
||||
Error: false,
|
||||
},
|
||||
{
|
||||
Name: "minsize set, no size",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
minsize = 1024
|
||||
`,
|
||||
Want: []FilesystemCustomization{{MinSize: 1024, Mountpoint: "/var"}},
|
||||
Error: false,
|
||||
},
|
||||
{
|
||||
Name: "minsize set (string), no size",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
minsize = "1KiB"
|
||||
`,
|
||||
Want: []FilesystemCustomization{{MinSize: 1024, Mountpoint: "/var"}},
|
||||
Error: false,
|
||||
},
|
||||
{
|
||||
Name: "size and minsize set",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
size = 1024
|
||||
minsize = 1024
|
||||
`,
|
||||
Want: []FilesystemCustomization{},
|
||||
Error: true,
|
||||
},
|
||||
{
|
||||
Name: "size and minsize not set",
|
||||
TOML: `
|
||||
[[customizations.filesystem]]
|
||||
mountpoint = "/var"
|
||||
`,
|
||||
Want: []FilesystemCustomization{},
|
||||
Error: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.Name, func(t *testing.T) {
|
||||
|
||||
var blueprint Blueprint
|
||||
err := toml.Unmarshal([]byte(tt.TOML), &blueprint)
|
||||
|
||||
if tt.Error {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, blueprint.Customizations)
|
||||
assert.Equal(t, tt.Want, blueprint.Customizations.Filesystem)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue