Skip to content

Commit

Permalink
pkg/blueprint: Go fmt customizations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andremarianiello authored and bcl committed Mar 21, 2024
1 parent 5538c28 commit a8d116c
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions pkg/blueprint/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestCheckAllowed(t *testing.T) {
GID := 321

expectedUsers := []UserCustomization{
UserCustomization{
{
Name: "John",
Description: &Desc,
Password: &Pass,
Expand All @@ -32,7 +32,7 @@ func TestCheckAllowed(t *testing.T) {
},
}

var expectedHostname = "Hostname"
expectedHostname := "Hostname"

x := Customizations{Hostname: &expectedHostname, User: expectedUsers}

Expand All @@ -49,20 +49,17 @@ func TestCheckAllowed(t *testing.T) {
}

func TestGetHostname(t *testing.T) {

var expectedHostname = "Hostname"
expectedHostname := "Hostname"

TestCustomizations := Customizations{
Hostname: &expectedHostname,
}

retHostname := TestCustomizations.GetHostname()
assert.Equal(t, &expectedHostname, retHostname)

}

func TestGetKernel(t *testing.T) {

expectedKernel := KernelCustomization{
Append: "--test",
Name: "kernel",
Expand All @@ -78,9 +75,8 @@ func TestGetKernel(t *testing.T) {
}

func TestSSHKey(t *testing.T) {

expectedSSHKeys := []SSHKeyCustomization{
SSHKeyCustomization{
{
User: "test-user",
Key: "test-key",
},
Expand All @@ -94,11 +90,9 @@ func TestSSHKey(t *testing.T) {

assert.Equal(t, expectedSSHKeys[0].User, retUser)
assert.Equal(t, expectedSSHKeys[0].Key, retKey)

}

func TestGetUsers(t *testing.T) {

Desc := "Test descritpion"
Pass := "testpass"
Key := "testkey"
Expand All @@ -111,7 +105,7 @@ func TestGetUsers(t *testing.T) {
GID := 321

expectedUsers := []UserCustomization{
UserCustomization{
{
Name: "John",
Description: &Desc,
Password: &Pass,
Expand All @@ -134,10 +128,9 @@ func TestGetUsers(t *testing.T) {
}

func TestGetGroups(t *testing.T) {

GID := 1234
expectedGroups := []GroupCustomization{
GroupCustomization{
{
Name: "TestGroup",
GID: &GID,
},
Expand All @@ -153,7 +146,6 @@ func TestGetGroups(t *testing.T) {
}

func TestGetTimezoneSettings(t *testing.T) {

expectedTimezone := "testZONE"
expectedNTPServers := []string{
"server",
Expand All @@ -172,11 +164,9 @@ func TestGetTimezoneSettings(t *testing.T) {

assert.Equal(t, expectedTimezone, *retTimezone)
assert.Equal(t, expectedNTPServers, retNTPServers)

}

func TestGetPrimaryLocale(t *testing.T) {

expectedLanguages := []string{
"enUS",
}
Expand All @@ -198,7 +188,6 @@ func TestGetPrimaryLocale(t *testing.T) {
}

func TestGetFirewall(t *testing.T) {

expectedPorts := []string{"22", "9090"}

expectedServices := FirewallServicesCustomization{
Expand All @@ -223,7 +212,6 @@ func TestGetFirewall(t *testing.T) {
}

func TestGetServices(t *testing.T) {

expectedServices := ServicesCustomization{
Enabled: []string{"cockpit", "osbuild-composer"},
Disabled: []string{"sshd", "ftp"},
Expand All @@ -249,12 +237,10 @@ func TestError(t *testing.T) {
retError := expectedError.Error()

assert.Equal(t, expectedError.Message, retError)

}

// This tests calling all the functions on a Blueprint with no Customizations
func TestNoCustomizationsInBlueprint(t *testing.T) {

TestBP := Blueprint{}

assert.Nil(t, TestBP.Customizations.GetHostname())
Expand All @@ -275,16 +261,15 @@ func TestNoCustomizationsInBlueprint(t *testing.T) {

// This tests additional scenarios where GetPrimaryLocale() returns nil values
func TestNilGetPrimaryLocale(t *testing.T) {

//Case empty Customization
// Case empty Customization
TestCustomizationsEmpty := Customizations{}

retLanguage, retKeyboard := TestCustomizationsEmpty.GetPrimaryLocale()

assert.Nil(t, retLanguage)
assert.Nil(t, retKeyboard)

//Case empty Languages
// Case empty Languages
expectedKeyboard := "en"
expectedLocaleCustomization := LocaleCustomization{
Keyboard: &expectedKeyboard,
Expand All @@ -298,12 +283,10 @@ func TestNilGetPrimaryLocale(t *testing.T) {

assert.Nil(t, retLanguage)
assert.Equal(t, expectedKeyboard, *retKeyboard)

}

// This tests additional scenario where GetTimezoneSEtting() returns nil values
func TestNilGetTimezoneSettings(t *testing.T) {

TestCustomizationsEmpty := Customizations{}

retTimezone, retNTPServers := TestCustomizationsEmpty.GetTimezoneSettings()
Expand All @@ -313,7 +296,6 @@ func TestNilGetTimezoneSettings(t *testing.T) {
}

func TestGetFilesystems(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1024,
Expand All @@ -331,7 +313,6 @@ func TestGetFilesystems(t *testing.T) {
}

func TestGetFilesystemsMinSize(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1024,
Expand All @@ -353,7 +334,6 @@ func TestGetFilesystemsMinSize(t *testing.T) {
}

func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {

expectedFilesystems := []FilesystemCustomization{
{
MinSize: 1025,
Expand All @@ -375,7 +355,6 @@ func TestGetFilesystemsMinSizeNonSectorSize(t *testing.T) {
}

func TestGetOpenSCAPConfig(t *testing.T) {

expectedOscap := OpenSCAPCustomization{
DataStream: "test-data-stream.xml",
ProfileID: "test_profile",
Expand Down

0 comments on commit a8d116c

Please sign in to comment.