Add test flag -update to update the golden files
Test flag `-update` can be used to update all the golden files whenever the CLI output changes. Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
@@ -96,6 +96,13 @@ Then you can run the end-to-end tests with:
|
|||||||
make e2e
|
make e2e
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When the output of the Flux CLI changes, to automatically update the golden
|
||||||
|
files used in the test, pass `-update` flag to the test as:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make e2e TEST_ARGS="-update"
|
||||||
|
```
|
||||||
|
|
||||||
Teardown the e2e environment with:
|
Teardown the e2e environment with:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -39,7 +39,7 @@ test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
|
|||||||
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
||||||
|
|
||||||
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
|
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
|
||||||
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast
|
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast $(TEST_ARGS)
|
||||||
|
|
||||||
test-with-kind: install-envtest
|
test-with-kind: install-envtest
|
||||||
make setup-kind
|
make setup-kind
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -42,6 +43,9 @@ import (
|
|||||||
|
|
||||||
var nextNamespaceId int64
|
var nextNamespaceId int64
|
||||||
|
|
||||||
|
// update allows golden files to be updated based on the current output.
|
||||||
|
var update = flag.Bool("update", false, "update golden files")
|
||||||
|
|
||||||
// Return a unique namespace with the specified prefix, for tests to create
|
// Return a unique namespace with the specified prefix, for tests to create
|
||||||
// objects that won't collide with each other.
|
// objects that won't collide with each other.
|
||||||
func allocateNamespace(prefix string) string {
|
func allocateNamespace(prefix string) string {
|
||||||
@@ -298,6 +302,13 @@ func assertGoldenTemplateFile(goldenFile string, templateValues map[string]strin
|
|||||||
expectedOutput = string(goldenFileContents)
|
expectedOutput = string(goldenFileContents)
|
||||||
}
|
}
|
||||||
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
|
if assertErr := assertGoldenValue(expectedOutput)(output, err); assertErr != nil {
|
||||||
|
// Update the golden files if comparision fails and the update flag is set.
|
||||||
|
if *update && output != "" {
|
||||||
|
if err := os.WriteFile(goldenFile, []byte(output), 0644); err != nil {
|
||||||
|
return fmt.Errorf("failed to update golden file '%s': %v", goldenFile, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
|
return fmt.Errorf("Mismatch from golden file '%s': %v", goldenFile, assertErr)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
NAME READY MESSAGE REVISION SUSPENDED
|
NAME REVISION SUSPENDED READY MESSAGE
|
||||||
thrfg True Release reconciliation succeeded 6.0.0 False
|
thrfg 6.0.0 False True Release reconciliation succeeded
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
NAME READY MESSAGE LATEST IMAGE
|
NAME LATEST IMAGE READY MESSAGE
|
||||||
podinfo-regex True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0 ghcr.io/stefanprodan/podinfo:5.0.0
|
podinfo-regex ghcr.io/stefanprodan/podinfo:5.0.0 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.0
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
NAME READY MESSAGE LATEST IMAGE
|
NAME LATEST IMAGE READY MESSAGE
|
||||||
podinfo-semver True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3 ghcr.io/stefanprodan/podinfo:5.0.3
|
podinfo-semver ghcr.io/stefanprodan/podinfo:5.0.3 True Latest image tag for 'ghcr.io/stefanprodan/podinfo' resolved to: 5.0.3
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
NAME READY MESSAGE REVISION SUSPENDED
|
NAME REVISION SUSPENDED READY MESSAGE
|
||||||
tkfg True Applied revision: 6.0.0/627d5c4 6.0.0/627d5c4 False
|
tkfg 6.0.0/627d5c4 False True Applied revision: 6.0.0/627d5c4
|
||||||
|
|||||||
Reference in New Issue
Block a user