github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/s3copy/s3_copy_plugin_test.go (about) 1 package s3copy_test 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/evergreen-ci/evergreen/agent/comm" 8 agentutil "github.com/evergreen-ci/evergreen/agent/testutil" 9 "github.com/evergreen-ci/evergreen/db" 10 "github.com/evergreen-ci/evergreen/model" 11 modelutil "github.com/evergreen-ci/evergreen/model/testutil" 12 "github.com/evergreen-ci/evergreen/model/version" 13 "github.com/evergreen-ci/evergreen/plugin" 14 "github.com/evergreen-ci/evergreen/plugin/builtin/s3" 15 . "github.com/evergreen-ci/evergreen/plugin/builtin/s3copy" 16 "github.com/evergreen-ci/evergreen/plugin/plugintest" 17 "github.com/evergreen-ci/evergreen/service" 18 "github.com/evergreen-ci/evergreen/testutil" 19 "github.com/mongodb/grip/slogger" 20 . "github.com/smartystreets/goconvey/convey" 21 ) 22 23 func TestS3CopyPluginExecution(t *testing.T) { 24 testConfig := testutil.TestConfig() 25 db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testConfig)) 26 27 testutil.ConfigureIntegrationTest(t, testConfig, "TestS3CopyPluginExecution") 28 29 Convey("With a SimpleRegistry and test project file", t, func() { 30 registry := plugin.NewSimpleRegistry() 31 s3CopyPlugin := &S3CopyPlugin{} 32 testutil.HandleTestingErr(registry.Register(s3CopyPlugin), t, "failed to register s3Copy plugin") 33 testutil.HandleTestingErr(registry.Register(&s3.S3Plugin{}), t, "failed to register S3 plugin") 34 testutil.HandleTestingErr( 35 db.ClearCollections(model.PushlogCollection, version.Collection), t, 36 "error clearing test collections") 37 version := &version.Version{ 38 Id: "versionId", 39 } 40 So(version.Insert(), ShouldBeNil) 41 server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins) 42 testutil.HandleTestingErr(err, t, "Couldn't set up testing server") 43 defer server.Close() 44 45 pwd := testutil.GetDirectoryOfFile() 46 configFile := filepath.Join(pwd, "testdata", "plugin_s3_copy.yml") 47 modelData, err := modelutil.SetupAPITestData(testConfig, "test", "linux-64", configFile, modelutil.NoPatch) 48 testutil.HandleTestingErr(err, t, "failed to setup test data") 49 httpCom := plugintest.TestAgentCommunicator(modelData, server.URL) 50 taskConfig := modelData.TaskConfig 51 taskConfig.WorkDir = "." 52 53 logger := agentutil.NewTestLogger(slogger.StdOutAppender()) 54 taskConfig.Expansions.Update(map[string]string{ 55 "aws_key": testConfig.Providers.AWS.Id, 56 "aws_secret": testConfig.Providers.AWS.Secret, 57 "pwd": pwd, 58 }) 59 60 Convey("the s3 copy command should execute successfully", func() { 61 for _, task := range taskConfig.Project.Tasks { 62 for _, command := range task.Commands { 63 pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions) 64 testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v") 65 So(pluginCmds, ShouldNotBeNil) 66 So(err, ShouldBeNil) 67 pluginCom := &comm.TaskJSONCommunicator{s3CopyPlugin.Name(), httpCom} 68 err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, 69 make(chan bool)) 70 So(err, ShouldBeNil) 71 } 72 } 73 }) 74 }) 75 }