From 06a3fe5f4788ad02bc00920be4cb8c6f6d424e14 Mon Sep 17 00:00:00 2001 From: Victor Sollerhed Date: Tue, 2 Dec 2025 13:43:44 +0100 Subject: [PATCH] Approve `stdout` & `stderr` separately --- .gitignore | 1 + ...ir_test.TestError.Service.stderr.approved.txt | 1 + ...r_test.TestError.Service.stdout.approved.txt} | 0 approvals/kir_test.go | 16 +++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 approvals/kir_test.TestError.Service.stderr.approved.txt rename approvals/{kir_test.TestError.Service.approved.txt => kir_test.TestError.Service.stdout.approved.txt} (100%) diff --git a/.gitignore b/.gitignore index c288e97..fe14120 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .approval_tests_temp +approvals/*.received.txt \ No newline at end of file diff --git a/approvals/kir_test.TestError.Service.stderr.approved.txt b/approvals/kir_test.TestError.Service.stderr.approved.txt new file mode 100644 index 0000000..c5215a1 --- /dev/null +++ b/approvals/kir_test.TestError.Service.stderr.approved.txt @@ -0,0 +1 @@ +error processing document: unsupported kind Service \ No newline at end of file diff --git a/approvals/kir_test.TestError.Service.approved.txt b/approvals/kir_test.TestError.Service.stdout.approved.txt similarity index 100% rename from approvals/kir_test.TestError.Service.approved.txt rename to approvals/kir_test.TestError.Service.stdout.approved.txt diff --git a/approvals/kir_test.go b/approvals/kir_test.go index 9fcb414..9568469 100644 --- a/approvals/kir_test.go +++ b/approvals/kir_test.go @@ -57,6 +57,7 @@ func TestKind(t *testing.T) { } func TestError(t *testing.T) { + t.Parallel() cases := []struct { name string @@ -72,10 +73,19 @@ func TestError(t *testing.T) { t.Run(tc.name, func(t *testing.T) { images, err := processor.ProcessFile(tc.file) if err == nil { - t.Fatalf("ProcessFile() error = %v", err) + t.Fatalf("ProcessFile() expected error but got nil") } - imagesAsString := strings.Join(images, "\n") - approvals.VerifyString(t, imagesAsString) + + // Test stdout output + stdoutOutput := "" + if len(images) > 0 { + stdoutOutput = strings.Join(images, "\n") + } + approvals.VerifyString(t, stdoutOutput, approvals.Options().ForFile().WithAdditionalInformation("stdout")) + + // Test stderr output + stderrOutput := err.Error() + approvals.VerifyString(t, stderrOutput, approvals.Options().ForFile().WithAdditionalInformation("stderr")) }) } } diff --git a/go.mod b/go.mod index a9e1f85..41fa6bf 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/mpv/kir go 1.24.1 require ( - github.com/approvals/go-approval-tests v1.2.0 + github.com/approvals/go-approval-tests v1.5.0 k8s.io/api v0.32.3 k8s.io/apimachinery v0.32.3 k8s.io/client-go v0.32.3 diff --git a/go.sum b/go.sum index aa88e5c..5fa5243 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/approvals/go-approval-tests v1.2.0 h1:0gnbtkFLryEa7ojI6YSP5SeBHOfYHCWFnOTM8q9BQz4= -github.com/approvals/go-approval-tests v1.2.0/go.mod h1:Jw45q7bEifPpUkRU2S5GCthnwDxMUWPHTGcNewVh6mw= +github.com/approvals/go-approval-tests v1.5.0 h1:4t8BL8xwrsR2BNhHIZHBmf43SYmkSmkPBPtCqUNOBMA= +github.com/approvals/go-approval-tests v1.5.0/go.mod h1:i7AlHlLqLyxTby+MnSFgxkObjFlsywI46fnOitjMBiU= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=