The conditional only checked if the cloudwatch group was set, and if it wasn't, the hostname variable wouldn't be set either. So the executor would try to look for a hostname but not find any.
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package awscloud
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSecureInstanceUserData(t *testing.T) {
|
|
type testCase struct {
|
|
CloudWatchGroup string
|
|
Hostname string
|
|
ExpectedUserData string
|
|
}
|
|
|
|
testCases := []testCase{
|
|
{
|
|
ExpectedUserData: `#cloud-config
|
|
write_files:
|
|
- path: /tmp/worker-run-executor-service
|
|
content: ''
|
|
`,
|
|
},
|
|
{
|
|
CloudWatchGroup: "test-group",
|
|
Hostname: "test-hostname",
|
|
ExpectedUserData: `#cloud-config
|
|
write_files:
|
|
- path: /tmp/worker-run-executor-service
|
|
content: ''
|
|
- path: /tmp/cloud_init_vars
|
|
content: |
|
|
OSBUILD_EXECUTOR_CLOUDWATCH_GROUP='test-group'
|
|
OSBUILD_EXECUTOR_HOSTNAME='test-hostname'
|
|
`,
|
|
},
|
|
{
|
|
Hostname: "test-hostname",
|
|
ExpectedUserData: `#cloud-config
|
|
write_files:
|
|
- path: /tmp/worker-run-executor-service
|
|
content: ''
|
|
- path: /tmp/cloud_init_vars
|
|
content: |
|
|
OSBUILD_EXECUTOR_HOSTNAME='test-hostname'
|
|
`,
|
|
},
|
|
{
|
|
CloudWatchGroup: "test-group",
|
|
ExpectedUserData: `#cloud-config
|
|
write_files:
|
|
- path: /tmp/worker-run-executor-service
|
|
content: ''
|
|
- path: /tmp/cloud_init_vars
|
|
content: |
|
|
OSBUILD_EXECUTOR_CLOUDWATCH_GROUP='test-group'
|
|
`,
|
|
}}
|
|
|
|
for idx, tc := range testCases {
|
|
t.Run(fmt.Sprintf("Test case %d", idx), func(t *testing.T) {
|
|
userData := SecureInstanceUserData(tc.CloudWatchGroup, tc.Hostname)
|
|
if userData != tc.ExpectedUserData {
|
|
t.Errorf("Expected: %s, got: %s", tc.ExpectedUserData, userData)
|
|
}
|
|
})
|
|
}
|
|
}
|