From 38717f46634503559474a44a42a842cd08d673ca Mon Sep 17 00:00:00 2001 From: Henri Koski Date: Mon, 28 Oct 2024 14:16:23 +0200 Subject: [PATCH] Add golden file helpers --- golang/target/go.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/golang/target/go.go b/golang/target/go.go index ecb5748..78e913b 100644 --- a/golang/target/go.go +++ b/golang/target/go.go @@ -7,6 +7,9 @@ package target import ( "context" + "errors" + "fmt" + "os" "github.com/elisasre/mageutil/golang" "github.com/magefile/mage/mg" @@ -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 +}