Skip to content
Snippets Groups Projects
Commit ac27a21a752d authored by Florent Aide's avatar Florent Aide
Browse files

add tests to prove the chart disabled as a variable

parent 2e270a1fd7d2
No related branches found
No related tags found
No related merge requests found
Pipeline #68420 passed
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
unit_tests: unit_tests:
stage: test stage: test
image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye image: quay.orus.io/cc/golang:1.21.3-bullseye
variables: variables:
YTT_VERSION: v0.41.1 YTT_VERSION: v0.41.1
YTT_SHA256: 65dbc4f3a4a2ed84296dd1b323e8e7bd77e488fa7540d12dd36cf7fb2fc77c03 YTT_SHA256: 65dbc4f3a4a2ed84296dd1b323e8e7bd77e488fa7540d12dd36cf7fb2fc77c03
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
lint: lint:
stage: lint stage: lint
image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye image: quay.orus.io/cc/golang:1.21.3-bullseye
cache: cache:
key: tooling key: tooling
paths: paths:
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
vulncheck: vulncheck:
stage: vulncheck stage: vulncheck
image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye image: quay.orus.io/cc/golang:1.21.3-bullseye
cache: cache:
key: tooling key: tooling
paths: paths:
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
build: build:
stage: build stage: build
image: quay.orus.io/cloudcrane/golang:1.20.6-bullseye image: quay.orus.io/cc/golang:1.21.3-bullseye
artifacts: artifacts:
paths: paths:
- build - build
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -15,7 +16,7 @@ ...@@ -15,7 +16,7 @@
"orus.io/orus-io/beaver/testutils" "orus.io/orus-io/beaver/testutils"
) )
var ( const (
fixtures = "fixtures/f1" fixtures = "fixtures/f1"
shaFixtures = "fixtures/f2" shaFixtures = "fixtures/f2"
helmNamespaceFixtures = "fixtures/f3" helmNamespaceFixtures = "fixtures/f3"
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
fixtures = "fixtures/f1" fixtures = "fixtures/f1"
shaFixtures = "fixtures/f2" shaFixtures = "fixtures/f2"
helmNamespaceFixtures = "fixtures/f3" helmNamespaceFixtures = "fixtures/f3"
disabledAsVar = "fixtures/fDisabledAsVar"
) )
func TestConfig(t *testing.T) { func TestConfig(t *testing.T) {
...@@ -240,6 +242,65 @@ ...@@ -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) { func TestSha(t *testing.T) {
shaValue := "2145bea9e32804c65d960e6d4af1c87f95ccc39fad7df5eec2f3925a193112ab" shaValue := "2145bea9e32804c65d960e6d4af1c87f95ccc39fad7df5eec2f3925a193112ab"
buildDir := filepath.Join(shaFixtures, "build", "example") buildDir := filepath.Join(shaFixtures, "build", "example")
......
namespace: example namespace: example
sha:
- key: configmap_demo
resource: ConfigMap.v1.demo.yaml
charts: charts:
demoytt: demoytt:
type: ytt type: ytt
path: demoytt.tmpl.yaml path: demoytt.tmpl.yaml
...@@ -5,7 +2,5 @@ ...@@ -5,7 +2,5 @@
charts: charts:
demoytt: demoytt:
type: ytt type: ytt
path: demoytt.tmpl.yaml path: demoytt.tmpl.yaml
demohelm: disabled: <[configmapDisabled]>
type: helm
path: demohelm
...@@ -4,7 +4,5 @@ ...@@ -4,7 +4,5 @@
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: demo name: demo
labels:
mysha: #@ data.values.sha
data: data:
answer: #@ data.values.answer answer: #@ data.values.answer
#@data/values #@data/values
--- ---
answer: 42 answer: 42
sha: <[sha.configmap_demo]>
namespace: ns1 namespace: ns1
inherit: ../../base inherit: ../base
variables: variables:
...@@ -3,11 +3,3 @@ ...@@ -3,11 +3,3 @@
variables: variables:
- name: VAULT_KV - name: configmapDisabled
value: k8s.orus.io value: false
- name: test-nested.nested-value1
value: another value
create:
- type: configmap
name: xbus-pipelines
args:
- flag: --from-file
value: pipelines
namespace: ns1 namespace: ns1
inherit: ../../base inherit: ../base
variables: variables:
...@@ -3,11 +3,3 @@ ...@@ -3,11 +3,3 @@
variables: variables:
- name: VAULT_KV - name: configmapDisabled
value: k8s.orus.io value: true
- name: test-nested.nested-value1
value: another value
create:
- type: configmap
name: xbus-pipelines
args:
- flag: --from-file
value: pipelines
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
return err return err
} }
// Search for over occurences of beaver variables // Search for over occurrences of beaver variables
regex := regexp.MustCompile(`<\[([^<\[\]>]*)\]>`) regex := regexp.MustCompile(`<\[([^<\[\]>]*)\]>`)
for regex.MatchString(s) { for regex.MatchString(s) {
return hydrateString(s, output, variables) return hydrateString(s, output, variables)
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type ToBoolTestCase struct { type ToBoolTestCase struct {
Input string Input string
...@@ -5,9 +6,9 @@ ...@@ -5,9 +6,9 @@
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
type ToBoolTestCase struct { type ToBoolTestCase struct {
Input string Input string
Ouput bool Output bool
ExpectError bool // if you expect an error put true here ExpectError bool // if you expect an error put true here
} }
...@@ -15,8 +16,8 @@ ...@@ -15,8 +16,8 @@
tCases := []ToBoolTestCase{ tCases := []ToBoolTestCase{
{ {
Input: "1", Input: "1",
Ouput: true, Output: true,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "0", Input: "0",
...@@ -19,9 +20,9 @@ ...@@ -19,9 +20,9 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "0", Input: "0",
Ouput: false, Output: false,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "True", Input: "True",
...@@ -24,9 +25,9 @@ ...@@ -24,9 +25,9 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "True", Input: "True",
Ouput: true, Output: true,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "true", Input: "true",
...@@ -29,9 +30,9 @@ ...@@ -29,9 +30,9 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "true", Input: "true",
Ouput: true, Output: true,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "False", Input: "False",
...@@ -34,9 +35,9 @@ ...@@ -34,9 +35,9 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "False", Input: "False",
Ouput: false, Output: false,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "false", Input: "false",
...@@ -39,9 +40,9 @@ ...@@ -39,9 +40,9 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "false", Input: "false",
Ouput: false, Output: false,
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "flase", Input: "flase",
...@@ -44,8 +45,8 @@ ...@@ -44,8 +45,8 @@
ExpectError: false, ExpectError: false,
}, },
{ {
Input: "flase", Input: "flase",
Ouput: false, Output: false,
ExpectError: true, ExpectError: true,
}, },
} }
...@@ -55,7 +56,7 @@ ...@@ -55,7 +56,7 @@
require.Error(t, err) require.Error(t, err)
} else { } else {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, tCase.Ouput, res) require.Equal(t, tCase.Output, res)
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment