From d618d7b1ff669e28ed1f3c62ff3bba38f1ac5fe9 Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 27 Nov 2023 16:31:29 -0800 Subject: [PATCH 1/8] MVP: deployment snapshot & diff --- go.mod | 22 +++- go.sum | 73 ++++++++--- modules/helm/template.go | 97 ++++++++++++++ modules/helm/template_test.go | 86 +++++++++++++ ...a_remote_example_template_snapshot_test.go | 118 ++++++++++++++++++ 5 files changed, 378 insertions(+), 18 deletions(-) create mode 100644 test/helm_keda_remote_example_template_snapshot_test.go diff --git a/go.mod b/go.mod index 8ce7e1bcf..40a3a2830 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/oracle/oci-go-sdk v7.1.0+incompatible github.com/pquerna/otp v1.2.0 github.com/sirupsen/logrus v1.8.1 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.8.4 github.com/tmccombs/hcl2json v0.3.3 github.com/urfave/cli v1.22.2 github.com/zclconf/go-cty v1.9.1 @@ -48,6 +48,8 @@ require ( require ( cloud.google.com/go/cloudbuild v1.6.0 + github.com/gonvenience/ytbx v1.4.4 + github.com/homeport/dyff v1.6.0 github.com/slack-go/slack v0.10.3 gotest.tools/v3 v3.0.3 ) @@ -63,6 +65,7 @@ require ( github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/BurntSushi/toml v1.3.2 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect @@ -76,13 +79,18 @@ require ( github.com/docker/docker-credential-helpers v0.6.3 // indirect github.com/emicklei/go-restful/v3 v3.9.0 // indirect github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.1 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect + github.com/gonvenience/bunt v1.3.5 // indirect + github.com/gonvenience/neat v1.3.12 // indirect + github.com/gonvenience/term v1.0.2 // indirect + github.com/gonvenience/text v1.0.7 // indirect + github.com/gonvenience/wrap v1.1.2 // indirect github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.1.0 // indirect @@ -97,9 +105,14 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.15.11 // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/mitchellh/hashstructure v1.1.0 // indirect github.com/moby/spdystream v0.2.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect @@ -110,10 +123,13 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/satori/go.uuid v1.2.0 // indirect + github.com/sergi/go-diff v1.3.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/texttheater/golang-levenshtein v1.0.1 // indirect github.com/ulikunitz/xz v0.5.10 // indirect + github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74 // indirect go.opencensus.io v0.24.0 // indirect - golang.org/x/sync v0.1.0 // indirect + golang.org/x/sync v0.4.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect diff --git a/go.sum b/go.sum index da5296810..80b3bf8d8 100644 --- a/go.sum +++ b/go.sum @@ -225,6 +225,8 @@ github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= @@ -479,6 +481,8 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA= github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -498,8 +502,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -516,8 +520,8 @@ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+ github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M= @@ -574,6 +578,18 @@ github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/gonvenience/bunt v1.3.5 h1:wSQquifvwEWtzn27k1ngLfeLaStyt0k1b/K6TrlCNAs= +github.com/gonvenience/bunt v1.3.5/go.mod h1:7ApqkVBEWvX04oJ28Q2WeI/BvJM6VtukaJAU/q/pTs8= +github.com/gonvenience/neat v1.3.12 h1:xwIyRbJcG9LgcDYys+HHLH9DqqHeQsUpS5CfBUeskbs= +github.com/gonvenience/neat v1.3.12/go.mod h1:8OljAIgPelN0uPPO94VBqxK+Kz98d6ZFwHDg5o/PfkE= +github.com/gonvenience/term v1.0.2 h1:qKa2RydbWIrabGjR/fegJwpW5m+JvUwFL8mLhHzDXn0= +github.com/gonvenience/term v1.0.2/go.mod h1:wThTR+3MzWtWn7XGVW6qQ65uaVf8GHED98KmwpuEQeo= +github.com/gonvenience/text v1.0.7 h1:YmIqmgTwxnACYCG59DykgMbomwteYyNhAmEUEJtPl14= +github.com/gonvenience/text v1.0.7/go.mod h1:OAjH+mohRszffLY6OjgQcUXiSkbrIavooFpfIt1ZwAs= +github.com/gonvenience/wrap v1.1.2 h1:xPKxNwL1HCguwyM+HlP/1CIuc9LRd7k8RodLwe9YTZA= +github.com/gonvenience/wrap v1.1.2/go.mod h1:GiryBSXoI3BAAhbWD1cZVj7RZmtiu0ERi/6R6eJfslI= +github.com/gonvenience/ytbx v1.4.4 h1:jQopwyaLsVGuwdxSiN4WkXjsEaFNPJ3V4lUj7eyEpzo= +github.com/gonvenience/ytbx v1.4.4/go.mod h1:w37+MKCPcCMY/jpPNmEklD4xKqrOAVBO6kIWW2+uI6M= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54= @@ -618,8 +634,9 @@ github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= +github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -648,6 +665,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR github.com/gorilla/handlers v0.0.0-20150720190736-60c7bfde3e33/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ= github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= +github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= +github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= @@ -699,6 +718,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hashicorp/terraform-json v0.13.0 h1:Li9L+lKD1FO5RVFRM1mMMIBDoUHslOniyEi5CM+FWGY= github.com/hashicorp/terraform-json v0.13.0/go.mod h1:y5OdLBCT+rxbwnpxZs9kGL7R9ExU76+cpdY8zHwoazk= +github.com/homeport/dyff v1.6.0 h1:AN+ikld0Fy+qx34YE7655b/bpWuxS6cL9k852pE2GUc= +github.com/homeport/dyff v1.6.0/go.mod h1:FlAOFYzeKvxmU5nTrnG+qrlJVWpsFew7pt8L99p5q8k= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -759,6 +780,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= @@ -768,12 +791,16 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7 github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= +github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 h1:BXxTozrOU8zgC5dkpn3J6NTRdoP+hjok/e+ACr4Hibk= +github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3/go.mod h1:x1uk6vxTiVuNt6S5R2UYgdhpj3oKojXvOXauHZ7dEnI= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o= @@ -792,6 +819,8 @@ github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HK github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= +github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= @@ -799,6 +828,8 @@ github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZX github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0= +github.com/mitchellh/hashstructure v1.1.0/go.mod h1:xUDAozZz0Wmdiufv0uyhnHkUTN6/6d8ulp4AwfLKrmA= github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= @@ -829,6 +860,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -837,17 +870,18 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1 h1:mFwc4LvZ0xpSvDZ3E+k8Yte0hLOMxXUlP+yXtJqkYfQ= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk= -github.com/onsi/ginkgo/v2 v2.9.1/go.mod h1:FEcmzVcCHl+4o9bQZVab+4dC9+j+91t2FHSzmGAPfuo= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= +github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= -github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E= -github.com/onsi/gomega v1.27.4/go.mod h1:riYq/GJKh8hhoM01HN6Vmuy93AarCXCBGpvFDK3q3fQ= +github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c= +github.com/onsi/gomega v1.28.0/go.mod h1:A1H2JE76sI14WIP57LMKj7FVfCHx3g3BcZVjJG8bjX8= github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= @@ -935,6 +969,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/sebdah/goldie v1.0.0/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= @@ -989,13 +1025,16 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I= +github.com/texttheater/golang-levenshtein v1.0.1 h1:+cRNoVrfiwufQPhoMzB6N0Yf/Mqajr6t1lOv8GyGE2U= +github.com/texttheater/golang-levenshtein v1.0.1/go.mod h1:PYAKrbF5sAiq9wd+H82hs7gNaen0CplQ9uvm6+enD/8= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ= @@ -1008,6 +1047,8 @@ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijb github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74 h1:JwtAtbp7r/7QSyGz8mKUbYJBg2+6Cd7OjM8o/GNOcVo= +github.com/virtuald/go-ordered-json v0.0.0-20170621173500-b18e6e673d74/go.mod h1:RmMWU37GKR2s6pgrIEB4ixgpVCt/cf7dnJv3fuH1J1c= github.com/vishvananda/netlink v0.0.0-20181108222139-023a6dafdcdf/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk= github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= @@ -1227,8 +1268,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1335,6 +1376,7 @@ golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1422,8 +1464,8 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= -golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1682,6 +1724,7 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/modules/helm/template.go b/modules/helm/template.go index a9070e12d..90c156a4e 100644 --- a/modules/helm/template.go +++ b/modules/helm/template.go @@ -11,6 +11,12 @@ import ( "github.com/gruntwork-io/terratest/modules/files" "github.com/gruntwork-io/terratest/modules/testing" + + "fmt" + "os" + + "github.com/gonvenience/ytbx" + "github.com/homeport/dyff/pkg/dyff" ) // RenderTemplate runs `helm template` to render the template given the provided options and returns stdout/stderr from @@ -134,3 +140,94 @@ func UnmarshalK8SYamlE(t testing.TestingT, yamlData string, destinationObj inter } return nil } + +// Create/update the manifest snapshot of a chart (e.g bitnami/nginx) +func UpdateSnapshot(yamlData string, releaseName string) { + + snapshotDir := "__snapshot__" + // Create a directory if not exists + if !files.FileExists(snapshotDir) { + os.Mkdir(snapshotDir, 0755) + } + + filename := snapshotDir + "/" + releaseName + ".yaml" + // Open a file in write mode + file, err := os.Create(filename) + if err != nil { + fmt.Println("Error creating file:", err) + return + } + defer file.Close() + + // Write the string representation of the "deployment" variable to the file + _, err = file.WriteString(yamlData) + if err != nil { + fmt.Println("Error writing to file: ", filename, err) + return + } + + fmt.Println("Content written to file successfully.", filename) +} + +// Create/update the manifest snapshot of a chart (e.g bitnami/nginx) +func DiffAgainstSnapshot(yamlData string, releaseName string) int { + + snapshotDir := "__snapshot__" + + filename := snapshotDir + "/" + releaseName + ".yaml" + from, err := ytbx.LoadFile(filename) + if err != nil { + fmt.Println("Error opening file:", err) + return 1 + } + + filename2 := releaseName + ".yaml" + // Open a file in write mode + file, err := os.Create(filename2) + if err != nil { + fmt.Println("Error creating file:", err) + return 1 + } + + // Write the string representation of the "deployment" variable to the file + _, err = file.WriteString(yamlData) + if err != nil { + fmt.Println("Error writing to file: ", filename2, err) + return 1 + } + + defer file.Close() + + to, err := ytbx.LoadFile(filename2) + if err != nil { + fmt.Println("Error opening file:", err) + return 1 + } + + compOpt := dyff.KubernetesEntityDetection(false) + + Report, err := dyff.CompareInputFiles(from, to, compOpt) + if err != nil { + fmt.Println("Error opening file:", err) + return 1 + } + + reportWriter := &dyff.HumanReport{ + Report: Report, + DoNotInspectCerts: false, + NoTableStyle: false, + OmitHeader: false, + UseGoPatchPaths: false, + } + + number_of_diffs := len(reportWriter.Diffs) + + writer := os.Stdout + reportWriter.WriteReport(writer) + + // if different, print diff + // if same, print "no diff" + + defer file.Close() + return number_of_diffs +} diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index 1c212099b..01fdf0b00 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -65,3 +65,89 @@ func TestRemoteChartRender(t *testing.T) { require.Equal(t, len(deploymentContainers), 1) require.Equal(t, deploymentContainers[0].Image, expectedContainerImage) } + +// Test that we can dump all the manifest locally a remote chart (e.g bitnami/nginx) +// so that I can use them later to compare between two versions of the same chart for example +func TestRemoteChartRenderDump(t *testing.T) { + const ( + remoteChartSource = "https://charts.bitnami.com/bitnami" + remoteChartName = "nginx" + remoteChartVersion = "13.2.20" + ) + + t.Parallel() + + namespaceName := "dump-ns" + + releaseName := remoteChartName + + options := &Options{ + SetValues: map[string]string{ + "image.repository": remoteChartName, + "image.registry": "", + "image.tag": remoteChartVersion, + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + output := RenderRemoteTemplate(t, options, remoteChartSource, releaseName, []string{}) + + // Now we use kubernetes/client-go library to render the template output into the Deployment struct. This will + // ensure the Deployment resource is rendered correctly. + var deployment appsv1.Deployment + UnmarshalK8SYaml(t, output, &deployment) + + // Verify the namespace matches the expected supplied namespace. + require.Equal(t, namespaceName, deployment.Namespace) + + // write chart manifest to a local filesystem directory + UpdateSnapshot(output, releaseName) +} + +// Test that we can diff all the manifest to a local snapshot using a remote chart (e.g bitnami/nginx) +func TestRemoteChartRenderDiff(t *testing.T) { + const ( + remoteChartSource = "https://charts.bitnami.com/bitnami" + remoteChartName = "nginx" + remoteChartVersion = "13.2.23" + ) + + t.Parallel() + + // namespaceName := fmt.Sprintf( + // "%s-%s", + // strings.ToLower(t.Name()), + // strings.ToLower(random.UniqueId()), + // ) + // need to set a fix name for the namespace so that we can compare the snapshot + namespaceName := "dump-ns" + + releaseName := remoteChartName + + options := &Options{ + SetValues: map[string]string{ + "image.repository": remoteChartName, + "image.registry": "", + "image.tag": remoteChartVersion, + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + output := RenderRemoteTemplate(t, options, remoteChartSource, releaseName, []string{}) + + // Now we use kubernetes/client-go library to render the template output into the Deployment struct. This will + // ensure the Deployment resource is rendered correctly. + var deployment appsv1.Deployment + UnmarshalK8SYaml(t, output, &deployment) + + // Verify the namespace matches the expected supplied namespace. + require.Equal(t, namespaceName, deployment.Namespace) + + // run the diff and assert the number of diffs + number_of_diffs := DiffAgainstSnapshot(output, releaseName) + require.Equal(t, number_of_diffs, 0) +} diff --git a/test/helm_keda_remote_example_template_snapshot_test.go b/test/helm_keda_remote_example_template_snapshot_test.go new file mode 100644 index 000000000..577a72e42 --- /dev/null +++ b/test/helm_keda_remote_example_template_snapshot_test.go @@ -0,0 +1,118 @@ +//go:build kubeall || helm +// +build kubeall helm + +// **NOTE**: we have build tags to differentiate kubernetes tests from non-kubernetes tests, and further differentiate helm +// tests. This is done because minikube is heavy and can interfere with docker related tests in terratest. Similarly, helm +// can overload the minikube system and thus interfere with the other kubernetes tests. Specifically, many of the tests +// start to fail with `connection refused` errors from `minikube`. To avoid overloading the system, we run the kubernetes +// tests and helm tests separately from the others. This may not be necessary if you have a sufficiently powerful machine. +// We recommend at least 4 cores and 16GB of RAM if you want to run all the tests together. + +package test + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/require" + appsv1 "k8s.io/api/apps/v1" + + "github.com/gruntwork-io/terratest/modules/helm" + "github.com/gruntwork-io/terratest/modules/k8s" + "github.com/gruntwork-io/terratest/modules/logger" + "github.com/gruntwork-io/terratest/modules/random" +) + +// This file contains an example of how to use terratest to test *remote* helm chart template logic by rendering the templates +// using `helm template`, and then reading in the rendered templates. +// - TestHelmKedaRemoteExampleTemplateRenderedDeployment: An example of how to read in the rendered object and check the +// computed values. + +// An example of how to verify the rendered template object of a Helm Chart given various inputs. +func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDump(t *testing.T) { + t.Parallel() + + // chart name + releaseName := "keda" + + // Set up the namespace; confirm that the template renders the expected value for the namespace. + namespaceName := "medieval-" + strings.ToLower(random.UniqueId()) + logger.Logf(t, "Namespace: %s\n", namespaceName) + + // Setup the args. For this test, we will set the following input values: + options := &helm.Options{ + SetValues: map[string]string{ + "metricsServer.replicaCount": "999", + "resources.metricServer.limits.memory": "1234Mi", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + // Additionally, we path a the templateFile for which we are setting test values to + // demonstrate how to select individual templates to render. + output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{"templates/metrics-server/deployment.yaml"}) + + // Now we use kubernetes/client-go library to render the template output into the Deployment struct. This will + // ensure the Deployment resource is rendered correctly. + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(t, output, &deployment) + + // Verify the namespace matches the expected supplied namespace. + require.Equal(t, namespaceName, deployment.Namespace) + + // Finally, we verify the deployment pod template spec is set to the expected container image value + var expectedMetricsServerReplica int32 + expectedMetricsServerReplica = 999 + deploymentMetricsServerReplica := *deployment.Spec.Replicas + require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) + + // write chart manifest to a local filesystem directory + helm.UpdateSnapshot(output, releaseName) +} + +// An example of how to verify the rendered template object of a Helm Chart given various inputs. +func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { + t.Parallel() + + // chart name + releaseName := "keda" + + // Set up the namespace; confirm that the template renders the expected value for the namespace. + namespaceName := "medieval-" + strings.ToLower(random.UniqueId()) + logger.Logf(t, "Namespace: %s\n", namespaceName) + + // Setup the args. For this test, we will set the following input values: + options := &helm.Options{ + SetValues: map[string]string{ + "metricsServer.replicaCount": "666", + "resources.metricServer.limits.memory": "4321Mi", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + // Additionally, we path a the templateFile for which we are setting test values to + // demonstrate how to select individual templates to render. + output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{"templates/metrics-server/deployment.yaml"}) + + // Now we use kubernetes/client-go library to render the template output into the Deployment struct. This will + // ensure the Deployment resource is rendered correctly. + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(t, output, &deployment) + + // Verify the namespace matches the expected supplied namespace. + require.Equal(t, namespaceName, deployment.Namespace) + + // Finally, we verify the deployment pod template spec is set to the expected container image value + var expectedMetricsServerReplica int32 + expectedMetricsServerReplica = 666 + deploymentMetricsServerReplica := *deployment.Spec.Replicas + require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) + + // run the diff and assert the number of diffs + number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) + require.Equal(t, number_of_diffs, 0) +} From 2a35a408c1a1062b9615ff0ac1742e9fd6585b91 Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Fri, 1 Dec 2023 17:09:18 -0800 Subject: [PATCH 2/8] Snapshot based testing --- modules/helm/template.go | 42 +++++++------ modules/helm/template_test.go | 20 ++---- test/fixtures/helm/keda-values.yaml | 30 +++++++++ ...a_remote_example_template_snapshot_test.go | 61 +++++++++++++++++++ .../helm_keda_remote_example_template_test.go | 46 ++++++++++++++ 5 files changed, 164 insertions(+), 35 deletions(-) create mode 100644 test/fixtures/helm/keda-values.yaml diff --git a/modules/helm/template.go b/modules/helm/template.go index 90c156a4e..054e8f2ff 100644 --- a/modules/helm/template.go +++ b/modules/helm/template.go @@ -141,7 +141,9 @@ func UnmarshalK8SYamlE(t testing.TestingT, yamlData string, destinationObj inter return nil } -// Create/update the manifest snapshot of a chart (e.g bitnami/nginx) +// Add snapshot based testing for helm +// see https://github.com/gruntwork-io/terratest/issues/1377 +// This function create/update the manifest snapshot of a chart (e.g bitnami/nginx) func UpdateSnapshot(yamlData string, releaseName string) { snapshotDir := "__snapshot__" @@ -159,59 +161,63 @@ func UpdateSnapshot(yamlData string, releaseName string) { } defer file.Close() - // Write the string representation of the "deployment" variable to the file + // Write the k8s manifest into the file _, err = file.WriteString(yamlData) if err != nil { fmt.Println("Error writing to file: ", filename, err) return } - fmt.Println("Content written to file successfully.", filename) + fmt.Println("k8s manifest written into file: ", filename) } -// Create/update the manifest snapshot of a chart (e.g bitnami/nginx) +// Add snapshot based testing for helm +// see https://github.com/gruntwork-io/terratest/issues/1377 +// This function compare the manifest snapshot of a chart (e.g bitnami/nginx) with the current manifest func DiffAgainstSnapshot(yamlData string, releaseName string) int { snapshotDir := "__snapshot__" - filename := snapshotDir + "/" + releaseName + ".yaml" - from, err := ytbx.LoadFile(filename) + // load the yaml snapshot file + snapshot := snapshotDir + "/" + releaseName + ".yaml" + from, err := ytbx.LoadFile(snapshot) if err != nil { fmt.Println("Error opening file:", err) return 1 } - filename2 := releaseName + ".yaml" - // Open a file in write mode - file, err := os.Create(filename2) + // write the current manifest into a file as `dyff` does not support string input + currentManifests := releaseName + ".yaml" + file, err := os.Create(currentManifests) if err != nil { fmt.Println("Error creating file:", err) return 1 } - - // Write the string representation of the "deployment" variable to the file _, err = file.WriteString(yamlData) if err != nil { - fmt.Println("Error writing to file: ", filename2, err) + fmt.Println("Error writing to file: ", currentManifests, err) return 1 } - defer file.Close() + defer os.Remove(currentManifests) - to, err := ytbx.LoadFile(filename2) + to, err := ytbx.LoadFile(currentManifests) if err != nil { fmt.Println("Error opening file:", err) return 1 } + // compare the two manifests using `dyff` compOpt := dyff.KubernetesEntityDetection(false) + // create a report Report, err := dyff.CompareInputFiles(from, to, compOpt) if err != nil { fmt.Println("Error opening file:", err) return 1 } + // write any difference to stdout reportWriter := &dyff.HumanReport{ Report: Report, DoNotInspectCerts: false, @@ -220,14 +226,10 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { UseGoPatchPaths: false, } - number_of_diffs := len(reportWriter.Diffs) - writer := os.Stdout reportWriter.WriteReport(writer) - // if different, print diff - // if same, print "no diff" - - defer file.Close() + // return the number of diffs to use in in assertion while testing: 0 = no differences + number_of_diffs := len(reportWriter.Diffs) return number_of_diffs } diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index 01fdf0b00..3870a459a 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -73,12 +73,12 @@ func TestRemoteChartRenderDump(t *testing.T) { remoteChartSource = "https://charts.bitnami.com/bitnami" remoteChartName = "nginx" remoteChartVersion = "13.2.20" + // need to set a fix name for the namespace so it is not flag as a difference + namespaceName = "dump-ns" ) t.Parallel() - namespaceName := "dump-ns" - releaseName := remoteChartName options := &Options{ @@ -112,20 +112,13 @@ func TestRemoteChartRenderDiff(t *testing.T) { remoteChartSource = "https://charts.bitnami.com/bitnami" remoteChartName = "nginx" remoteChartVersion = "13.2.23" + // need to set a fix name for the namespace so it is not flag as a difference + namespaceName = "dump-ns" ) t.Parallel() - // namespaceName := fmt.Sprintf( - // "%s-%s", - // strings.ToLower(t.Name()), - // strings.ToLower(random.UniqueId()), - // ) - // need to set a fix name for the namespace so that we can compare the snapshot - namespaceName := "dump-ns" - releaseName := remoteChartName - options := &Options{ SetValues: map[string]string{ "image.repository": remoteChartName, @@ -144,10 +137,7 @@ func TestRemoteChartRenderDiff(t *testing.T) { var deployment appsv1.Deployment UnmarshalK8SYaml(t, output, &deployment) - // Verify the namespace matches the expected supplied namespace. - require.Equal(t, namespaceName, deployment.Namespace) - - // run the diff and assert the number of diffs + // run the diff and assert there are no differences number_of_diffs := DiffAgainstSnapshot(output, releaseName) require.Equal(t, number_of_diffs, 0) } diff --git a/test/fixtures/helm/keda-values.yaml b/test/fixtures/helm/keda-values.yaml new file mode 100644 index 000000000..6dc15cf75 --- /dev/null +++ b/test/fixtures/helm/keda-values.yaml @@ -0,0 +1,30 @@ +metricsServer: + replicaCount: 3 +operator: + name: keda-operator + replicaCount: 3 +podAnnotations: + keda: + sidecar.istio.io/inject: "false" + metricsAdapter: + sidecar.istio.io/inject: "false" +podDisruptionBudget: + metricServer: + minAvailable: 1 + operator: + minAvailable: 1 +resources: + metricServer: + limits: + cpu: 100m + memory: 1234Mi + requests: + cpu: 50m + memory: 128Mi + operator: + limits: + cpu: 100m + memory: 1111Mi + requests: + cpu: 50m + memory: 888Mi diff --git a/test/helm_keda_remote_example_template_snapshot_test.go b/test/helm_keda_remote_example_template_snapshot_test.go index 577a72e42..8b3e8eb8f 100644 --- a/test/helm_keda_remote_example_template_snapshot_test.go +++ b/test/helm_keda_remote_example_template_snapshot_test.go @@ -116,3 +116,64 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) require.Equal(t, number_of_diffs, 0) } + +// An example of how to store a snapshot of the current manaifest for future comparison +func TestHelmKedaRemoteExampleTemplateRenderedPackageDump(t *testing.T) { + t.Parallel() + + // chart name + releaseName := "keda" + + // Set up the namespace; confirm that the template renders the expected value for the namespace. + namespaceName := "medieval-" + strings.ToLower(random.UniqueId()) + logger.Logf(t, "Namespace: %s\n", namespaceName) + + // Setup the args. For this test, we will set the following input values: + options := &helm.Options{ + SetValues: map[string]string{ + "metricsServer.replicaCount": "999", + "resources.metricServer.limits.memory": "1234Mi", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + // Additionally, we path a the templateFile for which we are setting test values to + // demonstrate how to select individual templates to render. + output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) + + // write chart manifest to a local filesystem directory + helm.UpdateSnapshot(output, releaseName) +} + +// An example of how to verify the current helm k8s manifest against a previous snapshot +func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { + t.Parallel() + + // chart name + releaseName := "keda" + + // Set up the namespace; confirm that the template renders the expected value for the namespace. + namespaceName := "medieval-" + strings.ToLower(random.UniqueId()) + logger.Logf(t, "Namespace: %s\n", namespaceName) + + // Setup the args. For this test, we will set the following input values: + options := &helm.Options{ + SetValues: map[string]string{ + "metricsServer.replicaCount": "666", + "resources.metricServer.limits.memory": "4321Mi", + }, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + // Additionally, we path a the templateFile for which we are setting test values to + // demonstrate how to select individual templates to render. + output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) + + // run the diff and assert the number of diffs + number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) + require.Equal(t, number_of_diffs, 0) +} diff --git a/test/helm_keda_remote_example_template_test.go b/test/helm_keda_remote_example_template_test.go index dbf6bbc59..8eabec7c6 100644 --- a/test/helm_keda_remote_example_template_test.go +++ b/test/helm_keda_remote_example_template_test.go @@ -67,4 +67,50 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeployment(t *testing.T) { expectedMetricsServerReplica = 999 deploymentMetricsServerReplica := *deployment.Spec.Replicas require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) + expectedContainerRLM := "1234Mi" + deploymentContainers := deployment.Spec.Template.Spec.Containers + require.Equal(t, len(deploymentContainers), 1) + currentContainerRLM := deploymentContainers[0].Resources.Limits.Memory().String() + require.Equal(t, currentContainerRLM, expectedContainerRLM) +} + +// An example of how to verify the rendered template object of a Helm Chart given input from a `values.yaml` file. +func TestHelmKedaRemoteExampleTemplateRenderedValuesFileFixtureDeployment(t *testing.T) { + t.Parallel() + + // chart name + releaseName := "keda" + + // Set up the namespace; confirm that the template renders the expected value for the namespace. + namespaceName := "medieval-" + strings.ToLower(random.UniqueId()) + logger.Logf(t, "Namespace: %s\n", namespaceName) + options := &helm.Options{ + ValuesFiles: []string{"./fixtures/helm/keda-values.yaml"}, + KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + } + + // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since + // we want to assert that the template renders without any errors. + // Additionally, we path a the templateFile for which we are setting test values to + // demonstrate how to select individual templates to render. + output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{"templates/metrics-server/deployment.yaml"}) + + // Now we use kubernetes/client-go library to render the template output into the Deployment struct. This will + // ensure the Deployment resource is rendered correctly. + var deployment appsv1.Deployment + helm.UnmarshalK8SYaml(t, output, &deployment) + + // Verify the namespace matches the expected supplied namespace. + require.Equal(t, namespaceName, deployment.Namespace) + + // Finally, we verify the deployment pod template spec is set to the expected value + var expectedMetricsServerReplica int32 + expectedMetricsServerReplica = 3 + deploymentMetricsServerReplica := *deployment.Spec.Replicas + require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) + expectedContainerRLM := "1234Mi" + deploymentContainers := deployment.Spec.Template.Spec.Containers + require.Equal(t, len(deploymentContainers), 1) + currentContainerRLM := deploymentContainers[0].Resources.Limits.Memory().String() + require.Equal(t, currentContainerRLM, expectedContainerRLM) } From 852433e5b4117a6f93dee24cce6a02b45579820e Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 11 Dec 2023 17:11:11 -0800 Subject: [PATCH 3/8] Change the snapshot diff test so it passes --- modules/helm/template_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index 3870a459a..6db5db24d 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -137,7 +137,7 @@ func TestRemoteChartRenderDiff(t *testing.T) { var deployment appsv1.Deployment UnmarshalK8SYaml(t, output, &deployment) - // run the diff and assert there are no differences + // run the diff and assert there is one difference: the image name number_of_diffs := DiffAgainstSnapshot(output, releaseName) - require.Equal(t, number_of_diffs, 0) + require.Equal(t, 1, number_of_diffs) } From a13ceded17757ef70fd8174314ab29c38c54d7c3 Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 11 Dec 2023 17:17:04 -0800 Subject: [PATCH 4/8] Change the test so it passes while still showing some diffs --- modules/helm/template_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index 6db5db24d..d1d097d21 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -137,7 +137,7 @@ func TestRemoteChartRenderDiff(t *testing.T) { var deployment appsv1.Deployment UnmarshalK8SYaml(t, output, &deployment) - // run the diff and assert there is one difference: the image name + // run the diff and assert there is only one difference: the image name number_of_diffs := DiffAgainstSnapshot(output, releaseName) require.Equal(t, 1, number_of_diffs) } From ffefe30d06edaa481739d64f0132d42bde0c7f4f Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 11 Dec 2023 17:45:08 -0800 Subject: [PATCH 5/8] Order tests and assert pass vs failed --- .../helm_keda_remote_example_template_snapshot_test.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/helm_keda_remote_example_template_snapshot_test.go b/test/helm_keda_remote_example_template_snapshot_test.go index 8b3e8eb8f..36a98ce02 100644 --- a/test/helm_keda_remote_example_template_snapshot_test.go +++ b/test/helm_keda_remote_example_template_snapshot_test.go @@ -30,7 +30,6 @@ import ( // An example of how to verify the rendered template object of a Helm Chart given various inputs. func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDump(t *testing.T) { - t.Parallel() // chart name releaseName := "keda" @@ -74,7 +73,6 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDump(t *testing.T) { // An example of how to verify the rendered template object of a Helm Chart given various inputs. func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { - t.Parallel() // chart name releaseName := "keda" @@ -114,12 +112,11 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { // run the diff and assert the number of diffs number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) - require.Equal(t, number_of_diffs, 0) + require.Equal(t, 4, number_of_diffs) } // An example of how to store a snapshot of the current manaifest for future comparison func TestHelmKedaRemoteExampleTemplateRenderedPackageDump(t *testing.T) { - t.Parallel() // chart name releaseName := "keda" @@ -149,7 +146,6 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDump(t *testing.T) { // An example of how to verify the current helm k8s manifest against a previous snapshot func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { - t.Parallel() // chart name releaseName := "keda" @@ -173,7 +169,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { // demonstrate how to select individual templates to render. output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) - // run the diff and assert the number of diffs + // run the diff and assert the number of diffs matches the number of diffs in the snapshot number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) - require.Equal(t, number_of_diffs, 0) + require.Equal(t, 18, number_of_diffs) } From b8087b13513e0aa348a139c076f22c803a544f6d Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Thu, 14 Dec 2023 18:01:20 -0800 Subject: [PATCH 6/8] Fix review comments --- modules/helm/template.go | 43 ++++++++++--------- modules/helm/template_test.go | 7 +-- ...a_remote_example_template_snapshot_test.go | 6 +-- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/modules/helm/template.go b/modules/helm/template.go index 054e8f2ff..ff1c82b61 100644 --- a/modules/helm/template.go +++ b/modules/helm/template.go @@ -141,15 +141,20 @@ func UnmarshalK8SYamlE(t testing.TestingT, yamlData string, destinationObj inter return nil } -// Add snapshot based testing for helm +// UpdateSnapshot creates or updates the k8s manifest snapshot of a chart (e.g bitnami/nginx). +// It is one of the two functions needed to implement snapshot based testing for helm. // see https://github.com/gruntwork-io/terratest/issues/1377 -// This function create/update the manifest snapshot of a chart (e.g bitnami/nginx) +// A snapshot is used to compare the current manifests of a chart with the previous manifests. +// A global diff is run against the two snapshost and the number of differences is returned. func UpdateSnapshot(yamlData string, releaseName string) { snapshotDir := "__snapshot__" // Create a directory if not exists if !files.FileExists(snapshotDir) { - os.Mkdir(snapshotDir, 0755) + if err := os.Mkdir(snapshotDir, 0755); err != nil { + fmt.Println("Error creating directory:", err) + return + } } filename := snapshotDir + "/" + releaseName + ".yaml" @@ -162,8 +167,7 @@ func UpdateSnapshot(yamlData string, releaseName string) { defer file.Close() // Write the k8s manifest into the file - _, err = file.WriteString(yamlData) - if err != nil { + if _, err = file.WriteString(yamlData); err != nil { fmt.Println("Error writing to file: ", filename, err) return } @@ -171,9 +175,10 @@ func UpdateSnapshot(yamlData string, releaseName string) { fmt.Println("k8s manifest written into file: ", filename) } -// Add snapshot based testing for helm +// DiffAgainstSnapshot compare the current manifests of a chart (e.g bitnami/nginx) +// with the previous manifests stored in the snapshot. // see https://github.com/gruntwork-io/terratest/issues/1377 -// This function compare the manifest snapshot of a chart (e.g bitnami/nginx) with the current manifest +// It returns the number of difference between the two manifest snaphost or -1 in case of error func DiffAgainstSnapshot(yamlData string, releaseName string) int { snapshotDir := "__snapshot__" @@ -183,7 +188,7 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { from, err := ytbx.LoadFile(snapshot) if err != nil { fmt.Println("Error opening file:", err) - return 1 + return -1 } // write the current manifest into a file as `dyff` does not support string input @@ -191,12 +196,12 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { file, err := os.Create(currentManifests) if err != nil { fmt.Println("Error creating file:", err) - return 1 + return -1 } - _, err = file.WriteString(yamlData) - if err != nil { + + if _, err = file.WriteString(yamlData); err != nil { fmt.Println("Error writing to file: ", currentManifests, err) - return 1 + return -1 } defer file.Close() defer os.Remove(currentManifests) @@ -204,32 +209,30 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { to, err := ytbx.LoadFile(currentManifests) if err != nil { fmt.Println("Error opening file:", err) - return 1 + return -1 } // compare the two manifests using `dyff` compOpt := dyff.KubernetesEntityDetection(false) // create a report - Report, err := dyff.CompareInputFiles(from, to, compOpt) + report, err := dyff.CompareInputFiles(from, to, compOpt) if err != nil { fmt.Println("Error opening file:", err) - return 1 + return -1 } // write any difference to stdout reportWriter := &dyff.HumanReport{ - Report: Report, + Report: report, DoNotInspectCerts: false, NoTableStyle: false, OmitHeader: false, UseGoPatchPaths: false, } - writer := os.Stdout - reportWriter.WriteReport(writer) + reportWriter.WriteReport(os.Stdout) // return the number of diffs to use in in assertion while testing: 0 = no differences - number_of_diffs := len(reportWriter.Diffs) - return number_of_diffs + return len(reportWriter.Diffs) } diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index d1d097d21..b9a72f75f 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -77,8 +77,6 @@ func TestRemoteChartRenderDump(t *testing.T) { namespaceName = "dump-ns" ) - t.Parallel() - releaseName := remoteChartName options := &Options{ @@ -116,8 +114,6 @@ func TestRemoteChartRenderDiff(t *testing.T) { namespaceName = "dump-ns" ) - t.Parallel() - releaseName := remoteChartName options := &Options{ SetValues: map[string]string{ @@ -138,6 +134,5 @@ func TestRemoteChartRenderDiff(t *testing.T) { UnmarshalK8SYaml(t, output, &deployment) // run the diff and assert there is only one difference: the image name - number_of_diffs := DiffAgainstSnapshot(output, releaseName) - require.Equal(t, 1, number_of_diffs) + require.Equal(t, 1, DiffAgainstSnapshot(output, releaseName)) } diff --git a/test/helm_keda_remote_example_template_snapshot_test.go b/test/helm_keda_remote_example_template_snapshot_test.go index 36a98ce02..28ac5bdc7 100644 --- a/test/helm_keda_remote_example_template_snapshot_test.go +++ b/test/helm_keda_remote_example_template_snapshot_test.go @@ -111,8 +111,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) // run the diff and assert the number of diffs - number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) - require.Equal(t, 4, number_of_diffs) + require.Equal(t, 4, helm.DiffAgainstSnapshot(output, releaseName)) } // An example of how to store a snapshot of the current manaifest for future comparison @@ -170,6 +169,5 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) // run the diff and assert the number of diffs matches the number of diffs in the snapshot - number_of_diffs := helm.DiffAgainstSnapshot(output, releaseName) - require.Equal(t, 18, number_of_diffs) + require.Equal(t, 18, helm.DiffAgainstSnapshot(output, releaseName)) } From 6ea6eff5bbba011abeabeda8f8d6358ccb8e16a9 Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 18 Dec 2023 16:47:33 -0800 Subject: [PATCH 7/8] Aligned with function patterns and other patterns Added an option for snaphsot directory go mod tidy --- go.mod | 3 +- modules/helm/options.go | 1 + modules/helm/template.go | 81 ++++++++++++------- modules/helm/template_test.go | 17 +++- ...a_remote_example_template_snapshot_test.go | 12 ++- .../helm_keda_remote_example_template_test.go | 2 + 6 files changed, 77 insertions(+), 39 deletions(-) diff --git a/go.mod b/go.mod index 30c1704c0..02e367f71 100644 --- a/go.mod +++ b/go.mod @@ -47,9 +47,9 @@ require ( ) require ( + cloud.google.com/go/cloudbuild v1.9.0 github.com/gonvenience/ytbx v1.4.4 github.com/homeport/dyff v1.6.0 - cloud.google.com/go/cloudbuild v1.9.0 github.com/slack-go/slack v0.10.3 gotest.tools/v3 v3.0.3 ) @@ -91,7 +91,6 @@ require ( github.com/gonvenience/term v1.0.2 // indirect github.com/gonvenience/text v1.0.7 // indirect github.com/gonvenience/wrap v1.1.2 // indirect - github.com/google/gnostic v0.5.7-v3refs // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.5.9 // indirect github.com/google/gofuzz v1.2.0 // indirect diff --git a/modules/helm/options.go b/modules/helm/options.go index bafdedea4..da210ef1b 100644 --- a/modules/helm/options.go +++ b/modules/helm/options.go @@ -18,4 +18,5 @@ type Options struct { Logger *logger.Logger // Set a non-default logger that should be used. See the logger package for more info. Use logger.Discard to not print the output while executing the command. ExtraArgs map[string][]string // Extra arguments to pass to the helm install/upgrade/rollback/delete and helm repo add commands. The key signals the command (e.g., install) while the values are the extra arguments to pass through. BuildDependencies bool // If true, helm dependencies will be built before rendering template, installing or upgrade the chart. + SnapshotPath string // The path to the snapshot directory when using snapshot based testing. Empty string means use default ($PWD/__snapshot__). } diff --git a/modules/helm/template.go b/modules/helm/template.go index ff1c82b61..8f0b321db 100644 --- a/modules/helm/template.go +++ b/modules/helm/template.go @@ -12,7 +12,6 @@ import ( "github.com/gruntwork-io/terratest/modules/files" "github.com/gruntwork-io/terratest/modules/testing" - "fmt" "os" "github.com/gonvenience/ytbx" @@ -145,71 +144,94 @@ func UnmarshalK8SYamlE(t testing.TestingT, yamlData string, destinationObj inter // It is one of the two functions needed to implement snapshot based testing for helm. // see https://github.com/gruntwork-io/terratest/issues/1377 // A snapshot is used to compare the current manifests of a chart with the previous manifests. -// A global diff is run against the two snapshost and the number of differences is returned. -func UpdateSnapshot(yamlData string, releaseName string) { +// A global diff is run against the two snapshosts and the number of differences is returned. +func UpdateSnapshot(t testing.TestingT, options *Options, yamlData string, releaseName string) { + require.NoError(t, UpdateSnapshotE(t, options, yamlData, releaseName)) +} + +// UpdateSnapshot creates or updates the k8s manifest snapshot of a chart (e.g bitnami/nginx). +// It is one of the two functions needed to implement snapshot based testing for helm. +// see https://github.com/gruntwork-io/terratest/issues/1377 +// A snapshot is used to compare the current manifests of a chart with the previous manifests. +// A global diff is run against the two snapshosts and the number of differences is returned. +// It will failed the test if there is an error while writing the manifests' snapshot in the file system +func UpdateSnapshotE(t testing.TestingT, options *Options, yamlData string, releaseName string) error { - snapshotDir := "__snapshot__" + var snapshotDir = "__snapshot__" + if options.SnapshotPath != "" { + snapshotDir = options.SnapshotPath + } // Create a directory if not exists if !files.FileExists(snapshotDir) { if err := os.Mkdir(snapshotDir, 0755); err != nil { - fmt.Println("Error creating directory:", err) - return + return errors.WithStackTrace(err) } } - filename := snapshotDir + "/" + releaseName + ".yaml" + filename := filepath.Join(snapshotDir, releaseName+".yaml") // Open a file in write mode file, err := os.Create(filename) if err != nil { - fmt.Println("Error creating file:", err) - return + return errors.WithStackTrace(err) } defer file.Close() // Write the k8s manifest into the file if _, err = file.WriteString(yamlData); err != nil { - fmt.Println("Error writing to file: ", filename, err) - return + return errors.WithStackTrace(err) } - fmt.Println("k8s manifest written into file: ", filename) + if options.Logger != nil { + options.Logger.Logf(t, "helm chart manifest written into file: %s", filename) + } + return nil } // DiffAgainstSnapshot compare the current manifests of a chart (e.g bitnami/nginx) // with the previous manifests stored in the snapshot. // see https://github.com/gruntwork-io/terratest/issues/1377 // It returns the number of difference between the two manifest snaphost or -1 in case of error -func DiffAgainstSnapshot(yamlData string, releaseName string) int { +// It will failed the test if there is an error while reading or writing the two manifests in the file system +func DiffAgainstSnapshot(t testing.TestingT, options *Options, yamlData string, releaseName string) int { + numberOfDiffs, err := DiffAgainstSnapshotE(t, options, yamlData, releaseName) + require.NoError(t, err) + return numberOfDiffs +} + +// DiffAgainstSnapshotE compare the current manifests of a chart (e.g bitnami/nginx) +// with the previous manifests stored in the snapshot. +// see https://github.com/gruntwork-io/terratest/issues/1377 +// It returns the number of difference between the two manifest snaphost or -1 in case of error +func DiffAgainstSnapshotE(t testing.TestingT, options *Options, yamlData string, releaseName string) (int, error) { - snapshotDir := "__snapshot__" + var snapshotDir = "__snapshot__" + if options.SnapshotPath != "" { + snapshotDir = options.SnapshotPath + } // load the yaml snapshot file - snapshot := snapshotDir + "/" + releaseName + ".yaml" + snapshot := filepath.Join(snapshotDir, releaseName+".yaml") from, err := ytbx.LoadFile(snapshot) if err != nil { - fmt.Println("Error opening file:", err) - return -1 + return -1, errors.WithStackTrace(err) } // write the current manifest into a file as `dyff` does not support string input currentManifests := releaseName + ".yaml" file, err := os.Create(currentManifests) if err != nil { - fmt.Println("Error creating file:", err) - return -1 + return -1, errors.WithStackTrace(err) } if _, err = file.WriteString(yamlData); err != nil { - fmt.Println("Error writing to file: ", currentManifests, err) - return -1 + return -1, errors.WithStackTrace(err) } defer file.Close() defer os.Remove(currentManifests) to, err := ytbx.LoadFile(currentManifests) if err != nil { - fmt.Println("Error opening file:", err) - return -1 + return -1, errors.WithStackTrace(err) } // compare the two manifests using `dyff` @@ -218,8 +240,7 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { // create a report report, err := dyff.CompareInputFiles(from, to, compOpt) if err != nil { - fmt.Println("Error opening file:", err) - return -1 + return -1, errors.WithStackTrace(err) } // write any difference to stdout @@ -231,8 +252,10 @@ func DiffAgainstSnapshot(yamlData string, releaseName string) int { UseGoPatchPaths: false, } - reportWriter.WriteReport(os.Stdout) - - // return the number of diffs to use in in assertion while testing: 0 = no differences - return len(reportWriter.Diffs) + err = reportWriter.WriteReport(os.Stdout) + if err != nil { + return -1, errors.WithStackTrace(err) + } + // return the number of diffs to use in assertion while testing: 0 = no differences + return len(reportWriter.Diffs), nil } diff --git a/modules/helm/template_test.go b/modules/helm/template_test.go index b9a72f75f..8de17575d 100644 --- a/modules/helm/template_test.go +++ b/modules/helm/template_test.go @@ -17,6 +17,7 @@ import ( appsv1 "k8s.io/api/apps/v1" "github.com/gruntwork-io/terratest/modules/k8s" + "github.com/gruntwork-io/terratest/modules/logger" "github.com/gruntwork-io/terratest/modules/random" ) @@ -25,7 +26,7 @@ func TestRemoteChartRender(t *testing.T) { const ( remoteChartSource = "https://charts.bitnami.com/bitnami" remoteChartName = "nginx" - remoteChartVersion = "13.2.23" + remoteChartVersion = "13.2.24" ) t.Parallel() @@ -45,6 +46,7 @@ func TestRemoteChartRender(t *testing.T) { "image.tag": remoteChartVersion, }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since @@ -86,6 +88,7 @@ func TestRemoteChartRenderDump(t *testing.T) { "image.tag": remoteChartVersion, }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since @@ -101,7 +104,11 @@ func TestRemoteChartRenderDump(t *testing.T) { require.Equal(t, namespaceName, deployment.Namespace) // write chart manifest to a local filesystem directory - UpdateSnapshot(output, releaseName) + options = &Options{ + Logger: logger.Default, + SnapshotPath: "__chart_manifests_snapshot__", + } + UpdateSnapshot(t, options, output, releaseName) } // Test that we can diff all the manifest to a local snapshot using a remote chart (e.g bitnami/nginx) @@ -109,7 +116,7 @@ func TestRemoteChartRenderDiff(t *testing.T) { const ( remoteChartSource = "https://charts.bitnami.com/bitnami" remoteChartName = "nginx" - remoteChartVersion = "13.2.23" + remoteChartVersion = "13.2.24" // need to set a fix name for the namespace so it is not flag as a difference namespaceName = "dump-ns" ) @@ -122,6 +129,8 @@ func TestRemoteChartRenderDiff(t *testing.T) { "image.tag": remoteChartVersion, }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, + SnapshotPath: "__chart_manifests_snapshot__", } // Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since @@ -134,5 +143,5 @@ func TestRemoteChartRenderDiff(t *testing.T) { UnmarshalK8SYaml(t, output, &deployment) // run the diff and assert there is only one difference: the image name - require.Equal(t, 1, DiffAgainstSnapshot(output, releaseName)) + require.Equal(t, 1, DiffAgainstSnapshot(t, options, output, releaseName)) } diff --git a/test/helm_keda_remote_example_template_snapshot_test.go b/test/helm_keda_remote_example_template_snapshot_test.go index 28ac5bdc7..3efddc837 100644 --- a/test/helm_keda_remote_example_template_snapshot_test.go +++ b/test/helm_keda_remote_example_template_snapshot_test.go @@ -45,6 +45,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDump(t *testing.T) { "resources.metricServer.limits.memory": "1234Mi", }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since @@ -68,7 +69,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDump(t *testing.T) { require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) // write chart manifest to a local filesystem directory - helm.UpdateSnapshot(output, releaseName) + helm.UpdateSnapshot(t, options, output, releaseName) } // An example of how to verify the rendered template object of a Helm Chart given various inputs. @@ -88,6 +89,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { "resources.metricServer.limits.memory": "4321Mi", }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since @@ -111,7 +113,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeploymentDiff(t *testing.T) { require.Equal(t, expectedMetricsServerReplica, deploymentMetricsServerReplica) // run the diff and assert the number of diffs - require.Equal(t, 4, helm.DiffAgainstSnapshot(output, releaseName)) + require.Equal(t, 4, helm.DiffAgainstSnapshot(t, options, output, releaseName)) } // An example of how to store a snapshot of the current manaifest for future comparison @@ -131,6 +133,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDump(t *testing.T) { "resources.metricServer.limits.memory": "1234Mi", }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since @@ -140,7 +143,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDump(t *testing.T) { output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) // write chart manifest to a local filesystem directory - helm.UpdateSnapshot(output, releaseName) + helm.UpdateSnapshot(t, options, output, releaseName) } // An example of how to verify the current helm k8s manifest against a previous snapshot @@ -160,6 +163,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { "resources.metricServer.limits.memory": "4321Mi", }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since @@ -169,5 +173,5 @@ func TestHelmKedaRemoteExampleTemplateRenderedPackageDiff(t *testing.T) { output := helm.RenderRemoteTemplate(t, options, "https://kedacore.github.io/charts", releaseName, []string{}) // run the diff and assert the number of diffs matches the number of diffs in the snapshot - require.Equal(t, 18, helm.DiffAgainstSnapshot(output, releaseName)) + require.Equal(t, 18, helm.DiffAgainstSnapshot(t, options, output, releaseName)) } diff --git a/test/helm_keda_remote_example_template_test.go b/test/helm_keda_remote_example_template_test.go index 8eabec7c6..1f66dda40 100644 --- a/test/helm_keda_remote_example_template_test.go +++ b/test/helm_keda_remote_example_template_test.go @@ -46,6 +46,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedDeployment(t *testing.T) { "resources.metricServer.limits.memory": "1234Mi", }, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since @@ -87,6 +88,7 @@ func TestHelmKedaRemoteExampleTemplateRenderedValuesFileFixtureDeployment(t *tes options := &helm.Options{ ValuesFiles: []string{"./fixtures/helm/keda-values.yaml"}, KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName), + Logger: logger.Discard, } // Run RenderTemplate to render the *remote* template and capture the output. Note that we use the version without `E`, since From b4b4d46c0303b5780f01fd93fca536f006ae5786 Mon Sep 17 00:00:00 2001 From: Jerome Guionnet Date: Mon, 8 Jan 2024 18:18:08 +0530 Subject: [PATCH 8/8] fix typos --- modules/helm/template.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/helm/template.go b/modules/helm/template.go index 8f0b321db..0cebe0bb1 100644 --- a/modules/helm/template.go +++ b/modules/helm/template.go @@ -149,7 +149,7 @@ func UpdateSnapshot(t testing.TestingT, options *Options, yamlData string, relea require.NoError(t, UpdateSnapshotE(t, options, yamlData, releaseName)) } -// UpdateSnapshot creates or updates the k8s manifest snapshot of a chart (e.g bitnami/nginx). +// UpdateSnapshotE creates or updates the k8s manifest snapshot of a chart (e.g bitnami/nginx). // It is one of the two functions needed to implement snapshot based testing for helm. // see https://github.com/gruntwork-io/terratest/issues/1377 // A snapshot is used to compare the current manifests of a chart with the previous manifests. @@ -190,8 +190,8 @@ func UpdateSnapshotE(t testing.TestingT, options *Options, yamlData string, rele // DiffAgainstSnapshot compare the current manifests of a chart (e.g bitnami/nginx) // with the previous manifests stored in the snapshot. // see https://github.com/gruntwork-io/terratest/issues/1377 -// It returns the number of difference between the two manifest snaphost or -1 in case of error -// It will failed the test if there is an error while reading or writing the two manifests in the file system +// It returns the number of difference between the two manifests or -1 in case of error +// It will fail the test if there is an error while reading or writing the two manifests in the file system func DiffAgainstSnapshot(t testing.TestingT, options *Options, yamlData string, releaseName string) int { numberOfDiffs, err := DiffAgainstSnapshotE(t, options, yamlData, releaseName) require.NoError(t, err) @@ -201,7 +201,7 @@ func DiffAgainstSnapshot(t testing.TestingT, options *Options, yamlData string, // DiffAgainstSnapshotE compare the current manifests of a chart (e.g bitnami/nginx) // with the previous manifests stored in the snapshot. // see https://github.com/gruntwork-io/terratest/issues/1377 -// It returns the number of difference between the two manifest snaphost or -1 in case of error +// It returns the number of difference between the manifests or -1 in case of error func DiffAgainstSnapshotE(t testing.TestingT, options *Options, yamlData string, releaseName string) (int, error) { var snapshotDir = "__snapshot__"