github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/expansions/expansions_plugin_test.go (about) 1 package expansions_test 2 3 import ( 4 "testing" 5 6 "github.com/evergreen-ci/evergreen/agent/comm" 7 "github.com/evergreen-ci/evergreen/command" 8 "github.com/evergreen-ci/evergreen/model" 9 "github.com/evergreen-ci/evergreen/model/task" 10 modelutil "github.com/evergreen-ci/evergreen/model/testutil" 11 "github.com/evergreen-ci/evergreen/plugin" 12 . "github.com/evergreen-ci/evergreen/plugin/builtin/expansions" 13 "github.com/evergreen-ci/evergreen/plugin/plugintest" 14 "github.com/evergreen-ci/evergreen/service" 15 "github.com/evergreen-ci/evergreen/testutil" 16 . "github.com/smartystreets/goconvey/convey" 17 ) 18 19 func TestExpansionsPlugin(t *testing.T) { 20 Convey("Should be able to update expansions", t, func() { 21 updateCommand := UpdateCommand{ 22 Updates: []PutCommandParams{ 23 { 24 Key: "base", 25 Value: "eggs", 26 }, 27 { 28 Key: "topping", 29 Concat: ",sausage", 30 }, 31 }, 32 } 33 34 expansions := command.Expansions{} 35 expansions.Put("base", "not eggs") 36 expansions.Put("topping", "bacon") 37 38 taskConfig := model.TaskConfig{ 39 Expansions: &expansions, 40 } 41 42 So(updateCommand.ExecuteUpdates(&taskConfig), ShouldBeNil) 43 44 So(expansions.Get("base"), ShouldEqual, "eggs") 45 So(expansions.Get("topping"), ShouldEqual, "bacon,sausage") 46 }) 47 48 } 49 50 func TestExpansionsPluginWExecution(t *testing.T) { 51 stopper := make(chan bool) 52 defer close(stopper) 53 54 testConfig := testutil.TestConfig() 55 server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins) 56 testutil.HandleTestingErr(err, t, "Couldn't set up testing server") 57 defer server.Close() 58 59 httpCom := plugintest.TestAgentCommunicator(&modelutil.TestModelData{}, server.URL) 60 jsonCom := &comm.TaskJSONCommunicator{"shell", httpCom} 61 62 conf := &model.TaskConfig{Expansions: &command.Expansions{}, Task: &task.Task{}, Project: &model.Project{}} 63 64 Convey("When running Update commands", t, func() { 65 Convey("if there is no expansion, the file name is not changed", func() { 66 So(conf.Expansions, ShouldResemble, &command.Expansions{}) 67 cmd := &UpdateCommand{YamlFile: "foo"} 68 So(cmd.Execute(&plugintest.MockLogger{}, jsonCom, conf, stopper), ShouldNotBeNil) 69 So(cmd.YamlFile, ShouldEqual, "foo") 70 }) 71 72 Convey("With an Expansion, the file name is expanded", func() { 73 conf.Expansions = command.NewExpansions(map[string]string{"foo": "bar"}) 74 cmd := &UpdateCommand{YamlFile: "${foo}"} 75 So(cmd.Execute(&plugintest.MockLogger{}, jsonCom, conf, stopper), ShouldNotBeNil) 76 So(cmd.YamlFile, ShouldEqual, "bar") 77 }) 78 }) 79 }