Skip to content

Commit

Permalink
Adds ability to update golden files
Browse files Browse the repository at this point in the history
  • Loading branch information
sebradloff committed Apr 20, 2020
1 parent c5f6e02 commit ec6acbc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd_test

import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
Expand All @@ -11,6 +12,14 @@ import (
"github.com/sebradloff/rawk8stfc/cmd"
)

var (
updateFlag bool
)

func init() {
flag.BoolVar(&updateFlag, "update", false, "Set this flag to update the golden files.")
}

func TestRoot(t *testing.T) {
testName := "one-obj"

Expand All @@ -26,6 +35,15 @@ func TestRoot(t *testing.T) {
t.Errorf("running root command failed. err = %v", err)
}

if updateFlag {
cmd.Flags().Set("k8sFile", k8sFile)
cmd.Flags().Set("outputFile", goldenFile)
err := cmd.RunE(cmd, []string{})
if err != nil {
t.Errorf("running root command failed. err = %v", err)
}
}

got, err := os.Open(outputFile)
if err != nil {
t.Fatalf("failed to open the got file: %s. err = %v", outputFile, err)
Expand Down

0 comments on commit ec6acbc

Please sign in to comment.