We need the ability to use different CloudWatch group for the osbuild-executor on Fedora workers in staging and production environment. Extend the worker confguration to allow configuring the CloudWatch group name used by the osbuild-executor. Extend the secure instance code to instruct cloud-init via user data to create /tmp/cloud_init_vars file with the CloudWatch group name in the osbuild-executor instance, to make it possible for the executor to configure its logging differently based on the value. Cover new changes by unit tests. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
43 lines
858 B
Go
43 lines
858 B
Go
package awscloud
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSecureInstanceUserData(t *testing.T) {
|
|
type testCase struct {
|
|
CloudWatchGroup string
|
|
ExpectedUserData string
|
|
}
|
|
|
|
testCases := []testCase{
|
|
{
|
|
ExpectedUserData: `#cloud-config
|
|
write_files:
|
|
- path: /tmp/worker-run-executor-service
|
|
content: ''
|
|
`,
|
|
},
|
|
{
|
|
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)
|
|
if userData != tc.ExpectedUserData {
|
|
t.Errorf("Expected: %s, got: %s", tc.ExpectedUserData, userData)
|
|
}
|
|
})
|
|
}
|
|
}
|