github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/config/config_test.go (about) 1 package config_test 2 3 import ( 4 "flag" 5 "os" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 "github.com/urfave/cli" 10 11 "github.com/fossas/fossa-cli/config" 12 "github.com/fossas/fossa-cli/vcs" 13 ) 14 15 func TestInitWorksWithoutGitRepository(t *testing.T) { 16 // Change to a directory without Git repository. 17 cwd, err := os.Getwd() 18 assert.NoError(t, err) 19 err = os.Chdir("/") 20 assert.NoError(t, err) 21 defer func() { 22 err = os.Chdir(cwd) 23 assert.NoError(t, err) 24 }() 25 26 // Check that there actually is no Git repository. 27 _, _, err = vcs.Nearest(".") 28 assert.Error(t, err, vcs.ErrNoNearestVCS) 29 30 // Check that config.setContext doesn't break. 31 ctx := cli.NewContext(cli.NewApp(), flag.NewFlagSet("test", 0), nil) 32 err = config.SetContext(ctx) 33 assert.NoError(t, err) 34 }