github.com/Azure/draft-classic@v0.16.0/cmd/draft/plugin_remove_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 "github.com/Azure/draft/pkg/testing/helpers" 11 ) 12 13 func TestPluginRemoveCmd(t *testing.T) { 14 buf := bytes.NewBuffer(nil) 15 target, err := newTestPluginEnv("", "") 16 if err != nil { 17 t.Fatal(err) 18 } 19 old, err := setupTestPluginEnv(target) 20 if err != nil { 21 t.Fatal(err) 22 } 23 defer teardownTestPluginEnv(target, old) 24 25 remove := &pluginRemoveCmd{ 26 home: draftpath.Home(homePath()), 27 out: buf, 28 names: []string{"echo"}, 29 } 30 31 helpers.CopyTree(t, filepath.Join("testdata", "plugins"), pluginDirPath(remove.home)) 32 33 if err := remove.run(); err != nil { 34 t.Errorf("Error removing plugin: %v", err) 35 } 36 37 expectedOutput := "Removed plugin: echo\n" 38 actual := buf.String() 39 40 if strings.Compare(expectedOutput, actual) != 0 { 41 t.Errorf("Expected %v, got %v", expectedOutput, actual) 42 } 43 }