github.com/Azure/draft-classic@v0.16.0/cmd/draft/plugin_list_test.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "path/filepath" 6 "strings" 7 "testing" 8 9 "github.com/Azure/draft/pkg/draft/draftpath" 10 ) 11 12 func TestPluginListCmd(t *testing.T) { 13 buf := bytes.NewBuffer(nil) 14 15 resetEnvVars := unsetEnvVars() 16 defer resetEnvVars() 17 18 list := &pluginListCmd{ 19 home: draftpath.Home(filepath.Join("testdata", "drafthome")), 20 out: buf, 21 } 22 23 if err := list.run(); err != nil { 24 t.Errorf("draft plugin list error: %v", err) 25 } 26 27 expectedOutput := "NAME \tVERSION\tDESCRIPTION \nargs \t \tThis echos args \necho \t \tThis echos stuff \nfullenv\t \tshow all env vars\nhome \t \tshow DRAFT_HOME \n" 28 29 actual := buf.String() 30 if strings.Compare(actual, expectedOutput) != 0 { 31 t.Errorf("Expected %q, Got %q", expectedOutput, actual) 32 } 33 } 34 35 func TestEmptyResultsOnPluginListCmd(t *testing.T) { 36 target, err := newTestPluginEnv("", "") 37 if err != nil { 38 t.Fatal(err) 39 } 40 41 old, err := setupTestPluginEnv(target) 42 if err != nil { 43 t.Fatal(err) 44 } 45 46 defer teardownTestPluginEnv(target, old) 47 48 buf := bytes.NewBuffer(nil) 49 list := &pluginListCmd{ 50 home: draftpath.Home(homePath()), 51 out: buf, 52 } 53 54 if err := list.run(); err != nil { 55 t.Errorf("draft plugin list error: %v", err) 56 } 57 58 expectedOutput := "No plugins found\n" 59 actual := buf.String() 60 if strings.Compare(actual, expectedOutput) != 0 { 61 t.Errorf("Expected %s, got %s", expectedOutput, actual) 62 } 63 64 }