From 536c401f3c8420151d342e45f004523892fc446e Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Fri, 26 Jul 2024 13:49:19 +0300 Subject: [PATCH] Make test more robust because on some workers machineID may come empty making the test fail Signed-off-by: Dimitris Karakasilis --- pkg/action/render_template.go | 5 +++-- pkg/action/render_template_test.go | 7 +++++-- tests/fixtures/template/test.yaml | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/action/render_template.go b/pkg/action/render_template.go index a472e5c..ed3deaa 100644 --- a/pkg/action/render_template.go +++ b/pkg/action/render_template.go @@ -2,12 +2,13 @@ package action import ( "bytes" + "os" + "text/template" + "github.com/Masterminds/sprig/v3" "github.com/kairos-io/kairos-agent/v2/pkg/config" "github.com/kairos-io/kairos-sdk/state" "gopkg.in/yaml.v3" - "os" - "text/template" ) func RenderTemplate(path string, config *config.Config, runtime state.Runtime) ([]byte, error) { diff --git a/pkg/action/render_template_test.go b/pkg/action/render_template_test.go index 0deb582..35f40e8 100644 --- a/pkg/action/render_template_test.go +++ b/pkg/action/render_template_test.go @@ -2,11 +2,12 @@ package action import ( "fmt" + "os" + agentConfig "github.com/kairos-io/kairos-agent/v2/pkg/config" "github.com/kairos-io/kairos-sdk/collector" "github.com/kairos-io/kairos-sdk/state" "gopkg.in/yaml.v3" - "os" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -20,6 +21,7 @@ var _ = Describe("RenderTemplate action test", func() { "testKey": "testValue", } runtime, err := state.NewRuntime() + Expect(err).ToNot(HaveOccurred()) fmt.Println(os.Getwd()) @@ -30,9 +32,10 @@ var _ = Describe("RenderTemplate action test", func() { var data map[string]string err = yaml.Unmarshal(result, &data) + Expect(err).ToNot(HaveOccurred()) Expect(data).To(HaveKeyWithValue("configTest", "TESTVALUE")) - Expect(data["stateTest"]).To(MatchRegexp("^[0-9a-f]{8}$")) + Expect(data["stateTest"]).To(Equal("amd64")) }) }) diff --git a/tests/fixtures/template/test.yaml b/tests/fixtures/template/test.yaml index d107698..45ec446 100644 --- a/tests/fixtures/template/test.yaml +++ b/tests/fixtures/template/test.yaml @@ -1,2 +1,2 @@ configTest: "{{.Config.testKey | upper}}" -stateTest: "{{.State.uuid | trunc 8}}" \ No newline at end of file +stateTest: "{{.State.system.os.architecture}}"