github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/manifest/manifest_plugin_test.go (about) 1 package manifest 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/manifest" 11 modelutil "github.com/evergreen-ci/evergreen/model/testutil" 12 "github.com/evergreen-ci/evergreen/plugin" 13 "github.com/evergreen-ci/evergreen/plugin/builtin/git" 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/mongodb/grip/slogger" 18 . "github.com/smartystreets/goconvey/convey" 19 ) 20 21 func reset(t *testing.T) { 22 db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testutil.TestConfig())) 23 testutil.HandleTestingErr( 24 db.ClearCollections(manifest.Collection), t, 25 "error clearing test collections") 26 } 27 28 func TestManifest(t *testing.T) { 29 reset(t) 30 Convey("With a pre-existing manifest for a revision existing", t, func() { 31 m := manifest.Manifest{ 32 Id: "abc123", 33 ProjectName: "mci_test", 34 Modules: map[string]*manifest.Module{}, 35 } 36 m.Modules["sample"] = &manifest.Module{ 37 Branch: "master", 38 Revision: "xyz345", 39 Repo: "repo", 40 Owner: "sr527", 41 URL: "randomurl.com", 42 } 43 44 dup, err := m.TryInsert() 45 So(dup, ShouldBeFalse) 46 So(err, ShouldBeNil) 47 48 Convey("insertion of another manifest should give a duplicate error", func() { 49 badManifest := manifest.Manifest{ 50 Id: "abc123", 51 ProjectName: "this_shouldn't_insert", 52 Modules: map[string]*manifest.Module{}, 53 } 54 dup, err = badManifest.TryInsert() 55 So(dup, ShouldBeTrue) 56 So(err, ShouldBeNil) 57 }) 58 59 }) 60 61 } 62 63 // ManifestFetchCmd integration tests 64 65 func TestManifestLoad(t *testing.T) { 66 reset(t) 67 testConfig := testutil.TestConfig() 68 69 db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testConfig)) 70 testutil.ConfigureIntegrationTest(t, testConfig, "TestManifestFetch") 71 Convey("With a SimpleRegistry and test project file", t, func() { 72 73 registry := plugin.NewSimpleRegistry() 74 manifestPlugin := &ManifestPlugin{} 75 testutil.HandleTestingErr(registry.Register(manifestPlugin), t, "failed to register manifest plugin") 76 77 gitPlugin := &git.GitPlugin{} 78 testutil.HandleTestingErr(registry.Register(gitPlugin), t, "failed to register git plugin") 79 80 server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins) 81 testutil.HandleTestingErr(err, t, "Couldn't set up testing server") 82 defer server.Close() 83 configPath := filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "mongodb-mongo-master.yml") 84 modelData, err := modelutil.SetupAPITestData(testConfig, "test", "rhel55", configPath, modelutil.NoPatch) 85 testutil.HandleTestingErr(err, t, "failed to setup test data") 86 httpCom := plugintest.TestAgentCommunicator(modelData, server.URL) 87 taskConfig := modelData.TaskConfig 88 89 logger := agentutil.NewTestLogger(slogger.StdOutAppender()) 90 91 Convey("the manifest load command should execute successfully", func() { 92 for _, task := range taskConfig.Project.Tasks { 93 So(len(task.Commands), ShouldNotEqual, 0) 94 for _, command := range task.Commands { 95 pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions) 96 testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v") 97 So(pluginCmds, ShouldNotBeNil) 98 So(err, ShouldBeNil) 99 pluginCom := &comm.TaskJSONCommunicator{manifestPlugin.Name(), 100 httpCom} 101 err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, 102 make(chan bool)) 103 So(err, ShouldBeNil) 104 } 105 106 } 107 Convey("the manifest should be inserted properly into the database", func() { 108 currentManifest, err := manifest.FindOne(manifest.ById(taskConfig.Task.Version)) 109 So(err, ShouldBeNil) 110 So(currentManifest, ShouldNotBeEmpty) 111 So(currentManifest.ProjectName, ShouldEqual, taskConfig.ProjectRef.Identifier) 112 So(currentManifest.Modules, ShouldNotBeNil) 113 So(len(currentManifest.Modules), ShouldEqual, 1) 114 for key := range currentManifest.Modules { 115 So(key, ShouldEqual, "sample") 116 } 117 So(taskConfig.Expansions.Get("sample_rev"), ShouldEqual, "3c7bfeb82d492dc453e7431be664539c35b5db4b") 118 }) 119 Convey("with a manifest already in the database the manifest should not create a new manifest", func() { 120 for _, task := range taskConfig.Project.Tasks { 121 So(len(task.Commands), ShouldNotEqual, 0) 122 for _, command := range task.Commands { 123 pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions) 124 testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v") 125 So(pluginCmds, ShouldNotBeNil) 126 So(err, ShouldBeNil) 127 pluginCom := &comm.TaskJSONCommunicator{manifestPlugin.Name(), 128 httpCom} 129 err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, 130 make(chan bool)) 131 So(err, ShouldBeNil) 132 } 133 134 } 135 Convey("the manifest should be inserted properly into the database", func() { 136 currentManifest, err := manifest.FindOne(manifest.ById(taskConfig.Task.Version)) 137 So(err, ShouldBeNil) 138 So(currentManifest, ShouldNotBeEmpty) 139 So(currentManifest.ProjectName, ShouldEqual, taskConfig.ProjectRef.Identifier) 140 So(currentManifest.Modules, ShouldNotBeNil) 141 So(len(currentManifest.Modules), ShouldEqual, 1) 142 for key := range currentManifest.Modules { 143 So(key, ShouldEqual, "sample") 144 } 145 So(currentManifest.Modules["sample"].Repo, ShouldEqual, "sample") 146 So(taskConfig.Expansions.Get("sample_rev"), ShouldEqual, "3c7bfeb82d492dc453e7431be664539c35b5db4b") 147 So(currentManifest.Id, ShouldEqual, taskConfig.Task.Version) 148 }) 149 }) 150 151 }) 152 }) 153 }