-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
420 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPackageConfig(t *testing.T) { | ||
t.Run("when given just a filename", func(t *testing.T) { | ||
p := PackageConfig{Filename: "testdata/example.go"} | ||
require.True(t, p.IsDefined()) | ||
|
||
require.NoError(t, p.Check()) | ||
|
||
require.Equal(t, p.Package, "config_test_data") | ||
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata", p.ImportPath()) | ||
|
||
require.Equal(t, "config_test_data", p.Pkg().Name()) | ||
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata", p.Pkg().Path()) | ||
|
||
require.Contains(t, p.Filename, "codegen/config/testdata/example.go") | ||
require.Contains(t, p.Dir(), "codegen/config/testdata") | ||
}) | ||
|
||
t.Run("when given both", func(t *testing.T) { | ||
p := PackageConfig{Filename: "testdata/example.go", Package: "wololo"} | ||
require.True(t, p.IsDefined()) | ||
|
||
require.NoError(t, p.Check()) | ||
|
||
require.Equal(t, p.Package, "wololo") | ||
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata", p.ImportPath()) | ||
|
||
require.Equal(t, "wololo", p.Pkg().Name()) | ||
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata", p.Pkg().Path()) | ||
|
||
require.Contains(t, p.Filename, "codegen/config/testdata/example.go") | ||
require.Contains(t, p.Dir(), "codegen/config/testdata") | ||
}) | ||
|
||
t.Run("when given nothing", func(t *testing.T) { | ||
p := PackageConfig{} | ||
require.False(t, p.IsDefined()) | ||
|
||
require.EqualError(t, p.Check(), "filename must be specified") | ||
|
||
require.Equal(t, "", p.Package) | ||
require.Equal(t, "", p.ImportPath()) | ||
|
||
require.Nil(t, p.Pkg()) | ||
|
||
require.Equal(t, "", p.Filename) | ||
require.Equal(t, "", p.Dir()) | ||
}) | ||
|
||
t.Run("when given invalid filename", func(t *testing.T) { | ||
p := PackageConfig{Filename: "wololo.sql"} | ||
require.True(t, p.IsDefined()) | ||
|
||
require.EqualError(t, p.Check(), "filename should be path to a go source file") | ||
}) | ||
|
||
t.Run("when package includes a filename", func(t *testing.T) { | ||
p := PackageConfig{Filename: "foo.go", Package: "foo/foo.go"} | ||
require.True(t, p.IsDefined()) | ||
|
||
require.EqualError(t, p.Check(), "package should be the output package name only, do not include the output filename") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.