From d74ae723715a102d644790df4d8708ceb2851f46 Mon Sep 17 00:00:00 2001 From: kovayur <8366110+kovayur@users.noreply.github.com> Date: Wed, 2 Feb 2022 15:43:57 +0100 Subject: [PATCH] ROX-9160: Add basic CI checks (#12) --- .github/workflows/ci.yaml | 31 +++++++++++++++++++++++++++++++ EXPECTED_GO_VERSION | 1 + go.mod | 2 +- go.sum | 1 - internal/parser/parser.go | 2 +- pkg/framework/loader.go | 9 +++++---- pkg/framework/loader_test.go | 13 +++++++------ pkg/framework/test_test.go | 3 ++- 8 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 EXPECTED_GO_VERSION diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..30d3915 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,31 @@ +name: helmtest CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-20.04 + steps: + - name: Checkout VCS + uses: actions/checkout@v2 + + - name: Prepare environment + run: | + go_version=$(cat EXPECTED_GO_VERSION) + echo "GO_VERSION=$go_version" >> $GITHUB_ENV + echo "CI=true" >> $GITHUB_ENV + + - name: Setup GO + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Test + run: make test + + - name: Lint + run: make golangci-lint diff --git a/EXPECTED_GO_VERSION b/EXPECTED_GO_VERSION new file mode 100644 index 0000000..06fb41b --- /dev/null +++ b/EXPECTED_GO_VERSION @@ -0,0 +1 @@ +1.17.2 diff --git a/go.mod b/go.mod index dbdefb7..aab522e 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,6 @@ require ( k8s.io/apimachinery v0.22.2 k8s.io/kube-openapi v0.0.0-20211025214626-d9a0cc0561b2 k8s.io/kubectl v0.22.2 - k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // indirect + k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 sigs.k8s.io/yaml v1.3.0 ) diff --git a/go.sum b/go.sum index 49161bb..36d72c5 100644 --- a/go.sum +++ b/go.sum @@ -1831,7 +1831,6 @@ k8s.io/metrics v0.22.2/go.mod h1:GUcsBtpsqQD1tKFS/2wCKu4ZBowwRncLOJH1rgWs3uw= k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= -k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a h1:8dYfu/Fc9Gz2rNJKB9IQRGgQOh2clmRzNIPPY1xLY5g= k8s.io/utils v0.0.0-20210819203725-bdf08cb9a70a/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 h1:ZKMMxTvduyf5WUtREOqg5LiXaN1KO/+0oOQPRFrClpo= k8s.io/utils v0.0.0-20211208161948-7d6a63dca704/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= diff --git a/internal/parser/parser.go b/internal/parser/parser.go index ae92c18..91e5bca 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -60,4 +60,4 @@ func ParseQuery(src string) (*gojq.Query, error) { return nil, err } return query, nil -} \ No newline at end of file +} diff --git a/pkg/framework/loader.go b/pkg/framework/loader.go index db1fc99..14b5cfb 100644 --- a/pkg/framework/loader.go +++ b/pkg/framework/loader.go @@ -1,12 +1,12 @@ package framework import ( - "k8s.io/utils/strings/slices" "os" "path/filepath" "strings" "github.com/pkg/errors" + "k8s.io/utils/strings/slices" ) const ( @@ -19,7 +19,7 @@ type Loader struct { additionalTestDirs []string } -// NewLoader returns a a loader and applies options to it. +// NewLoader returns a loader and applies options to it. func NewLoader(rootDir string, opts ...LoaderOpt) *Loader { loader := Loader{ rootDir: rootDir, @@ -31,7 +31,7 @@ func NewLoader(rootDir string, opts ...LoaderOpt) *Loader { return &loader } -// LoaderOpts allows to set custom options. +// LoaderOpt allows setting custom options. type LoaderOpt func(loader *Loader) // WithAdditionalTestDirs adds additional test source directories which are scanned for tests. @@ -82,7 +82,8 @@ func (loader *Loader) readTestYAMLFiles() ([]string, error) { var testYAMLFiles []string var scannedDirs []string - dirs := append(loader.additionalTestDirs, loader.rootDir) + dirs := []string{loader.rootDir} + dirs = append(dirs, loader.additionalTestDirs...) for _, dir := range dirs { if slices.Contains(scannedDirs, dir) { continue diff --git a/pkg/framework/loader_test.go b/pkg/framework/loader_test.go index 4be5adb..0a0e372 100644 --- a/pkg/framework/loader_test.go +++ b/pkg/framework/loader_test.go @@ -1,19 +1,20 @@ package framework import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestLoader(t *testing.T) { const testdataPath = "testdata/suite" tests := map[string]struct { - opts []LoaderOpt - expectedFunc func(*testing.T, *Test) - additionalDir string -}{ + opts []LoaderOpt + expectedFunc func(*testing.T, *Test) + additionalDir string + }{ "With root dir": { expectedFunc: func(t *testing.T, helmTest *Test) { assert.Len(t, helmTest.Tests, 2) @@ -24,7 +25,7 @@ func TestLoader(t *testing.T) { require.Len(t, test.Tests[1].Tests, 1) childTest := test.findFirst([]string{testdataPath, "helm.test.yaml", "test in helm.test.yaml", "with overwrites"}) assert.Equal(t, "with overwrites", childTest.Name) - assert.Equal(t, map[string]interface {}{"testValue":"value overwrite"}, childTest.Values) + assert.Equal(t, map[string]interface{}{"testValue": "value overwrite"}, childTest.Values) }, }, "Loader loads additional dir": { diff --git a/pkg/framework/test_test.go b/pkg/framework/test_test.go index 66d5644..c07484a 100644 --- a/pkg/framework/test_test.go +++ b/pkg/framework/test_test.go @@ -1,9 +1,10 @@ package framework import ( + "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "testing" ) func TestFind(t *testing.T) {