Skip to content

Commit

Permalink
Merge refactorings and additional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
quintush committed Dec 30, 2024
1 parent 4f9ae32 commit 68e2e9d
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 152 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# borrowed from https://github.com/technosophos/helm-template

HELM_VERSION := 3.16.3
HELM_VERSION := 3.16.4
VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml)
DIST := ./_dist
LDFLAGS := "-X main.version=${VERSION} -extldflags '-static'"
Expand Down Expand Up @@ -47,11 +47,11 @@ install-dbg: bootstrap build-debug plugin-dir
hookInstall: bootstrap build

.PHONY: unittest
unittest: ## Run unit tests
unittest: build ## Run unit tests
go test ./... -v -cover

.PHONY: test-coverage
test-coverage: ## Test coverage with open report in default browser
test-coverage: build ## Test coverage with open report in default browser
@go test -cover -coverprofile=cover.out -v ./...
@go tool cover -html=cover.out

Expand All @@ -60,7 +60,7 @@ build-debug: ## Compile packages and dependencies with debug flag
go build -o untt-dbg -gcflags "all=-N -l" ./cmd/helm-unittest

.PHONY: build
build: unittest ## Compile packages and dependencies
build: ## Compile packages and dependencies
go build -o untt -ldflags $(LDFLAGS) ./cmd/helm-unittest

.PHONY: dist
Expand Down
12 changes: 6 additions & 6 deletions internal/common/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ func YmlUnmarshal(in string, out interface{}) error {
return err
}

func YmlUnmarshalTestHelper(input string, out any, t *testing.T) {
t.Helper()
err := YmlUnmarshal(input, out)
assert.NoError(t, err)
}

func YmlMarshall(in interface{}) (string, error) {
out, err := yaml.Marshal(in)
if err != nil {
Expand All @@ -77,6 +71,12 @@ func YmlMarshall(in interface{}) (string, error) {
return string(out), nil
}

func YmlUnmarshalTestHelper(input string, out any, t *testing.T) {
t.Helper()
err := YmlUnmarshal(input, out)
assert.NoError(t, err)
}

func YmlMarshallTestHelper(in interface{}, t *testing.T) string {
t.Helper()
out, err := yaml.Marshal(in)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Charts: 1 passed, 1 total
Test Suites: 13 passed, 13 total
Tests: 40 passed, 40 total
Tests: 41 passed, 41 total
Snapshot: 4 passed, 4 total
Time: XX.XXXms

Expand Down
18 changes: 1 addition & 17 deletions pkg/unittest/.snapshots/TestV3RunnerOkWithFailedTests
Original file line number Diff line number Diff line change
Expand Up @@ -285,19 +285,6 @@
Actual:
2

- asserts[13] `matchSnapshot` fail
Template: basic/templates/deployment.yaml
DocumentIndex: 0
ValuesIndex: 0
Path: spec
Expected to match snapshot 1:
--- Expected
+++ Actual
@@ -22,2 +22,4 @@
resources: {}
+ securityContext:
+ runAsUser: 1000

- asserts[14] `contains` fail
Template: basic/templates/deployment.yaml
DocumentIndex: 0
Expand Down Expand Up @@ -542,13 +529,10 @@



Snapshot Summary: 1 snapshot failed in 1 test suite. Check changes and use `-u` to update snapshot.


Charts: 1 failed, 0 passed, 1 total
Test Suites: 9 failed, 0 passed, 9 total
Tests: 17 failed, 1 errored, 0 passed, 17 total
Snapshot: 1 failed, 1 passed, 2 total
Snapshot: 2 passed, 2 total
Time: XX.XXXms


Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Charts: 1 passed, 1 total
Test Suites: 13 passed, 13 total
Tests: 40 passed, 40 total
Tests: 41 passed, 41 total
Snapshot: 4 passed, 4 total
Time: XX.XXXms

Expand Down
2 changes: 1 addition & 1 deletion pkg/unittest/.snapshots/TestV3RunnerOkWithPassedTests
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Charts: 1 passed, 1 total
Test Suites: 13 passed, 13 total
Tests: 40 passed, 40 total
Tests: 41 passed, 41 total
Snapshot: 4 passed, 4 total
Time: XX.XXXms

Expand Down
2 changes: 1 addition & 1 deletion pkg/unittest/snapshot/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"

"github.com/helm-unittest/helm-unittest/internal/common"
yaml "gopkg.in/yaml.v3"
yaml "sigs.k8s.io/yaml"
)

// CompareResult result return by Cache.Compare
Expand Down
55 changes: 55 additions & 0 deletions pkg/unittest/valueutils/valueutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io"
"strconv"

"github.com/helm-unittest/helm-unittest/internal/common"
"github.com/vmware-labs/yaml-jsonpath/pkg/yamlpath"
Expand Down Expand Up @@ -167,6 +168,60 @@ func traverseSetPath(in io.RuneReader, traverser parseTraverser, state int) erro
return nil
}

func handleExpectIndex(k []rune, last rune, traverser parseTraverser) (int, error) {
if last != ']' {
return -1, fmt.Errorf("missing index value")
}
idx, idxErr := strconv.Atoi(string(k))
if idxErr != nil {
return -1, idxErr
}
traverser.traverseListIdx(idx)
return expectDenotation, nil
}

func handleExpectDenotation(last rune) (int, error) {
switch last {
case '.':
return expectKey, nil
case '[':
return expectIndex, nil
default:
return -1, fmt.Errorf("invalid denotation token %s", string(last))
}
}

func handleExpectKey(k []rune, last rune, traverser parseTraverser) (int, error) {
switch last {
case '.':
traverser.traverseMapKey(string(k))
return expectKey, nil
case '[':
if len(k) == 0 {
bufferedMapKey = ""
return expectEscaping, nil
}
traverser.traverseMapKey(string(k))
return expectIndex, nil
default:
return -1, fmt.Errorf("invalid key %s", string(last))
}
}

func handleExpectEscaping(k []rune, last rune, traverser parseTraverser) (int, error) {
switch last {
case '.':
bufferedMapKey += string(k) + "."
return expectEscaping, nil
case ']':
bufferedMapKey += string(k)
traverser.traverseMapKey(bufferedMapKey)
return expectDenotation, nil
default:
return -1, fmt.Errorf("invalid escaping token %s", string(last))
}
}

// copy from helm
func runesUntil(in io.RuneReader, stop map[rune]bool) ([]rune, rune, error) {
v := []rune{}
Expand Down
60 changes: 0 additions & 60 deletions pkg/unittest/valueutils/valueutils_handlers.go

This file was deleted.

1 change: 1 addition & 0 deletions pkg/unittest/valueutils/valueutils_handlers_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Need to restructure to run these tests in the valueutils package
package valueutils

import (
Expand Down
Loading

0 comments on commit 68e2e9d

Please sign in to comment.