Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Feb 18, 2020
1 parent 6ecdb88 commit 3abe5b3
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions internal/rewrite/rewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,37 @@ import (
)

func TestRewriter(t *testing.T) {
r, err := New("github.com/99designs/gqlgen/internal/rewrite/testdata")
require.NoError(t, err)

body := r.GetMethodBody("Foo", "Method")
require.Equal(t, `
// leading comment
// field comment
m.Field++
// trailing comment
`, body)

imps := r.ExistingImports("testdata/example.go")
require.Len(t, imps, 2)
assert.Equal(t, []Import{
{
Alias: "",
ImportPath: "fmt",
},
{
Alias: "lol",
ImportPath: "bytes",
},
}, imps)
t.Run("default", func(t *testing.T) {
r, err := New("github.com/99designs/gqlgen/internal/rewrite/testdata")
require.NoError(t, err)

body := r.GetMethodBody("Foo", "Method")
require.Equal(t, `
// leading comment
// field comment
m.Field++
// trailing comment
`, body)

imps := r.ExistingImports("testdata/example.go")
require.Len(t, imps, 2)
assert.Equal(t, []Import{
{
Alias: "",
ImportPath: "fmt",
},
{
Alias: "lol",
ImportPath: "bytes",
},
}, imps)

})

t.Run("out of scope dir", func(t *testing.T) {
_, err := New("../../../out-of-gomod/package")
require.Error(t, err)
})
}

0 comments on commit 3abe5b3

Please sign in to comment.