github.com/99designs/gqlgen@v0.17.45/internal/rewrite/rewriter_test.go (about) 1 package rewrite 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestRewriter(t *testing.T) { 12 t.Run("default", func(t *testing.T) { 13 r, err := New("testdata") 14 require.NoError(t, err) 15 16 body := r.GetMethodBody("Foo", "Method") 17 require.Equal(t, ` 18 // leading comment 19 20 // field comment 21 m.Field++ 22 23 // trailing comment 24 `, strings.ReplaceAll(body, "\r\n", "\n")) 25 26 imps := r.ExistingImports("testdata/example.go") 27 require.Len(t, imps, 2) 28 assert.Equal(t, []Import{ 29 { 30 Alias: "lol", 31 ImportPath: "bytes", 32 }, 33 { 34 Alias: "", 35 ImportPath: "fmt", 36 }, 37 }, imps) 38 }) 39 40 t.Run("out of scope dir", func(t *testing.T) { 41 _, err := New("../../../out-of-gomod/package") 42 require.Error(t, err) 43 }) 44 }