本文整理汇总了Golang中github.com/evergreen-ci/evergreen/model/distro.Distro.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang Distro.Id方法的具体用法?Golang Distro.Id怎么用?Golang Distro.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/evergreen-ci/evergreen/model/distro.Distro
的用法示例。
在下文中一共展示了Distro.Id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addDistro
func (uis *UIServer) addDistro(w http.ResponseWriter, r *http.Request) {
id, hasId := mux.Vars(r)["distro_id"]
u := MustHaveUser(r)
b, err := ioutil.ReadAll(r.Body)
if err != nil {
message := fmt.Sprintf("error adding distro: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer r.Body.Close()
var d distro.Distro
if err = json.Unmarshal(b, &d); err != nil {
message := fmt.Sprintf("error adding distro: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, message, http.StatusBadRequest)
return
}
if hasId {
d.Id = id
}
vErrs, err := validator.CheckDistro(&d, &uis.Settings, true)
if err != nil {
message := fmt.Sprintf("error retrieving distroIds: %v", err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
http.Error(w, message, http.StatusInternalServerError)
return
}
if len(vErrs) != 0 {
for _, e := range vErrs {
PushFlash(uis.CookieStore, r, w, NewErrorFlash(e.Error()))
}
uis.WriteJSON(w, http.StatusBadRequest, vErrs)
return
}
if err = d.Insert(); err != nil {
message := fmt.Sprintf("error inserting distro '%v': %v", d.Id, err)
PushFlash(uis.CookieStore, r, w, NewErrorFlash(message))
uis.WriteJSON(w, http.StatusInternalServerError, err)
return
}
event.LogDistroAdded(d.Id, u.Username(), d)
PushFlash(uis.CookieStore, r, w, NewSuccessFlash(fmt.Sprintf("Distro %v successfully added.", d.Id)))
uis.WriteJSON(w, http.StatusOK, "distro successfully added")
}
示例2: TestStoreRepositoryRevisions
func TestStoreRepositoryRevisions(t *testing.T) {
dropTestDB(t)
testutil.ConfigureIntegrationTest(t, testConfig, "TestStoreRepositoryRevisions")
Convey("When storing revisions gotten from a repository...", t, func() {
err := testutil.CreateTestLocalConfig(testConfig, "mci-test", "")
So(err, ShouldBeNil)
repoTracker := RepoTracker{testConfig, projectRef, NewGithubRepositoryPoller(projectRef,
testConfig.Credentials["github"])}
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("On storing a single repo revision, we expect a version to be created"+
" in the database for this project, which should be retrieved when we search"+
" for this project's most recent version", func() {
createTime := time.Now()
revisionOne := *createTestRevision("firstRevision", createTime)
revisions := []model.Revision{revisionOne}
resultVersion, err := repoTracker.StoreRevisions(revisions)
testutil.HandleTestingErr(err, t, "Error storing repository revisions %v")
newestVersion, err := version.FindOne(version.ByMostRecentForRequester(projectRef.String(), evergreen.RepotrackerVersionRequester))
testutil.HandleTestingErr(err, t, "Error retreiving newest version %v")
So(resultVersion, ShouldResemble, newestVersion)
})
Convey("On storing several repo revisions, we expect a version to be created "+
"for each revision", func() {
createTime := time.Now()
laterCreateTime := createTime.Add(time.Duration(4 * time.Hour))
revisionOne := *createTestRevision("one", laterCreateTime)
revisionTwo := *createTestRevision("two", createTime)
revisions := []model.Revision{revisionOne, revisionTwo}
_, err := repoTracker.StoreRevisions(revisions)
testutil.HandleTestingErr(err, t, "Error storing repository revisions %v")
versionOne, err := version.FindOne(version.ByProjectIdAndRevision(projectRef.Identifier, revisionOne.Revision))
testutil.HandleTestingErr(err, t, "Error retrieving first stored version %v")
versionTwo, err := version.FindOne(version.ByProjectIdAndRevision(projectRef.Identifier, revisionTwo.Revision))
testutil.HandleTestingErr(err, t, "Error retreiving second stored version %v")
So(versionOne.Revision, ShouldEqual, revisionOne.Revision)
So(versionTwo.Revision, ShouldEqual, revisionTwo.Revision)
})
Reset(func() {
dropTestDB(t)
})
})
Convey("When storing versions from repositories with remote configuration files...", t, func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("foo", time.Now().Add(1*time.Minute)),
}
poller := NewMockRepoPoller(project, revisions)
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 10,
},
poller,
}
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("We should not fetch configs for versions we already have stored.",
func() {
So(poller.ConfigGets, ShouldBeZeroValue)
// Store revisions the first time
_, err := repoTracker.StoreRevisions(revisions)
So(err, ShouldBeNil)
// We should have fetched the config once for each revision
So(poller.ConfigGets, ShouldEqual, len(revisions))
// Store them again
_, err = repoTracker.StoreRevisions(revisions)
So(err, ShouldBeNil)
// We shouldn't have fetched the config any additional times
// since we have already stored these versions
So(poller.ConfigGets, ShouldEqual, len(revisions))
},
)
//.........这里部分代码省略.........
示例3: TestBatchTimes
func TestBatchTimes(t *testing.T) {
dropTestDB(t)
Convey("When deciding whether or not to activate variants for the most recently stored version", t, func() {
// We create a version with an activation time of now so that all the bvs have a last activation time of now.
previouslyActivatedVersion := version.Version{
Id: "previously activated",
Identifier: "testproject",
BuildVariants: []version.BuildStatus{
{
BuildVariant: "bv1",
Activated: true,
ActivateAt: time.Now(),
},
{
BuildVariant: "bv2",
Activated: true,
ActivateAt: time.Now(),
},
},
RevisionOrderNumber: 0,
Requester: evergreen.RepotrackerVersionRequester,
}
So(previouslyActivatedVersion.Insert(), ShouldBeNil)
// insert distros used in testing.
d := distro.Distro{Id: "test-distro-one"}
So(d.Insert(), ShouldBeNil)
d.Id = "test-distro-two"
So(d.Insert(), ShouldBeNil)
Convey("If the project's batch time has not elapsed, and no buildvariants "+
"have overriden their batch times, no variants should be activated", func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("foo", time.Now()),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 1,
},
NewMockRepoPoller(project, revisions),
}
v, err := repoTracker.StoreRevisions(revisions)
So(v, ShouldNotBeNil)
So(err, ShouldBeNil)
So(len(v.BuildVariants), ShouldEqual, 2)
So(repoTracker.activateElapsedBuilds(v), ShouldBeNil)
So(v.BuildVariants[0].Activated, ShouldBeFalse)
So(v.BuildVariants[1].Activated, ShouldBeFalse)
})
Convey("If the project's batch time has elapsed, and no buildvariants "+
"have overridden their batch times, all variants should be activated", func() {
project := createTestProject(nil, nil)
revisions := []model.Revision{
*createTestRevision("bar", time.Now().Add(time.Duration(-6*time.Minute))),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 0,
},
NewMockRepoPoller(project, revisions),
}
version, err := repoTracker.StoreRevisions(revisions)
So(version, ShouldNotBeNil)
So(err, ShouldBeNil)
So(repoTracker.activateElapsedBuilds(version), ShouldBeNil)
bv1, found := findStatus(version, "bv1")
So(found, ShouldBeTrue)
So(bv1.Activated, ShouldBeTrue)
bv2, found := findStatus(version, "bv2")
So(found, ShouldBeTrue)
So(bv2.Activated, ShouldBeTrue)
})
Convey("If the project's batch time has elapsed, but both variants "+
"have overridden their batch times (which have not elapsed)"+
", no variants should be activated", func() {
// need to assign pointer vals
twoforty := 240
onetwenty := 120
project := createTestProject(&twoforty, &onetwenty)
revisions := []model.Revision{
*createTestRevision("baz", time.Now()),
}
repoTracker := RepoTracker{
testConfig,
&model.ProjectRef{
Identifier: "testproject",
BatchTime: 60,
},
//.........这里部分代码省略.........