Skip to content

Commit

Permalink
Test customizations on TestSuccessfulClassicRun
Browse files Browse the repository at this point in the history
  • Loading branch information
upils committed Mar 19, 2024
1 parent 8aaa356 commit 64561c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/imagedefinition/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ The following specification defines what is supported in the YAML:
- <string>
- <string>
# Environment variables to set before executing the command
# Format: ENV=VALUE
env: (optional)
- <string>
- <string>
Expand All @@ -286,7 +287,7 @@ The following specification defines what is supported in the YAML:
# The name of the group to create.
name: <string>
# The GID to assign to this group.
gid: <string> (optional)
id: <string> (optional)
# Set a custom fstab. The existing one (if any) will be truncated.
fstab: (optional)
-
Expand Down
46 changes: 46 additions & 0 deletions internal/statemachine/classic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,52 @@ func TestSuccessfulClassicRun(t *testing.T) {
t.Error("ubuntu2 user password should be expired")
}

// test addGroup customization
groupFilePath := filepath.Join(mountDir, "etc", "group")
groupFile, err := os.Open(groupFilePath)
asserter.AssertErrNil(err, true)
defer groupFile.Close()
addGroupFeatureFound := false
addGroupLine := ""

scanner = bufio.NewScanner(groupFile)

for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), "addgroupfeature") {
addGroupLine = scanner.Text()
addGroupFeatureFound = true
break
}
}

if !addGroupFeatureFound {
t.Error("addgroupfeature user not created")
}

gid := strings.Split(addGroupLine, ":")[2]

if gid != "4321" {
t.Errorf("addgroupfeature did not create the group with the right gid. Got gid %s", gid)
}

// test touch file customization
toucheFilePath := filepath.Join(mountDir, "etc", "touchfilefeature")
_, err = os.Stat(toucheFilePath)
if err != nil {
if os.IsNotExist(err) {
t.Errorf("File \"%s\" should exist, but does not", toucheFilePath)
}
}

// test execute file customization
executeFilePath := filepath.Join(mountDir, "etc", "executefeature")
executeBytes, err := os.ReadFile(executeFilePath)
asserter.AssertErrNil(err, true)
if string(executeBytes) != "test" {
t.Errorf("Expected 'test' in %s, but got %s", executeFilePath, string(executeBytes))
}

// test grub conf
grubCfg := filepath.Join(mountDir, "boot", "grub", "grub.cfg")
_, err = os.Stat(grubCfg)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions internal/statemachine/testdata/image_definitions/test_amd64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,22 @@ customization:
make-dirs:
- path: /etc/foo/bar
permissions: 0755
touch-file:
- path: /etc/touchfilefeature
execute:
- path: /usr/bin/bash
args:
- "-c"
- "echo -n 'test' > $ENV_VAR_TEST"
env:
- "ENV_VAR_TEST=/etc/executefeature"
add-user:
- name: ubuntu2
password: ubuntu2
password-type: text
add-group:
- name: addgroupfeature
id: 4321
components:
- main
- universe
Expand Down

0 comments on commit 64561c2

Please sign in to comment.