diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2e270a1fd7d2433581a6bc71733fad93125e8273_LmdpdGxhYi1jaS55bWw=..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_LmdpdGxhYi1jaS55bWw= 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,7 +8,7 @@ unit_tests: stage: test - image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye + image: quay.orus.io/cc/golang:1.21.3-bullseye variables: YTT_VERSION: v0.41.1 YTT_SHA256: 65dbc4f3a4a2ed84296dd1b323e8e7bd77e488fa7540d12dd36cf7fb2fc77c03 @@ -43,7 +43,7 @@ lint: stage: lint - image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye + image: quay.orus.io/cc/golang:1.21.3-bullseye cache: key: tooling paths: @@ -56,7 +56,7 @@ vulncheck: stage: vulncheck - image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye + image: quay.orus.io/cc/golang:1.21.3-bullseye cache: key: tooling paths: @@ -69,7 +69,7 @@ build: stage: build - image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye + image: quay.orus.io/cc/golang:1.21.3-bullseye artifacts: paths: - build diff --git a/runner/config_test.go b/runner/config_test.go index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2NvbmZpZ190ZXN0Lmdv..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2NvbmZpZ190ZXN0Lmdv 100644 --- a/runner/config_test.go +++ b/runner/config_test.go @@ -2,6 +2,7 @@ import ( "bytes" + "errors" "fmt" "os" "path/filepath" @@ -15,7 +16,7 @@ "orus.io/orus-io/beaver/testutils" ) -var ( +const ( fixtures = "fixtures/f1" shaFixtures = "fixtures/f2" helmNamespaceFixtures = "fixtures/f3" @@ -19,6 +20,7 @@ fixtures = "fixtures/f1" shaFixtures = "fixtures/f2" helmNamespaceFixtures = "fixtures/f3" + disabledAsVar = "fixtures/fDisabledAsVar" ) func TestConfig(t *testing.T) { @@ -240,6 +242,65 @@ } } +type disabledTCase struct { + Name string + TestPath string + FilePresent bool +} + +func TestDisabledAsVariable(t *testing.T) { + tCases := []disabledTCase{ + { + Name: "disabled", + TestPath: "noconfigmap", + FilePresent: false, + }, + { + Name: "enabled", + TestPath: "configmapenabled", + FilePresent: true, + }, + } + for _, tCase := range tCases { + t.Run(tCase.Name, func(t *testing.T) { + runTestDisabledAsVar(t, tCase) + }) + } +} + +func runTestDisabledAsVar(t *testing.T, tCase disabledTCase) { + t.Helper() + buildDir := filepath.Join(disabledAsVar, "build", "example") + defer func() { + require.NoError(t, runner.CleanDir(buildDir)) + }() + + tl := testutils.NewTestLogger(t) + absRootDir, err := filepath.Abs(disabledAsVar) + require.NoError(t, err) + c := runner.NewCmdConfig(tl.Logger(), absRootDir, tCase.TestPath, false, "", "") + tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-") + require.NoError(t, err) + defer func() { + assert.NoError(t, os.RemoveAll(tmpDir)) + }() + require.NoError(t, c.Initialize(tmpDir)) + r := runner.NewRunner(c) + require.NoError(t, r.Build(tmpDir)) + + outPutConfigMapName := filepath.Join(buildDir, "ConfigMap.v1.demo.yaml") + if !tCase.FilePresent { + _, err = os.Stat(outPutConfigMapName) + require.Error(t, err) + // file should not exist since it is disabled by a variable in the noconfigmap/beaver.yaml + require.True(t, errors.Is(err, os.ErrNotExist)) + } else { + _, err = os.Stat(outPutConfigMapName) + // file should exist + require.NoError(t, err) + } +} + func TestSha(t *testing.T) { shaValue := "2145bea9e32804c65d960e6d4af1c87f95ccc39fad7df5eec2f3925a193112ab" buildDir := filepath.Join(shaFixtures, "build", "example") diff --git a/runner/fixtures/f2/base/beaver.yaml b/runner/fixtures/fDisabledAsVar/base/beaver.yaml similarity index 52% copy from runner/fixtures/f2/base/beaver.yaml copy to runner/fixtures/fDisabledAsVar/base/beaver.yaml index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2ZpeHR1cmVzL2YyL2Jhc2UvYmVhdmVyLnlhbWw=..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2ZpeHR1cmVzL2ZEaXNhYmxlZEFzVmFyL2Jhc2UvYmVhdmVyLnlhbWw= 100644 --- a/runner/fixtures/f2/base/beaver.yaml +++ b/runner/fixtures/fDisabledAsVar/base/beaver.yaml @@ -1,8 +1,5 @@ namespace: example -sha: -- key: configmap_demo - resource: ConfigMap.v1.demo.yaml charts: demoytt: type: ytt path: demoytt.tmpl.yaml @@ -5,7 +2,5 @@ charts: demoytt: type: ytt path: demoytt.tmpl.yaml - demohelm: - type: helm - path: demohelm + disabled: <[configmapDisabled]> diff --git a/runner/fixtures/f2/base/demoytt.tmpl.yaml b/runner/fixtures/fDisabledAsVar/base/demoytt.tmpl.yaml similarity index 85% copy from runner/fixtures/f2/base/demoytt.tmpl.yaml copy to runner/fixtures/fDisabledAsVar/base/demoytt.tmpl.yaml index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2ZpeHR1cmVzL2YyL2Jhc2UvZGVtb3l0dC50bXBsLnlhbWw=..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2ZpeHR1cmVzL2ZEaXNhYmxlZEFzVmFyL2Jhc2UvZGVtb3l0dC50bXBsLnlhbWw= 100644 --- a/runner/fixtures/f2/base/demoytt.tmpl.yaml +++ b/runner/fixtures/fDisabledAsVar/base/demoytt.tmpl.yaml @@ -4,7 +4,5 @@ kind: ConfigMap metadata: name: demo - labels: - mysha: #@ data.values.sha data: answer: #@ data.values.answer diff --git a/runner/fixtures/f2/base/demoytt.yaml b/runner/fixtures/fDisabledAsVar/base/demoytt.yaml similarity index 67% copy from runner/fixtures/f2/base/demoytt.yaml copy to runner/fixtures/fDisabledAsVar/base/demoytt.yaml index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2ZpeHR1cmVzL2YyL2Jhc2UvZGVtb3l0dC55YW1s..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2ZpeHR1cmVzL2ZEaXNhYmxlZEFzVmFyL2Jhc2UvZGVtb3l0dC55YW1s 100644 --- a/runner/fixtures/f2/base/demoytt.yaml +++ b/runner/fixtures/fDisabledAsVar/base/demoytt.yaml @@ -1,4 +1,3 @@ #@data/values --- answer: 42 -sha: <[sha.configmap_demo]> diff --git a/runner/fixtures/f1/environments/ns1/beaver.yml b/runner/fixtures/fDisabledAsVar/configmapenabled/beaver.yml similarity index 16% copy from runner/fixtures/f1/environments/ns1/beaver.yml copy to runner/fixtures/fDisabledAsVar/configmapenabled/beaver.yml index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2ZpeHR1cmVzL2YxL2Vudmlyb25tZW50cy9uczEvYmVhdmVyLnltbA==..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2ZpeHR1cmVzL2ZEaXNhYmxlZEFzVmFyL2NvbmZpZ21hcGVuYWJsZWQvYmVhdmVyLnltbA== 100644 --- a/runner/fixtures/f1/environments/ns1/beaver.yml +++ b/runner/fixtures/fDisabledAsVar/configmapenabled/beaver.yml @@ -1,3 +1,3 @@ namespace: ns1 -inherit: ../../base +inherit: ../base variables: @@ -3,11 +3,3 @@ variables: -- name: VAULT_KV - value: k8s.orus.io -- name: test-nested.nested-value1 - value: another value -create: -- type: configmap - name: xbus-pipelines - args: - - flag: --from-file - value: pipelines +- name: configmapDisabled + value: false diff --git a/runner/fixtures/f1/environments/ns1/beaver.yml b/runner/fixtures/fDisabledAsVar/noconfigmap/beaver.yml similarity index 16% copy from runner/fixtures/f1/environments/ns1/beaver.yml copy to runner/fixtures/fDisabledAsVar/noconfigmap/beaver.yml index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2ZpeHR1cmVzL2YxL2Vudmlyb25tZW50cy9uczEvYmVhdmVyLnltbA==..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2ZpeHR1cmVzL2ZEaXNhYmxlZEFzVmFyL25vY29uZmlnbWFwL2JlYXZlci55bWw= 100644 --- a/runner/fixtures/f1/environments/ns1/beaver.yml +++ b/runner/fixtures/fDisabledAsVar/noconfigmap/beaver.yml @@ -1,3 +1,3 @@ namespace: ns1 -inherit: ../../base +inherit: ../base variables: @@ -3,11 +3,3 @@ variables: -- name: VAULT_KV - value: k8s.orus.io -- name: test-nested.nested-value1 - value: another value -create: -- type: configmap - name: xbus-pipelines - args: - - flag: --from-file - value: pipelines +- name: configmapDisabled + value: true diff --git a/runner/hydrate.go b/runner/hydrate.go index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL2h5ZHJhdGUuZ28=..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL2h5ZHJhdGUuZ28= 100644 --- a/runner/hydrate.go +++ b/runner/hydrate.go @@ -45,7 +45,7 @@ return err } - // Search for over occurences of beaver variables + // Search for over occurrences of beaver variables regex := regexp.MustCompile(`<\[([^<\[\]>]*)\]>`) for regex.MatchString(s) { return hydrateString(s, output, variables) diff --git a/runner/main_test.go b/runner/main_test.go index 2e270a1fd7d2433581a6bc71733fad93125e8273_cnVubmVyL21haW5fdGVzdC5nbw==..ac27a21a752d0019cb108f683ad38bb9aea3e2aa_cnVubmVyL21haW5fdGVzdC5nbw== 100644 --- a/runner/main_test.go +++ b/runner/main_test.go @@ -2,8 +2,9 @@ import ( "testing" + "github.com/stretchr/testify/require" ) type ToBoolTestCase struct { Input string @@ -5,9 +6,9 @@ "github.com/stretchr/testify/require" ) type ToBoolTestCase struct { Input string - Ouput bool + Output bool ExpectError bool // if you expect an error put true here } @@ -15,8 +16,8 @@ tCases := []ToBoolTestCase{ { Input: "1", - Ouput: true, + Output: true, ExpectError: false, }, { Input: "0", @@ -19,9 +20,9 @@ ExpectError: false, }, { Input: "0", - Ouput: false, + Output: false, ExpectError: false, }, { Input: "True", @@ -24,9 +25,9 @@ ExpectError: false, }, { Input: "True", - Ouput: true, + Output: true, ExpectError: false, }, { Input: "true", @@ -29,9 +30,9 @@ ExpectError: false, }, { Input: "true", - Ouput: true, + Output: true, ExpectError: false, }, { Input: "False", @@ -34,9 +35,9 @@ ExpectError: false, }, { Input: "False", - Ouput: false, + Output: false, ExpectError: false, }, { Input: "false", @@ -39,9 +40,9 @@ ExpectError: false, }, { Input: "false", - Ouput: false, + Output: false, ExpectError: false, }, { Input: "flase", @@ -44,8 +45,8 @@ ExpectError: false, }, { Input: "flase", - Ouput: false, + Output: false, ExpectError: true, }, } @@ -55,7 +56,7 @@ require.Error(t, err) } else { require.NoError(t, err) - require.Equal(t, tCase.Ouput, res) + require.Equal(t, tCase.Output, res) } } }