当前位置: 首页>>代码示例>>Golang>>正文


Golang db.Clear函数代码示例

本文整理汇总了Golang中github.com/evergreen-ci/evergreen/db.Clear函数的典型用法代码示例。如果您正苦于以下问题:Golang Clear函数的具体用法?Golang Clear怎么用?Golang Clear使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Clear函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestExistingFailedTaskTriggers

func TestExistingFailedTaskTriggers(t *testing.T) {
	Convey("With a previously failed instance of task in the database", t, func() {
		db.Clear(task.Collection)
		db.Clear(model.ProjectRefCollection)
		db.Clear(version.Collection)
		So(testProject.Insert(), ShouldBeNil)
		So(testVersion.Insert(), ShouldBeNil)
		testTask.Status = evergreen.TaskFailed
		err := testTask.Insert()
		So(err, ShouldBeNil)
		Convey("a newly failed task should trigger TaskFailed but *not* TaskFailTransition", func() {
			t2 := &task.Task{
				Id:                  "testTask2",
				Status:              evergreen.TaskFailed,
				DisplayName:         testTask.DisplayName,
				Project:             testTask.Project,
				BuildVariant:        testTask.BuildVariant,
				Version:             "testVersion2",
				RevisionOrderNumber: testTask.RevisionOrderNumber + 2,
			}
			ctx, err := getTaskTriggerContext(t2)
			So(err, ShouldBeNil)
			triggers, err := getActiveTaskFailureTriggers(*ctx)
			So(err, ShouldBeNil)
			So(len(triggers), ShouldEqual, 1)
			So(triggers[0].Id(), ShouldEqual, TaskFailed{}.Id())
		})
	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:29,代码来源:triggers_test.go

示例2: TestPatchPluginAPI

func TestPatchPluginAPI(t *testing.T) {
	testConfig := evergreen.TestConfig()
	cwd := testutil.GetDirectoryOfFile()
	Convey("With a running api server and installed plugin", t, func() {
		registry := plugin.NewSimpleRegistry()
		gitPlugin := &GitPlugin{}
		err := registry.Register(gitPlugin)
		testutil.HandleTestingErr(err, t, "Couldn't register patch plugin")
		server, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins, false)
		testutil.HandleTestingErr(err, t, "Couldn't set up testing server")
		taskConfig, _ := plugintest.CreateTestConfig(filepath.Join(cwd, "testdata", "plugin_patch.yml"), t)
		testCommand := GitGetProjectCommand{Directory: "dir"}
		_, _, err = plugintest.SetupAPITestData("testTask", filepath.Join(cwd, "testdata", "testmodule.patch"), t)
		testutil.HandleTestingErr(err, t, "Couldn't set up test documents")
		testTask, err := task.FindOne(task.ById("testTaskId"))
		testutil.HandleTestingErr(err, t, "Couldn't set up test patch task")

		sliceAppender := &evergreen.SliceAppender{[]*slogger.Log{}}
		logger := agentutil.NewTestLogger(sliceAppender)

		Convey("calls to existing tasks with patches should succeed", func() {
			httpCom := plugintest.TestAgentCommunicator(testTask.Id, testTask.Secret, server.URL)
			pluginCom := &comm.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
			patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
			So(err, ShouldBeNil)
			So(patch, ShouldNotBeNil)
			testutil.HandleTestingErr(db.Clear(version.Collection), t,
				"unable to clear versions collection")
		})
		Convey("calls to non-existing tasks should fail", func() {
			v := version.Version{Id: ""}
			testutil.HandleTestingErr(v.Insert(), t, "Couldn't insert dummy version")
			httpCom := plugintest.TestAgentCommunicator("BAD_TASK_ID", "", server.URL)
			pluginCom := &comm.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
			patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
			So(err.Error(), ShouldContainSubstring, "not found")
			So(err, ShouldNotBeNil)
			So(patch, ShouldBeNil)
			testutil.HandleTestingErr(db.Clear(version.Collection), t,
				"unable to clear versions collection")
		})
		Convey("calls to existing tasks without patches should fail", func() {
			noPatchTask := task.Task{Id: "noPatchTask", BuildId: "a"}
			testutil.HandleTestingErr(noPatchTask.Insert(), t, "Couldn't insert patch task")
			noPatchVersion := version.Version{Id: "noPatchVersion", BuildIds: []string{"a"}}
			testutil.HandleTestingErr(noPatchVersion.Insert(), t, "Couldn't insert patch version")
			v := version.Version{Id: ""}
			testutil.HandleTestingErr(v.Insert(), t, "Couldn't insert dummy version")
			httpCom := plugintest.TestAgentCommunicator(noPatchTask.Id, "", server.URL)
			pluginCom := &comm.TaskJSONCommunicator{gitPlugin.Name(), httpCom}
			patch, err := testCommand.GetPatch(taskConfig, pluginCom, logger)
			So(err, ShouldNotBeNil)
			So(err.Error(), ShouldContainSubstring, "no patch found for task")
			So(patch, ShouldBeNil)
			testutil.HandleTestingErr(db.Clear(version.Collection), t,
				"unable to clear versions collection")
		})

	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:60,代码来源:patch_test.go

示例3: setupCLITestHarness

func setupCLITestHarness() cliTestHarness {
	// create a test API server
	testServer, err := service.CreateTestServer(testConfig, nil, plugin.APIPlugins, true)
	So(err, ShouldBeNil)
	So(
		db.ClearCollections(
			task.Collection,
			build.Collection,
			user.Collection,
			patch.Collection,
			model.ProjectRefCollection,
			artifact.Collection,
		),
		ShouldBeNil)
	So(db.Clear(patch.Collection), ShouldBeNil)
	So(db.Clear(model.ProjectRefCollection), ShouldBeNil)
	So((&user.DBUser{Id: "testuser", APIKey: "testapikey", EmailAddress: "[email protected]"}).Insert(), ShouldBeNil)
	localConfBytes, err := ioutil.ReadFile(filepath.Join(testutil.GetDirectoryOfFile(), "testdata", "sample.yml"))
	So(err, ShouldBeNil)

	projectRef := &model.ProjectRef{
		Identifier:  "sample",
		Owner:       "evergreen-ci",
		Repo:        "sample",
		RepoKind:    "github",
		Branch:      "master",
		RemotePath:  "evergreen.yml",
		LocalConfig: string(localConfBytes),
		Enabled:     true,
		BatchTime:   180,
	}
	So(projectRef.Insert(), ShouldBeNil)

	// create a settings file for the command line client
	settings := model.CLISettings{
		APIServerHost: testServer.URL + "/api",
		UIServerHost:  "http://dev-evg.mongodb.com",
		APIKey:        "testapikey",
		User:          "testuser",
	}
	settingsFile, err := ioutil.TempFile("", "settings")
	So(err, ShouldBeNil)
	settingsBytes, err := yaml.Marshal(settings)
	So(err, ShouldBeNil)
	_, err = settingsFile.Write(settingsBytes)
	So(err, ShouldBeNil)
	settingsFile.Close()
	return cliTestHarness{testServer, settingsFile.Name()}
}
开发者ID:tychoish,项目名称:evergreen,代码行数:49,代码来源:cli_integration_test.go

示例4: TestSpawnExpireWarningTrigger

func TestSpawnExpireWarningTrigger(t *testing.T) {
	Convey("With a spawnhost due to expire in two hours", t, func() {
		db.Clear(host.Collection)
		testHost := host.Host{
			Id:             "testhost",
			StartedBy:      "test_user",
			Status:         "running",
			ExpirationTime: time.Now().Add(1 * time.Hour),
		}

		trigger := SpawnTwoHourWarning{}
		ctx := triggerContext{host: &testHost}
		shouldExec, err := trigger.ShouldExecute(ctx)
		So(err, ShouldBeNil)
		So(shouldExec, ShouldBeTrue)

		// run bookkeeping
		err = storeTriggerBookkeeping(ctx, []Trigger{trigger})
		So(err, ShouldBeNil)

		// should exec should now return false
		shouldExec, err = trigger.ShouldExecute(ctx)
		So(err, ShouldBeNil)
		So(shouldExec, ShouldBeFalse)
	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:26,代码来源:triggers_test.go

示例5: TestGenericBuildUpdating

func TestGenericBuildUpdating(t *testing.T) {
	Convey("When updating builds", t, func() {

		Reset(func() {
			testutil.HandleTestingErr(db.Clear(Collection), t, "Error clearing '%v' collection", Collection)
		})

		Convey("updating a single build should update the specified build"+
			" in the database", func() {

			buildOne := &Build{Id: "buildOne"}
			So(buildOne.Insert(), ShouldBeNil)

			err := UpdateOne(
				bson.M{IdKey: buildOne.Id},
				bson.M{"$set": bson.M{ProjectKey: "blah"}},
			)
			So(err, ShouldBeNil)

			buildOne, err = FindOne(ById(buildOne.Id))
			So(err, ShouldBeNil)
			So(buildOne.Project, ShouldEqual, "blah")
		})
	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:25,代码来源:build_test.go

示例6: TestFindTasksByIds

func TestFindTasksByIds(t *testing.T) {
	Convey("When calling FindTasksByIds...", t, func() {
		So(db.Clear(TasksCollection), ShouldBeNil)
		Convey("only tasks with the specified ids should be returned", func() {

			tasks := []Task{
				Task{
					Id: "one",
				},
				Task{
					Id: "two",
				},
				Task{
					Id: "three",
				},
			}

			for _, task := range tasks {
				So(task.Insert(), ShouldBeNil)
			}

			dbTasks, err := FindTasksByIds([]string{"one", "two"})
			So(err, ShouldBeNil)
			So(len(dbTasks), ShouldEqual, 2)
			So(dbTasks[0].Id, ShouldNotEqual, "three")
			So(dbTasks[1].Id, ShouldNotEqual, "three")
		})
	})
}
开发者ID:bjori,项目名称:evergreen,代码行数:29,代码来源:task_test.go

示例7: TestTaskSetPriority

func TestTaskSetPriority(t *testing.T) {

	Convey("With a task", t, func() {

		testutil.HandleTestingErr(db.Clear(TasksCollection), t, "Error clearing"+
			" '%v' collection", TasksCollection)

		task := &Task{
			Id: "task",
		}
		So(task.Insert(), ShouldBeNil)

		Convey("setting its priority should update it both in-memory"+
			" and in the database", func() {

			So(task.SetPriority(1), ShouldBeNil)
			So(task.Priority, ShouldEqual, 1)

			task, err := FindTask(task.Id)
			So(err, ShouldBeNil)
			So(task, ShouldNotBeNil)
			So(task.Priority, ShouldEqual, 1)
		})

	})

}
开发者ID:markbenvenuto,项目名称:evergreen,代码行数:27,代码来源:task_test.go

示例8: TestFindOneProjectRef

func TestFindOneProjectRef(t *testing.T) {
	Convey("With an existing repository ref", t, func() {
		testutil.HandleTestingErr(db.Clear(ProjectRefCollection), t,
			"Error clearing collection")
		projectRef := &ProjectRef{
			Owner:      "mongodb",
			Repo:       "mci",
			Branch:     "master",
			RepoKind:   "github",
			Enabled:    true,
			BatchTime:  10,
			Identifier: "ident",
		}
		Convey("all fields should be returned accurately for the "+
			"corresponding project ref", func() {
			So(projectRef.Insert(), ShouldBeNil)
			projectRefFromDB, err := FindOneProjectRef("ident")
			So(err, ShouldBeNil)
			So(projectRefFromDB, ShouldNotEqual, nil)
			So(projectRefFromDB.Owner, ShouldEqual, "mongodb")
			So(projectRefFromDB.Repo, ShouldEqual, "mci")
			So(projectRefFromDB.Branch, ShouldEqual, "master")
			So(projectRefFromDB.RepoKind, ShouldEqual, "github")
			So(projectRefFromDB.Enabled, ShouldEqual, true)
			So(projectRefFromDB.BatchTime, ShouldEqual, 10)
			So(projectRefFromDB.Identifier, ShouldEqual, "ident")
		})
	})
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:29,代码来源:project_ref_test.go

示例9: TestBuildMarkFinished

func TestBuildMarkFinished(t *testing.T) {

	Convey("With a build", t, func() {

		testutil.HandleTestingErr(db.Clear(build.Collection), t, "Error clearing"+
			" '%v' collection", build.Collection)

		startTime := time.Now()
		b := &build.Build{
			Id:        "build",
			StartTime: startTime,
		}
		So(b.Insert(), ShouldBeNil)

		Convey("marking it as finished should update the status,"+
			" finish time, and duration, both in memory and in the"+
			" database", func() {

			finishTime := time.Now()
			So(b.MarkFinished(evergreen.BuildSucceeded, finishTime), ShouldBeNil)
			So(b.Status, ShouldEqual, evergreen.BuildSucceeded)
			So(b.FinishTime.Equal(finishTime), ShouldBeTrue)
			So(b.TimeTaken, ShouldEqual, finishTime.Sub(startTime))

			// refresh from db and check again

			b, err := build.FindOne(build.ById(b.Id))
			So(err, ShouldBeNil)
			So(b.Status, ShouldEqual, evergreen.BuildSucceeded)
			So(b.FinishTime.Round(time.Second).Equal(
				finishTime.Round(time.Second)), ShouldBeTrue)
			So(b.TimeTaken, ShouldEqual, finishTime.Sub(startTime))
		})
	})
}
开发者ID:sr527,项目名称:evergreen,代码行数:35,代码来源:lifecycle_test.go

示例10: TestFindLastPassingVersionForBuildVariants

func TestFindLastPassingVersionForBuildVariants(t *testing.T) {
	Convey("works", t, func() {
		So(db.Clear(TaskQueuesCollection), ShouldBeNil)

		project := "MyProject"
		bv1 := "linux"
		bv2 := "windows"
		projectObj := Project{
			Identifier: project,
		}

		insertVersion("1", 1, project)
		insertVersion("2", 2, project)
		insertVersion("3", 3, project)

		insertBuild("1a", project, bv1, evergreen.BuildSucceeded, 1)
		insertBuild("1b", project, bv2, evergreen.BuildSucceeded, 1)

		insertBuild("2a", project, bv1, evergreen.BuildSucceeded, 2)
		insertBuild("2b", project, bv2, evergreen.BuildSucceeded, 2)

		insertBuild("3a", project, bv1, evergreen.BuildSucceeded, 3)
		insertBuild("3b", project, bv2, evergreen.BuildFailed, 3)

		version, err := FindLastPassingVersionForBuildVariants(projectObj,
			[]string{bv1, bv2})

		So(err, ShouldBeNil)
		So(version, ShouldNotBeNil)
		So(version.Id, ShouldEqual, "2")
		So(version.RevisionOrderNumber, ShouldEqual, 2)
	})
}
开发者ID:MauroJr,项目名称:evergreen,代码行数:33,代码来源:version_history_test.go

示例11: TestCheckProjectSemantics

func TestCheckProjectSemantics(t *testing.T) {
	Convey("When validating a project's semantics", t, func() {
		Convey("if the project passes all of the validation funcs, no errors"+
			" should be returned", func() {
			distros := []distro.Distro{
				{Id: "test-distro-one"},
				{Id: "test-distro-two"},
			}

			for _, d := range distros {
				So(d.Insert(), ShouldBeNil)
			}

			projectRef := &model.ProjectRef{
				Identifier:  "project_test",
				LocalConfig: "test: testing",
			}

			project, err := model.FindProject("", projectRef)
			So(err, ShouldBeNil)
			So(CheckProjectSemantics(project), ShouldResemble, []ValidationError{})
		})

		Reset(func() {
			db.Clear(distro.Collection)
		})
	})
}
开发者ID:tessavitabile,项目名称:evergreen,代码行数:28,代码来源:project_validator_test.go

示例12: TestBuildMarkStarted

func TestBuildMarkStarted(t *testing.T) {

	Convey("With a build", t, func() {

		testutil.HandleTestingErr(db.Clear(build.Collection), t, "Error clearing"+
			" '%v' collection", build.Collection)

		b := &build.Build{
			Id:     "build",
			Status: evergreen.BuildCreated,
		}
		So(b.Insert(), ShouldBeNil)

		Convey("marking it as started should update the status and"+
			" start time, both in memory and in the database", func() {

			startTime := time.Now()
			So(build.TryMarkStarted(b.Id, startTime), ShouldBeNil)

			// refresh from db and check again
			b, err := build.FindOne(build.ById(b.Id))
			So(err, ShouldBeNil)
			So(b.Status, ShouldEqual, evergreen.BuildStarted)
			So(b.StartTime.Round(time.Second).Equal(
				startTime.Round(time.Second)), ShouldBeTrue)
		})
	})
}
开发者ID:sr527,项目名称:evergreen,代码行数:28,代码来源:lifecycle_test.go

示例13: TestFindRunningSpawnedHosts

func TestFindRunningSpawnedHosts(t *testing.T) {
	testConfig := evergreen.TestConfig()
	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(testConfig))

	testutil.HandleTestingErr(db.Clear(Collection), t, "Error"+
		" clearing '%v' collection", Collection)

	Convey("With calling FindRunningSpawnedHosts...", t, func() {
		Convey("if there are no spawned hosts, nothing should be returned",
			func() {
				spawnedHosts, err := Find(IsRunningAndSpawned)
				So(err, ShouldBeNil)
				// make sure we only returned no document
				So(len(spawnedHosts), ShouldEqual, 0)

			})

		Convey("if there are spawned hosts, they should be returned", func() {
			host := &Host{}
			host.Id = "spawned-1"
			host.Status = "running"
			host.StartedBy = "user1"
			testutil.HandleTestingErr(host.Insert(), t, "error from "+
				"FindRunningSpawnedHosts")
			spawnedHosts, err := Find(IsRunningAndSpawned)
			testutil.HandleTestingErr(err, t, "error from "+
				"FindRunningSpawnedHosts: %v", err)
			// make sure we only returned no document
			So(len(spawnedHosts), ShouldEqual, 1)

		})
	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:33,代码来源:host_test.go

示例14: TestHostSetRunningTask

func TestHostSetRunningTask(t *testing.T) {

	Convey("With a host", t, func() {

		testutil.HandleTestingErr(db.Clear(Collection), t, "Error"+
			" clearing '%v' collection", Collection)

		host := &Host{
			Id: "hostOne",
		}
		So(host.Insert(), ShouldBeNil)

		Convey("setting the running task for the host should set the running"+
			" task and task dispatch time for both the in-memory and database"+
			" copies of the host", func() {

			taskDispatchTime := time.Now()

			So(host.SetRunningTask("taskId", "c", taskDispatchTime), ShouldBeNil)
			So(host.RunningTask, ShouldEqual, "taskId")
			So(host.AgentRevision, ShouldEqual, "c")
			So(host.TaskDispatchTime.Round(time.Second).Equal(
				taskDispatchTime.Round(time.Second)), ShouldBeTrue)

			host, err := FindOne(ById(host.Id))
			So(err, ShouldBeNil)
			So(host.RunningTask, ShouldEqual, "taskId")
			So(host.AgentRevision, ShouldEqual, "c")
			So(host.TaskDispatchTime.Round(time.Second).Equal(
				taskDispatchTime.Round(time.Second)), ShouldBeTrue)

		})

	})
}
开发者ID:tychoish,项目名称:evergreen,代码行数:35,代码来源:host_test.go

示例15: TestNoteStorage

func TestNoteStorage(t *testing.T) {
	Convey("With a test note to save", t, func() {
		db.Clear(NotesCollection)
		n := Note{
			TaskId:       "t1",
			UnixNanoTime: time.Now().UnixNano(),
			Content:      "test note",
		}
		Convey("saving the note should work without error", func() {
			So(n.Upsert(), ShouldBeNil)

			Convey("the note should be retrievable", func() {
				n2, err := NoteForTask("t1")
				So(err, ShouldBeNil)
				So(n2, ShouldNotBeNil)
				So(*n2, ShouldResemble, n)
			})
			Convey("saving the note again should overwrite the existing note", func() {
				n3 := n
				n3.Content = "new content"
				So(n3.Upsert(), ShouldBeNil)
				n4, err := NoteForTask("t1")
				So(err, ShouldBeNil)
				So(n4, ShouldNotBeNil)
				So(n4.TaskId, ShouldEqual, "t1")
				So(n4.Content, ShouldEqual, n3.Content)
			})
		})
	})
}
开发者ID:ramonfm,项目名称:build-baron-plugin,代码行数:30,代码来源:build_baron_test.go


注:本文中的github.com/evergreen-ci/evergreen/db.Clear函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。