github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/shell/sh_plugin_test.go (about) 1 package shell 2 3 import ( 4 "fmt" 5 "runtime" 6 "testing" 7 8 "github.com/evergreen-ci/evergreen/agent/comm" 9 "github.com/evergreen-ci/evergreen/command" 10 "github.com/evergreen-ci/evergreen/model" 11 "github.com/evergreen-ci/evergreen/model/task" 12 modelutil "github.com/evergreen-ci/evergreen/model/testutil" 13 "github.com/evergreen-ci/evergreen/plugin" 14 "github.com/evergreen-ci/evergreen/plugin/plugintest" 15 "github.com/evergreen-ci/evergreen/service" 16 "github.com/evergreen-ci/evergreen/testutil" 17 . "github.com/smartystreets/goconvey/convey" 18 ) 19 20 func TestShellExecuteCommand(t *testing.T) { 21 stopper := make(chan bool) 22 defer close(stopper) 23 24 testConfig := testutil.TestConfig() 25 server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins) 26 if err != nil { 27 t.Fatalf("failed to create test server %+v", err) 28 } 29 defer server.Close() 30 31 httpCom := plugintest.TestAgentCommunicator(&modelutil.TestModelData{}, server.URL) 32 jsonCom := &comm.TaskJSONCommunicator{"shell", httpCom} 33 34 conf := &model.TaskConfig{Expansions: &command.Expansions{}, Task: &task.Task{}, Project: &model.Project{}} 35 36 Convey("With a shell command", t, func() { 37 38 Convey("if unset, default is determined by local command", func() { 39 cmd := &ShellExecCommand{} 40 So(cmd.Execute(&plugintest.MockLogger{}, jsonCom, conf, stopper), ShouldBeNil) 41 So(cmd.Shell, ShouldEqual, "") 42 }) 43 44 shells := []string{"bash", "python", "sh"} 45 46 if runtime.GOOS != "windows" { 47 shells = append(shells, "/bin/sh", "/bin/bash", "/usr/bin/python") 48 } 49 50 for _, sh := range shells { 51 Convey(fmt.Sprintf("when set, %s is not overwritten during execution", sh), func() { 52 cmd := &ShellExecCommand{Shell: sh} 53 So(cmd.Execute(&plugintest.MockLogger{}, jsonCom, conf, stopper), ShouldBeNil) 54 So(cmd.Shell, ShouldEqual, sh) 55 }) 56 } 57 }) 58 }