diff --git a/AlpineTest.Dockerfile b/AlpineTest.Dockerfile index 950cebd17..e8b1448ee 100644 --- a/AlpineTest.Dockerfile +++ b/AlpineTest.Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM alpine:3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d +FROM --platform=$BUILDPLATFORM alpine:3@sha256:1e42bbe2508154c9126d48c2b8a75420c3544343bf86fd041fb7527e017a4b4a # variable "HELM_VERSION" and "PLUGIN_VERSION" must be passed as docker environment variables during the image build # docker buildx build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t alpine/helm-unittest:test -f AlpineTest.Dockerfile . diff --git a/CHANGELOG.md b/CHANGELOG.md index cf524f041..75d8fce0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +0.7.0 / 2024-11-25 +================== +- Fix template path is translated differently (credits @ivankatliarchuk, resolves #300) +- Fix rendering with subchart alias with version override (credits @ivankatliarchuk, resolves #457) +- Added multivalue validations (credits @Andreas02-dev, resolves #289, resolves #345, resolves #405) +- Improved proper FailFast (credits @Andreas02-dev) +- Update packages to latest patch versions +- Update documentation + 0.6.3 / 2024-10-08 ================== - Fix regression on document separator for raw files (credits @ivankatliarchuk, resolves #413) diff --git a/Dockerfile b/Dockerfile index a3480d693..0390ab086 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM alpine:3@sha256:beefdbd8a1da6d2915566fde36db9db0b524eb737fc57cd1367effd16dc0d06d +FROM --platform=$BUILDPLATFORM alpine:3@sha256:1e42bbe2508154c9126d48c2b8a75420c3544343bf86fd041fb7527e017a4b4a # variable "HELM_VERSION" and "PLUGIN_VERSION" must be passed as docker environment variables during the image build # docker buildx build --no-cache --platform linux/amd64,linux/arm64 --build-arg HELM_VERSION=3.10.0 --build-arg PLUGIN_VERSION=0.3.0 -t alpine/helm-unittest:3.10.0-0.3.0 . diff --git a/Fedora.Dockerfile b/Fedora.Dockerfile index ca6fd7cb4..595a0e1be 100644 --- a/Fedora.Dockerfile +++ b/Fedora.Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM fedora:40@sha256:d0207dbb078ee261852590b9a8f1ab1f8320547be79a2f39af9f3d23db33735e +FROM --platform=$BUILDPLATFORM fedora:41@sha256:3ec60eb34fa1a095c0c34dd37cead9fd38afb62612d43892fcf1d3425c32bc1e # variable "HELM_VERSION" must be passed as docker environment variables during the image build # docker buildx build --load --no-cache --platform linux/amd64 --build-arg HELM_VERSION=3.13.0 -t fedora/helm-unittest:test -f Fedora.Dockerfile . diff --git a/Makefile b/Makefile index 6d030ebb1..309c4f723 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # borrowed from https://github.com/technosophos/helm-template -HELM_VERSION := 3.16.1 +HELM_VERSION := 3.16.3 VERSION := $(shell sed -n -e 's/version:[ "]*\([^"]*\).*/\1/p' plugin.yaml) DIST := ./_dist LDFLAGS := "-X main.version=${VERSION} -extldflags '-static'" diff --git a/go.mod b/go.mod index a8fe2cb04..7e19dca24 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/vmware-labs/yaml-jsonpath v0.3.2 github.com/yargevad/filepathx v1.0.0 gopkg.in/yaml.v3 v3.0.1 - helm.sh/helm/v3 v3.16.2 + helm.sh/helm/v3 v3.16.3 k8s.io/apimachinery v0.31.2 k8s.io/client-go v0.31.2 ) @@ -63,23 +63,22 @@ require ( github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/crypto v0.28.0 // indirect - golang.org/x/net v0.30.0 // indirect - golang.org/x/oauth2 v0.23.0 // indirect - golang.org/x/sys v0.26.0 // indirect - golang.org/x/term v0.25.0 // indirect - golang.org/x/text v0.19.0 // indirect - golang.org/x/time v0.7.0 // indirect - google.golang.org/protobuf v1.35.1 // indirect + golang.org/x/crypto v0.29.0 // indirect + golang.org/x/net v0.31.0 // indirect + golang.org/x/oauth2 v0.24.0 // indirect + golang.org/x/sys v0.27.0 // indirect + golang.org/x/term v0.26.0 // indirect + golang.org/x/text v0.20.0 // indirect + golang.org/x/time v0.8.0 // indirect + google.golang.org/protobuf v1.35.2 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect k8s.io/api v0.31.2 // indirect k8s.io/apiextensions-apiserver v0.31.2 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 // indirect - k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 // indirect + k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect + k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 // indirect sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.4.3 // indirect sigs.k8s.io/yaml v1.4.0 ) diff --git a/go.sum b/go.sum index 17a72d7b0..b48843173 100644 --- a/go.sum +++ b/go.sum @@ -188,8 +188,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -200,10 +200,10 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= -golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= -golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= -golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -225,20 +225,20 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= -golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= +golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ= -golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= +golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -258,8 +258,8 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= @@ -274,17 +274,15 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -helm.sh/helm/v3 v3.16.2 h1:Y9v7ry+ubQmi+cb5zw1Llx8OKHU9Hk9NQ/+P+LGBe2o= -helm.sh/helm/v3 v3.16.2/go.mod h1:SyTXgKBjNqi2NPsHCW5dDAsHqvGIu0kdNYNH9gQaw70= +helm.sh/helm/v3 v3.16.3 h1:kb8bSxMeRJ+knsK/ovvlaVPfdis0X3/ZhYCSFRP+YmY= +helm.sh/helm/v3 v3.16.3/go.mod h1:zeVWGDR4JJgiRbT3AnNsjYaX8OTJlIE9zC+Q7F7iUSU= k8s.io/api v0.31.2 h1:3wLBbL5Uom/8Zy98GRPXpJ254nEFpl+hwndmk9RwmL0= k8s.io/api v0.31.2/go.mod h1:bWmGvrGPssSK1ljmLzd3pwCQ9MgoTsRCuK35u6SygUk= k8s.io/apiextensions-apiserver v0.31.2 h1:W8EwUb8+WXBLu56ser5IudT2cOho0gAKeTOnywBLxd0= @@ -295,13 +293,13 @@ k8s.io/client-go v0.31.2 h1:Y2F4dxU5d3AQj+ybwSMqQnpZH9F30//1ObxOKlTI9yc= k8s.io/client-go v0.31.2/go.mod h1:NPa74jSVR/+eez2dFsEIHNa+3o09vtNaWwWwb1qSxSs= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094 h1:MErs8YA0abvOqJ8gIupA1Tz6PKXYUw34XsGlA7uSL1k= -k8s.io/kube-openapi v0.0.0-20241009091222-67ed5848f094/go.mod h1:7ioBJr1A6igWjsR2fxq2EZ0mlMwYLejazSIc2bzMp2U= -k8s.io/utils v0.0.0-20240921022957-49e7df575cb6 h1:MDF6h2H/h4tbzmtIKTuctcwZmY0tY9mD9fNT47QO6HI= -k8s.io/utils v0.0.0-20240921022957-49e7df575cb6/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= +k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= +k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 h1:jGnCPejIetjiy2gqaJ5V0NLwTpF4wbQ6cZIItJCSHno= +k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= -sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= +sigs.k8s.io/structured-merge-diff/v4 v4.4.3 h1:sCP7Vv3xx/CWIuTPVN38lUPx0uw0lcLfzaiDa8Ja01A= +sigs.k8s.io/structured-merge-diff/v4 v4.4.3/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/pkg/unittest/assertion_test.go b/pkg/unittest/assertion_test.go index f95a0555b..ad5b51e39 100644 --- a/pkg/unittest/assertion_test.go +++ b/pkg/unittest/assertion_test.go @@ -73,12 +73,14 @@ func TestAssertionUnmarshaledFromYAML(t *testing.T) { - lengthEqual: ` + a := assert.New(t) assertionsAsMap := make([]map[string]interface{}, 33) - yaml.Unmarshal([]byte(assertionsYAML), &assertionsAsMap) + mapErr := yaml.Unmarshal([]byte(assertionsYAML), &assertionsAsMap) + a.Nil(mapErr) assertions := make([]Assertion, 33) - yaml.Unmarshal([]byte(assertionsYAML), &assertions) + assErr := yaml.Unmarshal([]byte(assertionsYAML), &assertions) + a.Nil(assErr) - a := assert.New(t) for idx, assertion := range assertions { _, ok := assertionsAsMap[idx][assertion.AssertType] a.True(ok) @@ -147,10 +149,12 @@ func TestAssertionUnmarshaledFromYAMLWithNotTrue(t *testing.T) { - failedTemplate: not: true ` + a := assert.New(t) + assertions := make([]Assertion, 29) - yaml.Unmarshal([]byte(assertionsYAML), &assertions) + err := yaml.Unmarshal([]byte(assertionsYAML), &assertions) + a.Nil(err) - a := assert.New(t) for _, assertion := range assertions { a.True(assertion.Not) } @@ -201,10 +205,12 @@ func TestReverseAssertionTheSameAsOriginalOneWithNotTrue(t *testing.T) { not: true - notFailedTemplate: ` + a := assert.New(t) + assertions := make([]Assertion, 28) - yaml.Unmarshal([]byte(assertionsYAML), &assertions) + err := yaml.Unmarshal([]byte(assertionsYAML), &assertions) + a.Nil(err) - a := assert.New(t) for idx := 0; idx < len(assertions); idx += 2 { a.Equal(assertions[idx].Not, !assertions[idx+1].Not) } @@ -228,8 +234,7 @@ e: f: g x: ` - manifest := common.K8sManifest{} - yaml.Unmarshal([]byte(manifestDoc), &manifest) + manifest := common.TrustedUnmarshalYAML(manifestDoc) renderedMap := map[string][]common.K8sManifest{ "t.yaml": {manifest}, } @@ -353,9 +358,10 @@ func TestAssertionAssertWhenTemplateNotSpecifiedAndNoDefault(t *testing.T) { } assertionYAML := "equal:" assertion := new(Assertion) - yaml.Unmarshal([]byte(assertionYAML), &assertion) + err := yaml.Unmarshal([]byte(assertionYAML), &assertion) a := assert.New(t) + a.Nil(err) result := assertion.Assert(renderedMap, fakeSnapshotComparer(true), true, nil, &results.AssertionResult{Index: 0}, false) a.Equal(&results.AssertionResult{ Index: 0, diff --git a/pkg/unittest/formatter/formatter.go b/pkg/unittest/formatter/formatter.go index 47431d5ae..6e1f91261 100644 --- a/pkg/unittest/formatter/formatter.go +++ b/pkg/unittest/formatter/formatter.go @@ -56,14 +56,22 @@ func writeContentToFile(noXMLHeader bool, content interface{}, w io.Writer) erro writer := bufio.NewWriter(w) if !noXMLHeader { - writer.WriteString(xml.Header) + _, headerErr := writer.WriteString(xml.Header) + if headerErr != nil { + return headerErr + } } - writer.Write(bytes) - writer.WriteByte('\n') - writer.Flush() + _, writeErr := writer.Write(bytes) + if writeErr != nil { + return writeErr + } + byteErr := writer.WriteByte('\n') + if byteErr != nil { + return byteErr + } - return nil + return writer.Flush() } // Formatter Interface. diff --git a/pkg/unittest/formatter/junit_report_xml_test.go b/pkg/unittest/formatter/junit_report_xml_test.go index 8b201634e..6645ae045 100644 --- a/pkg/unittest/formatter/junit_report_xml_test.go +++ b/pkg/unittest/formatter/junit_report_xml_test.go @@ -152,7 +152,8 @@ func TestWriteTestOutputAsJUnitMinimalSuccess(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual JUnitTestSuites - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertJUnitTestSuite(assert, expected.Suites, actual.Suites) } @@ -205,7 +206,8 @@ func TestWriteTestOutputAsJUnitWithFailures(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual JUnitTestSuites - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertJUnitTestSuite(assert, expected.Suites, actual.Suites) } @@ -264,7 +266,8 @@ func TestWriteTestOutputAsJUnitWithFailuresAndErrors(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual JUnitTestSuites - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertJUnitTestSuite(assert, expected.Suites, actual.Suites) } diff --git a/pkg/unittest/formatter/nunit_report_xml_test.go b/pkg/unittest/formatter/nunit_report_xml_test.go index 881d315b4..ecdf5ccae 100644 --- a/pkg/unittest/formatter/nunit_report_xml_test.go +++ b/pkg/unittest/formatter/nunit_report_xml_test.go @@ -142,7 +142,8 @@ func TestWriteTestOutputAsNUnitMinimalSuccess(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual NUnitTestResults - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assert.Equal(expected.Total, actual.Total) assert.Equal(expected.Errors, actual.Errors) @@ -214,7 +215,8 @@ func TestWriteTestOutputAsNUnitWithFailures(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual NUnitTestResults - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assert.Equal(expected.Total, actual.Total) assert.Equal(expected.Errors, actual.Errors) @@ -296,7 +298,8 @@ func TestWriteTestOutputAsNUnitWithFailuresAndErrors(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual NUnitTestResults - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assert.Equal(expected.Total, actual.Total) assert.Equal(expected.Errors, actual.Errors) @@ -346,7 +349,8 @@ func TestWriteTestOutputAsNUnitWithErrors(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual NUnitTestResults - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assert.Equal(expected.Total, actual.Total) assert.Equal(expected.Errors, actual.Errors) diff --git a/pkg/unittest/formatter/sonar_report_xml_test.go b/pkg/unittest/formatter/sonar_report_xml_test.go index 4834e6879..9398e501e 100644 --- a/pkg/unittest/formatter/sonar_report_xml_test.go +++ b/pkg/unittest/formatter/sonar_report_xml_test.go @@ -48,7 +48,7 @@ func validateSonarTestCases(assert *assert.Assertions, expected, actual []SonarT } func TestWriteTestOutputAsSonarNoTests(t *testing.T) { - _assert := assert.New(t) + assert := assert.New(t) outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml") expected := SonarTestExecutions{ @@ -58,21 +58,18 @@ func TestWriteTestOutputAsSonarNoTests(t *testing.T) { var given []*results.TestSuiteResult sut := NewSonarReportXML() - byteValue := loadFormatterTestcase(_assert, outputFile, given, sut) + byteValue := loadFormatterTestcase(assert, outputFile, given, sut) var actual SonarTestExecutions err := xml.Unmarshal(byteValue, &actual) - if err != nil { - _assert.Fail(err.Error()) - return - } + assert.Nil(err) - _assert.Equal(expected.Version, actual.Version) - validateSonarFiles(_assert, expected.Files, actual.Files) + assert.Equal(expected.Version, actual.Version) + validateSonarFiles(assert, expected.Files, actual.Files) } func TestWriteTestOutputAsSonarMinimalSuccess(t *testing.T) { - _assert := assert.New(t) + assert := assert.New(t) outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml") testSuiteDisplayName := "TestingSuiteSuccess" testCaseDisplayName := "TestCaseSuccessSuccess" @@ -107,20 +104,18 @@ func TestWriteTestOutputAsSonarMinimalSuccess(t *testing.T) { given[0].TestsResult[0].Duration, _ = time.ParseDuration("12s") sut := NewSonarReportXML() - byteValue := loadFormatterTestcase(_assert, outputFile, given, sut) + byteValue := loadFormatterTestcase(assert, outputFile, given, sut) var actual SonarTestExecutions err := xml.Unmarshal(byteValue, &actual) - if err != nil { - _assert.Fail(err.Error()) - } + assert.Nil(err) - _assert.Equal(expected.Version, actual.Version) - validateSonarFiles(_assert, expected.Files, actual.Files) + assert.Equal(expected.Version, actual.Version) + validateSonarFiles(assert, expected.Files, actual.Files) } func TestWriteTestOutputAsSonarWithErrorsAndFailures(t *testing.T) { - _assert := assert.New(t) + assert := assert.New(t) outputFile := filepath.Join(tmpNunitTestDir, "Sonar_Test_Output.xml") testSuiteDisplayName := "TestingSuiteFailuresAndErrors" testCaseDisplayNameError := "TestCaseError" @@ -170,14 +165,12 @@ func TestWriteTestOutputAsSonarWithErrorsAndFailures(t *testing.T) { given[0].TestsResult[1].Duration, _ = time.ParseDuration("456ms") sut := NewSonarReportXML() - byteValue := loadFormatterTestcase(_assert, outputFile, given, sut) + byteValue := loadFormatterTestcase(assert, outputFile, given, sut) var actual SonarTestExecutions err := xml.Unmarshal(byteValue, &actual) - if err != nil { - _assert.Fail(err.Error()) - } + assert.Nil(err) - _assert.Equal(expected.Version, actual.Version) - validateSonarFiles(_assert, expected.Files, actual.Files) + assert.Equal(expected.Version, actual.Version) + validateSonarFiles(assert, expected.Files, actual.Files) } diff --git a/pkg/unittest/formatter/xunit_report_xml_test.go b/pkg/unittest/formatter/xunit_report_xml_test.go index 8b63126ad..43d6f1793 100644 --- a/pkg/unittest/formatter/xunit_report_xml_test.go +++ b/pkg/unittest/formatter/xunit_report_xml_test.go @@ -167,7 +167,8 @@ func TestWriteTestOutputAsXUnitMinimalSuccess(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual XUnitAssemblies - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertXUnitTestAssemblies(assert, expected.Assembly, actual.Assembly) } @@ -235,7 +236,8 @@ func TestWriteTestOutputAsXUnitWithFailures(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual XUnitAssemblies - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertXUnitTestAssemblies(assert, expected.Assembly, actual.Assembly) } @@ -308,7 +310,8 @@ func TestWriteTestOutputAsXUnitWithFailuresAndErrors(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual XUnitAssemblies - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertXUnitTestAssemblies(assert, expected.Assembly, actual.Assembly) } @@ -366,7 +369,8 @@ func TestWriteTestOutputAsXUnitWithErrors(t *testing.T) { bytevalue := loadFormatterTestcase(assert, outputFile, given, sut) var actual XUnitAssemblies - xml.Unmarshal(bytevalue, &actual) + err := xml.Unmarshal(bytevalue, &actual) + assert.Nil(err) assertXUnitTestAssemblies(assert, expected.Assembly, actual.Assembly) } diff --git a/pkg/unittest/results/assertion_result.go b/pkg/unittest/results/assertion_result.go index cc5cefbbc..04fa04db7 100644 --- a/pkg/unittest/results/assertion_result.go +++ b/pkg/unittest/results/assertion_result.go @@ -21,7 +21,7 @@ func (ar AssertionResult) print(printer *printer.Printer, verbosity int) { return } - printer.Println(printer.Danger(ar.getTitle()), 2) + printer.Println(printer.Danger("%s", ar.getTitle()), 2) for _, infoLine := range ar.FailInfo { printer.Println(infoLine, 3) } diff --git a/pkg/unittest/results/test_job_result.go b/pkg/unittest/results/test_job_result.go index 0a521acd0..910a952b5 100644 --- a/pkg/unittest/results/test_job_result.go +++ b/pkg/unittest/results/test_job_result.go @@ -22,16 +22,12 @@ func (tjr TestJobResult) print(printer *printer.Printer, verbosity int) { } if tjr.ExecError != nil { - printer.Println(printer.Highlight("- "+tjr.DisplayName), 1) - printer.Println( - printer.Highlight("Error: ")+ - tjr.ExecError.Error()+"\n", - 2, - ) + printer.Println(printer.Highlight("- %s", tjr.DisplayName), 1) + printer.Println(printer.Highlight("Error: %s\n", tjr.ExecError.Error()), 2) return } - printer.Println(printer.Danger("- "+tjr.DisplayName+"\n"), 1) + printer.Println(printer.Danger("- %s\n", tjr.DisplayName), 1) for _, assertResult := range tjr.AssertsResult { assertResult.print(printer, verbosity) } diff --git a/pkg/unittest/results/test_suite_result.go b/pkg/unittest/results/test_suite_result.go index 5dad31227..b0d772450 100644 --- a/pkg/unittest/results/test_suite_result.go +++ b/pkg/unittest/results/test_suite_result.go @@ -34,10 +34,10 @@ func (tsr TestSuiteResult) printTitle(printer *printer.Printer) { } var pathToPrint string if tsr.FilePath != "" { - pathToPrint = printer.Faint(filepath.ToSlash(filepath.Dir(tsr.FilePath)+string(os.PathSeparator))) + + pathToPrint = printer.Faint("%s", filepath.ToSlash(filepath.Dir(tsr.FilePath)+string(os.PathSeparator))) + filepath.Base(tsr.FilePath) } - name := printer.Highlight(tsr.DisplayName) + name := printer.Highlight("%s", tsr.DisplayName) printer.Println( fmt.Sprintf("%s %s\t%s", label, name, pathToPrint), 0, @@ -48,7 +48,7 @@ func (tsr TestSuiteResult) printTitle(printer *printer.Printer) { func (tsr TestSuiteResult) Print(printer *printer.Printer, verbosity int) { tsr.printTitle(printer) if tsr.ExecError != nil { - printer.Println(printer.Highlight("- Execution Error: "), 1) + printer.Println(printer.Highlight("%s", "- Execution Error: "), 1) printer.Println(tsr.ExecError.Error()+"\n", 2) return } diff --git a/pkg/unittest/snapshot/cache_test.go b/pkg/unittest/snapshot/cache_test.go index cb7b2efb0..6905d4aae 100644 --- a/pkg/unittest/snapshot/cache_test.go +++ b/pkg/unittest/snapshot/cache_test.go @@ -41,11 +41,14 @@ var contentNew = map[string]interface{}{ }, } -func createCache(existed bool) *Cache { +func createCache(assert *assert.Assertions, existed bool) *Cache { dir, _ := os.MkdirTemp("", "test") cacheFile := filepath.Join(dir, "cache_test.yaml") if existed { - os.WriteFile(cacheFile, []byte(lastTimeContent), os.ModePerm) + err := os.WriteFile(cacheFile, []byte(lastTimeContent), os.ModePerm) + if err != nil { + assert.FailNow("Failed to create cache file") + } } return &Cache{Filepath: cacheFile} @@ -72,10 +75,10 @@ func verifyCache(assert *assert.Assertions, cache *Cache, exists, changed bool, } func TestCacheWhenFirstTime(t *testing.T) { - cache := createCache(false) + a := assert.New(t) + cache := createCache(a, false) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, false, false, 0, 0, 0, 0, 0) @@ -97,10 +100,10 @@ func TestCacheWhenFirstTime(t *testing.T) { } func TestCacheWhenNotChanged(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -122,10 +125,10 @@ func TestCacheWhenNotChanged(t *testing.T) { } func TestCacheWhenChanged(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -146,11 +149,11 @@ func TestCacheWhenChanged(t *testing.T) { } func TestCacheWhenNotChangedIfIsUpdating(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) cache.IsUpdating = true err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -172,11 +175,11 @@ func TestCacheWhenNotChangedIfIsUpdating(t *testing.T) { } func TestCacheWhenChangedIfIsUpdating(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) cache.IsUpdating = true err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -204,10 +207,10 @@ func TestCacheWhenChangedIfIsUpdating(t *testing.T) { } func TestCacheWhenHasVanished(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -228,10 +231,10 @@ func TestCacheWhenHasVanished(t *testing.T) { } func TestCacheWhenHasInserted(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -265,10 +268,10 @@ func TestCacheWhenHasInserted(t *testing.T) { } func TestCacheWhenNewOneAtMiddle(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) @@ -303,11 +306,11 @@ func TestCacheWhenNewOneAtMiddle(t *testing.T) { } func TestCacheWhenNewOneAtMiddleIfIsUpdating(t *testing.T) { - cache := createCache(true) + a := assert.New(t) + cache := createCache(a, true) cache.IsUpdating = true err := cache.RestoreFromFile() - a := assert.New(t) a.Nil(err) verifyCache(a, cache, true, true, 0, 0, 0, 0, 2) diff --git a/pkg/unittest/snapshot/factory_test.go b/pkg/unittest/snapshot/factory_test.go index 1f42bd6c8..ae081829b 100644 --- a/pkg/unittest/snapshot/factory_test.go +++ b/pkg/unittest/snapshot/factory_test.go @@ -42,13 +42,17 @@ func TestCreateSnapshotOfSuiteWhenNoCacheDir(t *testing.T) { } func TestCreateSnapshotOfSuiteWhenCacheDirExisted(t *testing.T) { + a := assert.New(t) + dir, _ := os.MkdirTemp("", "test") - os.Mkdir(filepath.Join(dir, "__snapshot__"), os.ModePerm) + dirErr := os.Mkdir(filepath.Join(dir, "__snapshot__"), os.ModePerm) + if dirErr != nil { + a.FailNow("Failed to create cache dir") + } cache, _ := CreateSnapshotOfSuite(filepath.Join(dir, "service_test.yaml"), false) info, err := os.Stat(filepath.Join(dir, "__snapshot__")) - a := assert.New(t) a.Nil(err) a.True(info.IsDir()) @@ -60,18 +64,24 @@ func TestCreateSnapshotOfSuiteWhenCacheDirExisted(t *testing.T) { } func TestCreateSnapshotOfSuiteWhenCacheFileExisted(t *testing.T) { + a := assert.New(t) dir, _ := os.MkdirTemp("", "test") - os.Mkdir(filepath.Join(dir, "__snapshot__"), os.ModePerm) - os.WriteFile(filepath.Join(dir, "__snapshot__", "service_test.yaml.snap"), []byte(`a test: + dirErr := os.Mkdir(filepath.Join(dir, "__snapshot__"), os.ModePerm) + if dirErr != nil { + a.FailNow("Failed to create cache dir") + } + fileErr := os.WriteFile(filepath.Join(dir, "__snapshot__", "service_test.yaml.snap"), []byte(`a test: 1: | a: b: c `), os.ModePerm) + if fileErr != nil { + a.FailNow("Failed to create cache file") + } cache, _ := CreateSnapshotOfSuite(filepath.Join(dir, "service_test.yaml"), false) info, err := os.Stat(filepath.Join(dir, "__snapshot__")) - a := assert.New(t) a.Nil(err) a.True(info.IsDir()) diff --git a/pkg/unittest/test_job_test.go b/pkg/unittest/test_job_test.go index a2773a065..d88e7be82 100644 --- a/pkg/unittest/test_job_test.go +++ b/pkg/unittest/test_job_test.go @@ -50,7 +50,7 @@ asserts: "x.y.z": "XYZ", }) assertions := make([]*Assertion, 2) - yaml.Unmarshal([]byte(` + assErr := yaml.Unmarshal([]byte(` - equal: path: a.b value: c @@ -58,6 +58,7 @@ asserts: path: x.y pattern: /z/ `), &assertions) + a.Nil(assErr) a.Equal(tj.Assertions, assertions) } @@ -79,11 +80,12 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -110,12 +112,13 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, renderPath, &results.TestJobResult{}) defer os.RemoveAll(renderPath) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -140,11 +143,12 @@ asserts: pattern: -basic$ ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -169,11 +173,12 @@ asserts: pattern: -basic ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -201,11 +206,12 @@ asserts: path: metadata.name ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -226,11 +232,12 @@ asserts: errorMessage: The externalPort is required ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -255,12 +262,13 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, false, "", &results.TestJobResult{}) // Write Buffer a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -285,12 +293,13 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) // Write Buffer a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -312,11 +321,12 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -337,17 +347,27 @@ asserts: documentIndex: 0 template: templates/deployment.yaml ` + a := assert.New(t) - file, _ := os.Create("testjob_test_TestRunJobWithValuesFile.yaml") - file.WriteString("nameOverride: mary-jane") - file.Close() + file, fileErr := os.Create("testjob_test_TestRunJobWithValuesFile.yaml") + if fileErr != nil { + a.FailNow("Failed to create file") + } + _, writeErr := file.WriteString("nameOverride: mary-jane") + if writeErr != nil { + a.FailNow("Failed to write to file") + } + closeErr := file.Close() + if closeErr != nil { + a.FailNow("Failed to close file") + } var tj TestJob - yaml.Unmarshal([]byte(fmt.Sprintf(manifest, file.Name())), &tj) + err := yaml.Unmarshal([]byte(fmt.Sprintf(manifest, file.Name())), &tj) + a.Nil(err) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) - a := assert.New(t) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.FileExists(file.Name()) @@ -373,11 +393,12 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -395,11 +416,12 @@ asserts: template: templates/crd_backup.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -419,11 +441,12 @@ asserts: template: templates/crd_backup.yaml ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.NotNil(testResult.ExecError) @@ -550,11 +573,12 @@ asserts: template: templates/deployment.yaml ` var tj TestJob - _ = unmarshalJob(manifest, &tj) + err := unmarshalJob(manifest, &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -578,9 +602,9 @@ asserts: testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) - a.Nil(err) a.Nil(testResult.ExecError) a.True(testResult.Passed) a.Equal(1, len(testResult.AssertsResult)) @@ -596,11 +620,12 @@ asserts: errorMessage: "values don't meet the specifications of the schema(s) in the following chart(s):\nwith-schema:\n- (root): image is required\n" ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.NotNil(testResult.ExecError) @@ -621,11 +646,12 @@ asserts: - failedTemplate: {} ` var tj TestJob - _ = unmarshalJob(manifest, &tj) + err := unmarshalJob(manifest, &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.NotNil(testResult.ExecError) @@ -646,11 +672,12 @@ asserts: - notFailedTemplate: {} ` var tj TestJob - yaml.Unmarshal([]byte(manifest), &tj) + err := yaml.Unmarshal([]byte(manifest), &tj) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) a := assert.New(t) + a.Nil(err) cupaloy.SnapshotT(t, makeTestJobResultSnapshotable(testResult)) a.Nil(testResult.ExecError) @@ -819,11 +846,12 @@ asserts: ----- ` var tj TestJob + assert := assert.New(t) err := yaml.Unmarshal([]byte(manifest), &tj) - assert.NoError(t, err) + assert.NoError(err) testResult := tj.RunV3(c, &snapshot.Cache{}, true, "", &results.TestJobResult{}) - assert.NoError(t, testResult.ExecError) - assert.True(t, testResult.Passed, testResult.AssertsResult) + assert.NoError(testResult.ExecError) + assert.True(testResult.Passed, testResult.AssertsResult) } diff --git a/pkg/unittest/test_runner.go b/pkg/unittest/test_runner.go index 448f39683..035c71fbb 100644 --- a/pkg/unittest/test_runner.go +++ b/pkg/unittest/test_runner.go @@ -215,7 +215,14 @@ func (tr *TestRunner) runV3SuitesOfChart(suites []*TestSuite, chartPath string) tr.handleSuiteResult(result) tr.testResults = append(tr.testResults, result) - snapshotCache.StoreToFileIfNeeded() + _, storeErr := snapshotCache.StoreToFileIfNeeded() + if storeErr != nil { + tr.handleSuiteResult(&results.TestSuiteResult{ + FilePath: suite.SnapshotFileUrl(), + ExecError: storeErr, + }) + chartPassed = false + } if !chartPassed && tr.Failfast { break @@ -264,8 +271,8 @@ func (tr *TestRunner) printChartHeader(chartName, path string) { ` header := fmt.Sprintf( headerFormat, - tr.Printer.Highlight(chartName), - tr.Printer.Faint(path), + tr.Printer.Highlight("%s", chartName), + tr.Printer.Faint("%s", path), ) tr.Printer.Println(header, 0) } @@ -273,7 +280,7 @@ func (tr *TestRunner) printChartHeader(chartName, path string) { // printErroredChartHeader if chart has exexution error print header with error func (tr *TestRunner) printErroredChartHeader(err error) { headerFormat := ` -### ` + tr.Printer.Danger("Error: ") + ` %s +### ` + tr.Printer.Danger("%s", "Error: ") + ` %s ` header := fmt.Sprintf(headerFormat, err) tr.Printer.Println(header, 0) @@ -287,7 +294,7 @@ Snapshot Summary: %s` summary := tr.Printer.Danger("%d snapshot failed", tr.snapshotCounting.failed) + fmt.Sprintf(" in %d test suite.", tr.suiteCounting.snapshotFailed) + - tr.Printer.Faint(" Check changes and use `-u` to update snapshot.") + tr.Printer.Faint("%s", " Check changes and use `-u` to update snapshot.") tr.Printer.Println(fmt.Sprintf(snapshotFormat, summary), 0) } diff --git a/pkg/unittest/test_suite_test.go b/pkg/unittest/test_suite_test.go index 438ec2fd3..e15091aa4 100644 --- a/pkg/unittest/test_suite_test.go +++ b/pkg/unittest/test_suite_test.go @@ -387,7 +387,8 @@ tests: asserts: ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_noasserts_template_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) @@ -426,7 +427,8 @@ tests: - matchSnapshot: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_multiple_template_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) @@ -450,7 +452,8 @@ tests: - matchSnapshot: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_suite_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) @@ -486,7 +489,8 @@ tests: - matchSnapshot: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_suite_override_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) @@ -509,7 +513,8 @@ tests: value: Pod ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_failed_suite_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) @@ -532,7 +537,8 @@ tests: - matchSnapshot: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_subfolder_test.yaml"), false) suiteResult := testSuite.RunV3(testV3WithSubFolderChart, cache, true, "", &results.TestSuiteResult{}) @@ -554,7 +560,8 @@ tests: - matchSnapshot: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_subchart_test.yaml"), false) suiteResult := testSuite.RunV3(testV3WithSubChart, cache, true, "", &results.TestSuiteResult{}) @@ -578,7 +585,8 @@ tests: pattern: "(.*-)?postgresql-1.2.3" ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) suiteResult := testSuite.RunV3(testV3WithSubChart, &snapshot.Cache{}, true, "", &results.TestSuiteResult{}) assert.True(t, suiteResult.Passed) @@ -598,7 +606,8 @@ tests: - notFailedTemplate: {} ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_subchartwithtrimming_test.yaml"), false) suiteResult := testSuite.RunV3(testV3WithSubChart, cache, true, "", &results.TestSuiteResult{}) @@ -628,7 +637,8 @@ tests: count: 0 ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_subchartwithalias_test.yaml"), false) suiteResult := testSuite.RunV3(testV3WithSubChart, cache, true, "", &results.TestSuiteResult{}) @@ -654,7 +664,8 @@ tests: value: postgresql-0.8.3 ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) suiteResult := testSuite.RunV3(testV3WithSubChart, &snapshot.Cache{}, true, "", &results.TestSuiteResult{}) @@ -682,7 +693,8 @@ tests: value: postgresql-0.6.3 ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) suiteResult := testSuite.RunV3(testV3WithSubChart, &snapshot.Cache{}, true, "", &results.TestSuiteResult{}) @@ -712,7 +724,8 @@ tests: value: postgresql-0.7.1 ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) suiteResult := testSuite.RunV3(testV3WithSubChart, &snapshot.Cache{}, true, "", &results.TestSuiteResult{}) @@ -735,7 +748,8 @@ tests: errorMessage: nameOverride cannot be longer than 20 characters ` testSuite := TestSuite{} - yaml.Unmarshal([]byte(suiteDoc), &testSuite) + err := yaml.Unmarshal([]byte(suiteDoc), &testSuite) + assert.Nil(t, err) cache, _ := snapshot.CreateSnapshotOfSuite(path.Join(tmpdir, "v3_nameoverride_failed_suite_test.yaml"), false) suiteResult := testSuite.RunV3(testV3BasicChart, cache, true, "", &results.TestSuiteResult{}) diff --git a/pkg/unittest/validators/common_test.go b/pkg/unittest/validators/common_test.go index 806c35670..495b7313e 100644 --- a/pkg/unittest/validators/common_test.go +++ b/pkg/unittest/validators/common_test.go @@ -4,13 +4,10 @@ import ( "github.com/helm-unittest/helm-unittest/internal/common" "github.com/helm-unittest/helm-unittest/pkg/unittest/snapshot" "github.com/stretchr/testify/mock" - yaml "gopkg.in/yaml.v3" ) func makeManifest(doc string) common.K8sManifest { - manifest := common.K8sManifest{} - yaml.Unmarshal([]byte(doc), &manifest) - return manifest + return common.TrustedUnmarshalYAML(doc) } type mockSnapshotComparer struct { diff --git a/pkg/unittest/validators/contains_document_validator_test.go b/pkg/unittest/validators/contains_document_validator_test.go index 700715a2f..fc63b3ebb 100644 --- a/pkg/unittest/validators/contains_document_validator_test.go +++ b/pkg/unittest/validators/contains_document_validator_test.go @@ -111,8 +111,12 @@ func TestContainsDocumentValidatorWhenNotAllDocumentsAreOk(t *testing.T) { Namespace: "foo", } pass, diff := validator.Validate(&ValidateContext{ - Docs: []common.K8sManifest{makeManifest(docToTestContainsDocument1), - makeManifest(docToTestContainsDocument2)}, + Docs: []common.K8sManifest{ + makeManifest(docToTestContainsDocument1), + makeManifest(docToTestContainsDocument2), + makeManifest(docToTestContainsDocument3), + makeManifest(docToTestContainsDocument4), + }, }) assert.False(t, pass) @@ -120,6 +124,12 @@ func TestContainsDocumentValidatorWhenNotAllDocumentsAreOk(t *testing.T) { "DocumentIndex:\t0", "Expected to contain document:", "\tKind = Service, apiVersion = v1, Name = bar, Namespace = foo", + "DocumentIndex:\t2", + "Expected to contain document:", + "\tKind = Service, apiVersion = v1, Name = bar, Namespace = foo", + "DocumentIndex:\t3", + "Expected to contain document:", + "\tKind = Service, apiVersion = v1, Name = bar, Namespace = foo", }, diff) } diff --git a/pkg/unittest/validators/equal_or_greater_validator_test.go b/pkg/unittest/validators/equal_or_greater_validator_test.go index 48065cb54..7479e3513 100644 --- a/pkg/unittest/validators/equal_or_greater_validator_test.go +++ b/pkg/unittest/validators/equal_or_greater_validator_test.go @@ -140,8 +140,8 @@ func TestEqualOrGreaterValidatorWhenInvalidPath(t *testing.T) { var actual = ` spec: containers: - - name: nginx - image: nginx + - name: nginx + image: nginx ` manifest := makeManifest(actual) @@ -165,14 +165,13 @@ func TestEqualOrGreaterValidatorWhenUnkownPath(t *testing.T) { var actual = ` spec: containers: - - name: nginx - image: nginx - resources: - limits: - memory: "256Mi" - requests: - cpu: 0.4 - memory: "128Mi" + - name: nginx + image: nginx + resources: + limits: + memory: "256Mi" + requests: + memory: "128Mi" ` manifest := makeManifest(actual) diff --git a/pkg/unittest/validators/equal_or_less_validator_test.go b/pkg/unittest/validators/equal_or_less_validator_test.go index 032f55d62..203fa42a8 100644 --- a/pkg/unittest/validators/equal_or_less_validator_test.go +++ b/pkg/unittest/validators/equal_or_less_validator_test.go @@ -127,14 +127,13 @@ func TestEqualOrLessValidatorWhenUnkownPath(t *testing.T) { var actual = ` spec: containers: - - name: nginx - image: nginx - resources: - limits: - memory: "256Mi" - requests: - cpu: 0.4 - memory: "128Mi" + - name: nginx + image: nginx + resources: + limits: + memory: "256Mi" + requests: + memory: "128Mi" ` manifest := makeManifest(actual) diff --git a/pkg/unittest/validators/is_subset_validator_test.go b/pkg/unittest/validators/is_subset_validator_test.go index adc00db38..1a4d042c1 100644 --- a/pkg/unittest/validators/is_subset_validator_test.go +++ b/pkg/unittest/validators/is_subset_validator_test.go @@ -215,7 +215,7 @@ a: } func TestIsSubsetValidatorWhenInvalidPath(t *testing.T) { - manifest := makeManifest("a::error") + manifest := makeManifest("a: error") validator := IsSubsetValidator{"a[b]", common.K8sManifest{"d": "foo bar"}} pass, diff := validator.Validate(&ValidateContext{ @@ -231,7 +231,7 @@ func TestIsSubsetValidatorWhenInvalidPath(t *testing.T) { } func TestIsSubsetValidatorWhenUnknownPath(t *testing.T) { - manifest := makeManifest("a::error") + manifest := makeManifest("a: error") validator := IsSubsetValidator{"a[5]", common.K8sManifest{"d": "foo bar"}} pass, diff := validator.Validate(&ValidateContext{ @@ -247,7 +247,7 @@ func TestIsSubsetValidatorWhenUnknownPath(t *testing.T) { } func TestIsSubsetValidatorWhenUnknownPathFailFast(t *testing.T) { - manifest := makeManifest("a::error") + manifest := makeManifest("a: error") validator := IsSubsetValidator{"a[5]", common.K8sManifest{"d": "foo bar"}} pass, diff := validator.Validate(&ValidateContext{ @@ -264,7 +264,7 @@ func TestIsSubsetValidatorWhenUnknownPathFailFast(t *testing.T) { } func TestIsSubsetValidatorWhenInvalidPathFailFast(t *testing.T) { - manifest := makeManifest("a::error") + manifest := makeManifest("a: error") validator := IsSubsetValidator{"a[b]", common.K8sManifest{"d": "foo bar"}} pass, diff := validator.Validate(&ValidateContext{ diff --git a/pkg/unittest/validators/length_equal_document_validator.go b/pkg/unittest/validators/length_equal_document_validator.go index 84f60ea50..8e641235f 100644 --- a/pkg/unittest/validators/length_equal_document_validator.go +++ b/pkg/unittest/validators/length_equal_document_validator.go @@ -34,11 +34,7 @@ func (v LengthEqualDocumentsValidator) singleValidateCounts(manifest common.K8sM return false, splitInfof(errorFormat, manifestIndex, -1, err.Error()), 0 } - if len(actuals) == 0 { - return false, splitInfof(errorFormat, manifestIndex, -1, fmt.Sprintf("unknown parameter %s", path)), 0 - } - - manifestSuccess := false + manifestSuccess := (len(actuals) == 0 && context.Negative) var manifestErrors []string arrayLength := 0 @@ -145,6 +141,7 @@ func (v LengthEqualDocumentsValidator) Validate(context *ValidateContext) (bool, if v.validatePathPaths() { return false, splitInfof(errorFormat, -1, -1, "'paths' couldn't be used with 'path'") } + // TODO: with the new approach path can also contain a list of paths singleMode := len(v.Path) > 0 manifests := context.getManifests() diff --git a/pkg/unittest/validators/length_equal_document_validator_test.go b/pkg/unittest/validators/length_equal_document_validator_test.go index a90e99cc1..1c7375a88 100644 --- a/pkg/unittest/validators/length_equal_document_validator_test.go +++ b/pkg/unittest/validators/length_equal_document_validator_test.go @@ -104,6 +104,22 @@ func TestLengthEqualDocumentsValidatorNegativeOk_Single(t *testing.T) { assert.Equal(t, []string{}, diff) } +func TestLengthEqualDocumentsValidatorNegativeOk_SingleNoPath(t *testing.T) { + manifest := makeManifest(testDocLengthEqual1) + count := 2 + validator := LengthEqualDocumentsValidator{ + Path: "spec.ssl", + Count: &count, + } + pass, diff := validator.Validate(&ValidateContext{ + Docs: []common.K8sManifest{manifest}, + Negative: true, + }) + + assert.True(t, pass) + assert.Equal(t, []string{}, diff) +} + func TestLengthEqualDocumentsValidatorOk_Multi(t *testing.T) { manifest := makeManifest(testDocLengthEqual3_Success) @@ -118,6 +134,21 @@ func TestLengthEqualDocumentsValidatorOk_Multi(t *testing.T) { assert.Equal(t, []string{}, diff) } +func TestLengthEqualDocumentsValidatorNegative_MultiNoPath(t *testing.T) { + manifest := makeManifest(testDocLengthEqual3_Success) + + validator := LengthEqualDocumentsValidator{ + Paths: []string{"spec.ssl", "spec.rules"}, + } + pass, diff := validator.Validate(&ValidateContext{ + Docs: []common.K8sManifest{manifest}, + Negative: true, + }) + + assert.True(t, pass) + assert.Equal(t, []string{}, diff) +} + func TestLengthEqualDocumentsValidatorNegativeFail_Multi(t *testing.T) { manifest := makeManifest(testDocLengthEqual3_Success) diff --git a/pkg/unittest/validators/match_regex_validator_test.go b/pkg/unittest/validators/match_regex_validator_test.go index 1a71011f8..d471c7981 100644 --- a/pkg/unittest/validators/match_regex_validator_test.go +++ b/pkg/unittest/validators/match_regex_validator_test.go @@ -207,7 +207,7 @@ func TestMatchRegexValidatorWhenNoPattern(t *testing.T) { } func TestMatchRegexValidatorWhenErrorGetValueOfSetPath(t *testing.T) { - manifest := makeManifest("a.b.d::error") + manifest := makeManifest("a.b.d: error") validator := MatchRegexValidator{"a.[b]", "^hello", false} pass, diff := validator.Validate(&ValidateContext{ @@ -223,7 +223,7 @@ func TestMatchRegexValidatorWhenErrorGetValueOfSetPath(t *testing.T) { } func TestMatchRegexValidatorWhenUnknownPathFailFast(t *testing.T) { - manifest := makeManifest("a.b.d::error") + manifest := makeManifest("a.b.d: error") validator := MatchRegexValidator{"a[2]", "^hello", false} pass, diff := validator.Validate(&ValidateContext{ diff --git a/pkg/unittest/validators/snapshot_validator_test.go b/pkg/unittest/validators/snapshot_validator_test.go index 677124da2..97d32fc98 100644 --- a/pkg/unittest/validators/snapshot_validator_test.go +++ b/pkg/unittest/validators/snapshot_validator_test.go @@ -123,7 +123,7 @@ func TestSnapshotValidatorWhenNegativeAndFail(t *testing.T) { } func TestSnapshotValidatorWhenInvalidPath(t *testing.T) { - manifest := makeManifest("a:b") + manifest := makeManifest("a: b") cached := "a:\n b: c\n" mockComparer := new(mockSnapshotComparer) @@ -148,7 +148,7 @@ func TestSnapshotValidatorWhenInvalidPath(t *testing.T) { } func TestSnapshotValidatorWhenUnknownPath(t *testing.T) { - manifest := makeManifest("a:b") + manifest := makeManifest("a: b") cached := "a:\n b: c\n" mockComparer := new(mockSnapshotComparer) diff --git a/pkg/unittest/valueutils/documentselector_test.go b/pkg/unittest/valueutils/documentselector_test.go index 6c5e5774f..23d80b0c4 100644 --- a/pkg/unittest/valueutils/documentselector_test.go +++ b/pkg/unittest/valueutils/documentselector_test.go @@ -6,7 +6,6 @@ import ( "github.com/helm-unittest/helm-unittest/internal/common" . "github.com/helm-unittest/helm-unittest/pkg/unittest/valueutils" "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v3" ) var firstTemplateDocToTestIndex0 = ` @@ -61,10 +60,7 @@ func createMultiTemplateMultiManifest() map[string][]common.K8sManifest { } func parseManifest(manifest string) common.K8sManifest { - parsedManifest := common.K8sManifest{} - yaml.Unmarshal([]byte(manifest), &parsedManifest) - - return parsedManifest + return common.TrustedUnmarshalYAML(manifest) } func TestFindDocumentsIndexSinglePathOk(t *testing.T) { diff --git a/sonar-project.properties b/sonar-project.properties index a9c3edfe3..70851fccf 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.organization=helm-unittest # This is the name and version displayed in the SonarCloud UI. sonar.projectName=helm-unittest -sonar.projectVersion=0.6.4 +sonar.projectVersion=0.7.0 # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. # Define all sources and exclude test-, and vendor files. diff --git a/test/data/v3/with-subfolder/tests/deployment_test.yaml b/test/data/v3/with-subfolder/tests/deployment_test.yaml index 672e6ea68..fc4ffc1b1 100644 --- a/test/data/v3/with-subfolder/tests/deployment_test.yaml +++ b/test/data/v3/with-subfolder/tests/deployment_test.yaml @@ -102,3 +102,9 @@ tests: asserts: - notExists: path: spec.template.spec.volumes + - notLengthEqual: + path: spec.template.spec.volumes + count: 0 + - notLengthEqual: + path: spec.template.spec.volumes + count: 1