Skip to content

Commit

Permalink
Add golden.FlagUpdate method
Browse files Browse the repository at this point in the history
Returns true when the -test.update-golden flag has been set.

Fixes: gotestyourself#205
  • Loading branch information
odsod committed Jul 15, 2020
1 parent 90977a4 commit ca3b132
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type helperT interface {
// The default value may change in a future major release.
var NormalizeCRLFToLF = os.Getenv("GOTESTTOOLS_GOLDEN_NormalizeCRLFToLF") != "false"

// FlagUpdate returns true when the -test.update-golden flag has been set.
func FlagUpdate() bool {
return *flagUpdate
}

// Open opens the file in ./testdata
func Open(t assert.TestingT, filename string) *os.File {
if ht, ok := t.(helperT); ok {
Expand Down
7 changes: 7 additions & 0 deletions golden/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,10 @@ func TestBytesFailure(t *testing.T) {
assert.Equal(t, result.(failure).FailureMessage(),
`[53 53 53 53] (actual) != [53 53 53 54] (expected)`+failurePostamble(filename))
}

func TestFlagUpdate(t *testing.T) {
assert.Assert(t, !FlagUpdate())
undo := setUpdateFlag()
defer undo()
assert.Assert(t, FlagUpdate())
}

0 comments on commit ca3b132

Please sign in to comment.