github.com/Azure/draft-classic@v0.16.0/cmd/draft/init_test.go (about) 1 package main 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 "testing" 7 8 "github.com/Azure/draft/pkg/draft/draftpath" 9 ) 10 11 func TestParseConfig(t *testing.T) { 12 testCases := []struct { 13 configFile string 14 expectErr bool 15 pluginCount int 16 repoCount int 17 }{ 18 {"", false, 0, 0}, 19 {filepath.Join("testdata", "init", "configFile.toml"), false, 1, 1}, 20 {filepath.Join("testdata", "init", "malformedConfigFile.toml"), true, 0, 0}, 21 {filepath.Join("testdata", "init", "missingConfigFile.toml"), true, 0, 0}, 22 } 23 24 for _, tc := range testCases { 25 resetEnvVars := unsetEnvVars() 26 tempHome, teardown := tempDir(t, "draft-init") 27 defer func() { 28 teardown() 29 resetEnvVars() 30 }() 31 32 cmd := &initCmd{ 33 home: draftpath.Home(tempHome), 34 out: ioutil.Discard, 35 configFile: tc.configFile, 36 } 37 38 plugins, repos, err := cmd.parseConfig() 39 if err != nil && !tc.expectErr { 40 t.Errorf("Not expecting error but got error: %v", err) 41 } 42 if len(plugins) != tc.pluginCount { 43 t.Errorf("Expected %v plugins, got %#v", tc.pluginCount, len(plugins)) 44 } 45 if len(repos) != tc.repoCount { 46 t.Errorf("Expected %v pack repos, got %#v", tc.repoCount, len(repos)) 47 } 48 } 49 }