From 3abe5b32e965a6a05164a66110ac7cafda2e89d3 Mon Sep 17 00:00:00 2001 From: vvakame Date: Tue, 18 Feb 2020 14:16:24 +0900 Subject: [PATCH] add test --- internal/rewrite/rewriter_test.go | 58 ++++++++++++++++++------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/internal/rewrite/rewriter_test.go b/internal/rewrite/rewriter_test.go index e30142c653..5a0d44b348 100644 --- a/internal/rewrite/rewriter_test.go +++ b/internal/rewrite/rewriter_test.go @@ -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) + }) }