Skip to content

Commit

Permalink
TestNotifyConfigUpdateWithAgentYaml updates
Browse files Browse the repository at this point in the history
to verify the behavior of Landscape client config tags:
 - tags=wsl by default
 - preserve user provided tags otherwise

And use goldens to ease coping with serialization mismatches.
  • Loading branch information
CarlosNihelton committed Jun 26, 2024
1 parent 63c4324 commit 1ba7b03
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 12 deletions.
26 changes: 14 additions & 12 deletions windows-agent/internal/proservices/landscape/landscape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,13 +919,12 @@ func TestNotifyConfigUpdateWithAgentYaml(t *testing.T) {

testcases := map[string]struct {
conf string

want string
wantNotInAgentYaml []string
}{

"Task and agent.yaml don't contain [host] section": {conf: "[host]\nurl=localhost\n[client]\ncomputer_title=another\n", want: "[client]\ncomputer_title=another\n", wantNotInAgentYaml: []string{"host:", "url:"}},
"Task and agent.yaml only contains [client] section)": {conf: "[irrelevant]\nnothing=important\n[host]\nurl=localhost\n[client]\ncomputer_title=another\n", want: "[client]\ncomputer_title=another\n", wantNotInAgentYaml: []string{"irrelevant:", "nothing:", "host:", "url:"}},
"Task and agent.yaml don't contain [host] section": {conf: "[host]\nurl=localhost\n[client]\ncomputer_title=another\n"},
"Task and agent.yaml only contains [client] section)": {conf: "[irrelevant]\nnothing=important\n[host]\nurl=localhost\n[client]\ncomputer_title=another\n"},
"Task and agent.yaml with default tags": {conf: "[host]\nurl=localhost\n[client]\ncomputer_title=another\n"},
"Task and agent.yaml with supplied tags": {conf: "[host]\nurl=localhost\n[client]\ntags=another\n"},
}

for name, tc := range testcases {
Expand Down Expand Up @@ -969,17 +968,20 @@ func TestNotifyConfigUpdateWithAgentYaml(t *testing.T) {

b, err := os.ReadFile(tasksFiles[0])
require.NoError(t, err, "NotifyConfigUpdate: should have caused creation of a tasks file")
task := strings.TrimSpace(strings.ReplaceAll(string(b), " ", ""))
task := string(b)
require.NotEmpty(t, task, "NotifyConfigUpdate: tasks file should not be empty")

require.Contains(t, task, tasks.LandscapeConfigure{}.String(), "NotifyConfigUpdate: tasks file should contain a LandscapeConfigure task")

basepath := testutils.TestFixturePath(t)

wantTask := testutils.LoadWithUpdateFromGolden(t, task, testutils.WithGoldenPath(filepath.Join(basepath, "golden.tasks")))
require.Equal(t, wantTask, task, "NotifyConfigUpdate: tasks file should contain the expected Landscape client config")

agentYaml, err := os.ReadFile(filepath.Join(homedir, ".cloud-init", "agent.yaml"))
require.NoError(t, err, "NotifyConfigUpdate: could not read agent.yaml")
for _, wantNot := range tc.wantNotInAgentYaml {
require.NotContains(t, agentYaml, wantNot, "NotifyConfigUpdate: agent.yaml should be empty")
}

require.Contains(t, task, tasks.LandscapeConfigure{}.String(), "NotifyConfigUpdate: tasks file should contain a LandscapeConfigure task")
require.Contains(t, task, tc.want, "NotifyConfigUpdate: tasks file should contain the expected Landscape client config")
wantAgentYaml := testutils.LoadWithUpdateFromGolden(t, string(agentYaml), testutils.WithGoldenPath(filepath.Join(basepath, "agent.yaml")))
require.Equal(t, wantAgentYaml, string(agentYaml), "NotifyConfigUpdate: tasks file and agent.yaml don't match")
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
computer_title: another
hostagent_uid: landscapeUID
tags: wsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- task:
config: |
[client]
computer_title = another
tags = wsl
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
hostagent_uid: landscapeUID
tags: another
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- task:
config: |
[client]
tags = another
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
computer_title: another
hostagent_uid: landscapeUID
tags: wsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- task:
config: |
[client]
computer_title = another
tags = wsl
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
computer_title: another
hostagent_uid: landscapeUID
tags: wsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- task:
config: |
[client]
computer_title = another
tags = wsl
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
computer_title: another
hostagent_uid: landscapeUID
tags: wsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- task:
config: |
[client]
computer_title = another
tags = wsl
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# cloud-init
# This file was generated automatically and must not be edited
landscape:
client:
hostagent_uid: landscapeUID
tags: another
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- task:
config: |
[client]
tags = another
hostagent_uid = landscapeUID
type: tasks.LandscapeConfigure

0 comments on commit 1ba7b03

Please sign in to comment.