Skip to content

Commit

Permalink
internal/blueprint: Go fmt customizations test
Browse files Browse the repository at this point in the history
  • Loading branch information
andremarianiello committed Mar 28, 2024
1 parent 3653c80 commit 4adc0b3
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions internal/blueprint/customizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCheckAllowed(t *testing.T) {
GID := 321

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

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

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

Expand All @@ -50,20 +50,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 @@ -79,9 +76,8 @@ func TestGetKernel(t *testing.T) {
}

func TestSSHKey(t *testing.T) {

expectedSSHKeys := []SSHKeyCustomization{
SSHKeyCustomization{
{
User: "test-user",
Key: "test-key",
},
Expand All @@ -95,11 +91,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 @@ -113,7 +107,7 @@ func TestGetUsers(t *testing.T) {
ExpireDate := 12345

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

func TestGetGroups(t *testing.T) {

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

func TestGetTimezoneSettings(t *testing.T) {

expectedTimezone := "testZONE"
expectedNTPServers := []string{
"server",
Expand All @@ -175,11 +167,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 @@ -201,7 +191,6 @@ func TestGetPrimaryLocale(t *testing.T) {
}

func TestGetFirewall(t *testing.T) {

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

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

func TestGetServices(t *testing.T) {

expectedServices := ServicesCustomization{
Enabled: []string{"cockpit", "osbuild-composer"},
Disabled: []string{"sshd", "ftp"},
Expand All @@ -252,12 +240,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 @@ -278,16 +264,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 @@ -301,12 +286,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 @@ -316,7 +299,6 @@ func TestNilGetTimezoneSettings(t *testing.T) {
}

func TestGetOpenSCAPConfig(t *testing.T) {

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

0 comments on commit 4adc0b3

Please sign in to comment.