Skip to content

Commit

Permalink
Update to use a golden file test, instead of just comparing a string
Browse files Browse the repository at this point in the history
  • Loading branch information
reillywatson committed Aug 24, 2024
1 parent a024924 commit c7f4a31
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
22 changes: 6 additions & 16 deletions pkg/moq/moq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ func TestMockGolden(t *testing.T) {
interfaces: []string{"Magician"},
goldenFile: filepath.Join("testpackages/rangenum", "rangenum_moq.golden.go"),
},
{
name: "TypeAlias",
cfg: Config{SrcDir: "testpackages/typealias"},
interfaces: []string{"Example"},
goldenFile: filepath.Join("testpackages/typealias", "typealias_moq.golden.go"),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -664,22 +670,6 @@ func TestImportedPackageWithSameName(t *testing.T) {
}
}

func TestImportedPackageWithTypeAlias(t *testing.T) {
m, err := New(Config{SrcDir: "testpackages/typealias"})
if err != nil {
t.Fatalf("moq.New: %s", err)
}
var buf bytes.Buffer
err = m.Mock(&buf, "Example")
if err != nil {
t.Errorf("mock error: %s", err)
}
s := buf.String()
if !strings.Contains(s, `a typealiastwo.AliasType`) {
t.Error("missing typealiastwo.AliasType")
}
}

func TestParseError(t *testing.T) {
_, err := New(Config{SrcDir: "testpackages/_parseerror/service"})
if err == nil {
Expand Down
75 changes: 75 additions & 0 deletions pkg/moq/testpackages/typealias/typealias_moq.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c7f4a31

Please sign in to comment.