Skip to content

Commit

Permalink
Merge pull request #206 from elisasre/feat/golden-helpers
Browse files Browse the repository at this point in the history
Add golden file helpers
  • Loading branch information
heppu authored Oct 28, 2024
2 parents 84cd08c + 38717f4 commit 5b867b9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions golang/target/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package target

import (
"context"
"errors"
"fmt"
"os"

"github.com/elisasre/mageutil/golang"
"github.com/magefile/mage/mg"
Expand Down Expand Up @@ -102,3 +105,28 @@ func (Go) Tidy(ctx context.Context) error {
func (Go) TidyAndVerify(ctx context.Context) error {
return golang.TidyAndVerify(ctx)
}

// RegenIntegrationTestArtifacts regenerates the integration test artifacts
func (Go) RegenIntegrationTestArtifacts(ctx context.Context) {
os.Setenv("OVERRIDE_TEST_DATA", "true")
mg.SerialCtxDeps(ctx,
mg.F(sh.Rm, "./integrationtests/testdata"),
Go.IntegrationTest,
)
}

// IntegrationTestAndValidate runs the integration tests and checks that testdata artifacts are unchanged
func (Go) IntegrationTestAndValidate(ctx context.Context) error {
mg.SerialCtxDeps(ctx, Go.RegenIntegrationTestArtifacts)
out, err := sh.Output("git", "status", "--porcelain", "--", "./integrationtests/testdata/")
if err != nil {
return err
}

if len(out) > 0 {
fmt.Println(out)
return errors.New("testdata artifacts have changed")
}

return nil
}

0 comments on commit 5b867b9

Please sign in to comment.