-
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
10 changed files
with
142 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package codegen | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
t.Run("config does not exist", func(t *testing.T) { | ||
_, err := LoadConfig("doesnotexist.yml") | ||
require.EqualError(t, err, "unable to read config: open doesnotexist.yml: no such file or directory") | ||
}) | ||
|
||
t.Run("malformed config", func(t *testing.T) { | ||
_, err := LoadConfig("testdata/cfg/malformedconfig.yml") | ||
require.EqualError(t, err, "unable to parse config: yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `asdf` into codegen.Config") | ||
}) | ||
} | ||
|
||
func TestLoadDefaultConfig(t *testing.T) { | ||
testDir, err := os.Getwd() | ||
require.NoError(t, err) | ||
var cfg *Config | ||
|
||
t.Run("will find closest match", func(t *testing.T) { | ||
err = os.Chdir(filepath.Join(testDir, "testdata", "cfg", "subdir")) | ||
require.NoError(t, err) | ||
|
||
cfg, err = LoadDefaultConfig() | ||
require.NoError(t, err) | ||
require.Equal(t, cfg.SchemaFilename, "inner") | ||
}) | ||
|
||
t.Run("will find config in parent dirs", func(t *testing.T) { | ||
err = os.Chdir(filepath.Join(testDir, "testdata", "cfg", "otherdir")) | ||
require.NoError(t, err) | ||
|
||
cfg, err = LoadDefaultConfig() | ||
require.NoError(t, err) | ||
require.Equal(t, cfg.SchemaFilename, "outer") | ||
}) | ||
|
||
t.Run("will fallback to defaults", func(t *testing.T) { | ||
err = os.Chdir(testDir) | ||
require.NoError(t, err) | ||
|
||
cfg, err = LoadDefaultConfig() | ||
require.NoError(t, err) | ||
require.Equal(t, cfg.SchemaFilename, "schema.graphql") | ||
}) | ||
} |
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 @@ | ||
schema: outer |
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 @@ | ||
asdf |
Empty file.
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 @@ | ||
schema: inner |
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
File renamed without changes.
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