github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/attach/xunit_results_command_test.go (about) 1 package attach_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/model" 10 "github.com/evergreen-ci/evergreen/model/task" 11 modelutil "github.com/evergreen-ci/evergreen/model/testutil" 12 "github.com/evergreen-ci/evergreen/plugin" 13 . "github.com/evergreen-ci/evergreen/plugin/builtin/attach" 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 const TotalResultCount = 677 22 23 var ( 24 workingDirectory = testutil.GetDirectoryOfFile() 25 SingleFileConfig = filepath.Join(workingDirectory, "testdata", "plugin_attach_xunit.yml") 26 WildcardConfig = filepath.Join(workingDirectory, "testdata", "plugin_attach_xunit_wildcard.yml") 27 ) 28 29 // runTest abstracts away common tests and setup between all attach xunit tests. 30 // It also takes as an argument a function which runs any additional tests desired. 31 func runTest(t *testing.T, configPath string, customTests func(string)) { 32 resetTasks(t) 33 testConfig := testutil.TestConfig() 34 Convey("With attachResults plugin installed into plugin registry", t, func() { 35 registry := plugin.NewSimpleRegistry() 36 attachPlugin := &AttachPlugin{} 37 err := registry.Register(attachPlugin) 38 testutil.HandleTestingErr(err, t, "Couldn't register plugin: %v") 39 40 server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins) 41 testutil.HandleTestingErr(err, t, "Couldn't set up testing server") 42 defer server.Close() 43 44 modelData, err := modelutil.SetupAPITestData(testConfig, "test", "rhel55", configPath, modelutil.NoPatch) 45 testutil.HandleTestingErr(err, t, "failed to setup test data") 46 47 httpCom := plugintest.TestAgentCommunicator(modelData, server.URL) 48 49 taskConfig := modelData.TaskConfig 50 taskConfig.WorkDir = "." 51 logger := agentutil.NewTestLogger(slogger.StdOutAppender()) 52 53 Convey("all commands in test project should execute successfully", func() { 54 for _, projTask := range taskConfig.Project.Tasks { 55 So(len(projTask.Commands), ShouldNotEqual, 0) 56 for _, command := range projTask.Commands { 57 pluginCmds, err := registry.GetCommands(command, taskConfig.Project.Functions) 58 testutil.HandleTestingErr(err, t, "Couldn't get plugin command: %v") 59 So(pluginCmds, ShouldNotBeNil) 60 So(err, ShouldBeNil) 61 pluginCom := &comm.TaskJSONCommunicator{pluginCmds[0].Plugin(), httpCom} 62 err = pluginCmds[0].Execute(logger, pluginCom, taskConfig, make(chan bool)) 63 So(err, ShouldBeNil) 64 testTask, err := task.FindOne(task.ById(httpCom.TaskId)) 65 testutil.HandleTestingErr(err, t, "Couldn't find task") 66 So(testTask, ShouldNotBeNil) 67 } 68 } 69 70 Convey("and the tests should be present in the db", func() { 71 customTests(modelData.Task.Id) 72 }) 73 }) 74 }) 75 } 76 77 // dBTests are the database verification tests for standard one file execution 78 func dBTests(taskId string) { 79 task, err := task.FindOne(task.ById(taskId)) 80 So(err, ShouldBeNil) 81 So(task, ShouldNotBeNil) 82 So(len(task.TestResults), ShouldNotEqual, 0) 83 84 Convey("along with the proper logs", func() { 85 // junit_3.xml 86 tl := dBFindOneTestLog( 87 "test.test_threads_replica_set_client.TestThreadsReplicaSet.test_safe_update", 88 taskId, 89 ) 90 So(tl.Lines[0], ShouldContainSubstring, "SKIPPED") 91 tl = dBFindOneTestLog("test.test_bson.TestBSON.test_basic_encode", taskId) 92 So(tl.Lines[0], ShouldContainSubstring, "AssertionError") 93 }) 94 } 95 96 // dBTestsWildcard are the database verification tests for globbed file execution 97 func dBTestsWildcard(taskId string) { 98 task, err := task.FindOne(task.ById(taskId)) 99 So(err, ShouldBeNil) 100 So(len(task.TestResults), ShouldEqual, TotalResultCount) 101 102 Convey("along with the proper logs", func() { 103 // junit_1.xml 104 tl := dBFindOneTestLog("pkg1.test.test_things.test_params_func_2", taskId) 105 So(tl.Lines[0], ShouldContainSubstring, "FAILURE") 106 So(tl.Lines[6], ShouldContainSubstring, "AssertionError") 107 tl = dBFindOneTestLog("pkg1.test.test_things.SomeTests.test_skippy", taskId) 108 So(tl.Lines[0], ShouldContainSubstring, "SKIPPED") 109 110 // junit_2.xml 111 tl = dBFindOneTestLog("tests.ATest.fail", taskId) 112 So(tl.Lines[0], ShouldContainSubstring, "FAILURE") 113 So(tl.Lines[1], ShouldContainSubstring, "AssertionFailedError") 114 115 // junit_3.xml 116 tl = dBFindOneTestLog( 117 "test.test_threads_replica_set_client.TestThreadsReplicaSet.test_safe_update", 118 taskId, 119 ) 120 So(tl.Lines[0], ShouldContainSubstring, "SKIPPED") 121 tl = dBFindOneTestLog("test.test_bson.TestBSON.test_basic_encode", taskId) 122 So(tl.Lines[0], ShouldContainSubstring, "AssertionError") 123 }) 124 } 125 126 // dBFindOneTestLog abstracts away some of the common attributes of database 127 // verification tests. 128 func dBFindOneTestLog(name, taskId string) *model.TestLog { 129 ret, err := model.FindOneTestLog( 130 name, 131 taskId, 132 0, 133 ) 134 So(err, ShouldBeNil) 135 So(ret, ShouldNotBeNil) 136 return ret 137 } 138 139 func TestAttachXUnitResults(t *testing.T) { 140 runTest(t, SingleFileConfig, dBTests) 141 } 142 143 func TestAttachXUnitWildcardResults(t *testing.T) { 144 runTest(t, WildcardConfig, dBTestsWildcard) 145 }