(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func TestEncodeGolden(t *testing.T) { |
| 61 | cases := []struct { |
| 62 | name string |
| 63 | artifact Artifact |
| 64 | golden string |
| 65 | }{ |
| 66 | {"playbook", samplePlaybook(), "playbook.golden.md"}, |
| 67 | {"convention", sampleConvention(), "convention.golden.md"}, |
| 68 | } |
| 69 | for _, tc := range cases { |
| 70 | t.Run(tc.name, func(t *testing.T) { |
| 71 | got, err := Encode(tc.artifact) |
| 72 | if err != nil { |
| 73 | t.Fatalf("Encode: %v", err) |
| 74 | } |
| 75 | path := filepath.Join("testdata", tc.golden) |
| 76 | if *update { |
| 77 | if err := os.WriteFile(path, got, 0o644); err != nil { |
| 78 | t.Fatalf("write golden: %v", err) |
| 79 | } |
| 80 | return |
| 81 | } |
| 82 | want, err := os.ReadFile(path) |
| 83 | if err != nil { |
| 84 | t.Fatalf("read golden (run -update to create): %v", err) |
| 85 | } |
| 86 | if !bytes.Equal(got, want) { |
| 87 | t.Errorf("Encode output mismatch with %s\n--- got ---\n%s\n--- want ---\n%s", tc.golden, got, want) |
| 88 | } |
| 89 | }) |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | func TestEncodeDeterministic(t *testing.T) { |
| 94 | for _, a := range []Artifact{samplePlaybook(), sampleConvention()} { |
nothing calls this directly
no test coverage detected