[ATMOSPHERE-536] [stable/2023.2] ci: update go unit tests (#2074)
This is an automated cherry-pick of #1983
/assign okozachenko1203
diff --git a/roles/defaults/vars.go b/roles/defaults/vars.go
index 4c11748..0799e7d 100644
--- a/roles/defaults/vars.go
+++ b/roles/defaults/vars.go
@@ -3,6 +3,7 @@
import (
"bytes"
_ "embed"
+ "strings"
"github.com/goccy/go-yaml"
)
@@ -12,14 +13,25 @@
varsFile []byte
)
+// Define a global variable for the release value.
+var release = "main"
+
+// Function to replace the {{ release }} placeholders
+func replaceReleaseInYAML(yamlContent []byte, release string) []byte {
+ return []byte(strings.ReplaceAll(string(yamlContent), "{{ atmosphere_release }}", release))
+}
+
func GetImages() (map[string]string, error) {
+ // Replace {{ release }} with the actual release value
+ modifiedVarsFile := replaceReleaseInYAML(varsFile, release)
+
path, err := yaml.PathString("$._atmosphere_images")
if err != nil {
return nil, err
}
var images map[string]string
- if err := path.Read(bytes.NewReader(varsFile), &images); err != nil {
+ if err := path.Read(bytes.NewReader(modifiedVarsFile), &images); err != nil {
return nil, err
}
diff --git a/roles/defaults/vars_test.go b/roles/defaults/vars_test.go
index 7224a40..44e022d 100644
--- a/roles/defaults/vars_test.go
+++ b/roles/defaults/vars_test.go
@@ -28,16 +28,22 @@
// NOTE(mnaser): ParseReference does not allow both tag & digest,
// so we strip the tags from the image name.
nameWithTagSplit := strings.Split(image, "@")
- require.Len(t, nameWithTagSplit, 2)
+ // NOTE(okozachenko1203): We'll enable this again when use image digest.
+ // require.Len(t, nameWithTagSplit, 2)
nameWithTag := nameWithTagSplit[0]
- name := strings.Split(nameWithTag, ":")[0]
- digest := strings.Split(image, "@")[1]
- image := fmt.Sprintf("%s@%s", name, digest)
+ var imageRef string
+ if len(nameWithTagSplit) == 2 {
+ name := strings.Split(nameWithTag, ":")[0]
+ digest := strings.Split(image, "@")[1]
+ imageRef = fmt.Sprintf("%s@%s", name, digest)
+ } else {
+ imageRef = nameWithTag
+ }
- t.Run(image, func(t *testing.T) {
+ t.Run(imageRef, func(t *testing.T) {
t.Parallel()
- ref, err := docker.ParseReference(fmt.Sprintf("//%s", image))
+ ref, err := docker.ParseReference(fmt.Sprintf("//%s", imageRef))
require.NoError(t, err)
ctx := context.Background()