debian-forge-composer/internal/cloud/awscloud/secure-instance_test.go
Sanne Raymaekers 2a621521a8 osbuildexecutor/aws.ec2: set hostname of executor via cloud-init
This way much more of the journal will be captured under the new
hostname.
2024-06-25 10:58:10 +02:00

46 lines
982 B
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'
`,
},
}
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)
}
})
}
}