本文整理匯總了Golang中github.com/evergreen-ci/evergreen/auth.LoadUserManager函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadUserManager函數的具體用法?Golang LoadUserManager怎麽用?Golang LoadUserManager使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoadUserManager函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
settings := evergreen.GetSettingsOrExit()
if settings.Ui.LogFile != "" {
evergreen.SetLogger(settings.Ui.LogFile)
}
db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings))
home := evergreen.FindEvergreenHome()
userManager, err := auth.LoadUserManager(settings.AuthConfig)
if err != nil {
fmt.Println("Failed to create user manager:", err)
os.Exit(1)
}
cookieStore := sessions.NewCookieStore([]byte(settings.Ui.Secret))
uis := ui.UIServer{
nil, // render
settings.Ui.Url, // RootURL
userManager, // User Manager
*settings, // mci settings
cookieStore, // cookiestore
nil, // plugin panel manager
}
router, err := uis.NewRouter()
if err != nil {
fmt.Println("Failed to create router:", err)
os.Exit(1)
}
webHome := filepath.Join(home, "public")
functionOptions := ui.FuncOptions{webHome, settings.Ui.HelpUrl, true, router}
functions, err := ui.MakeTemplateFuncs(functionOptions, settings.SuperUsers)
if err != nil {
fmt.Println("Failed to create template function map:", err)
os.Exit(1)
}
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, ui.WebRootPath, ui.Templates),
DisableCache: !settings.Ui.CacheTemplates,
Funcs: functions,
})
err = uis.InitPlugins()
if err != nil {
fmt.Println("WARNING: Error initializing plugins:", err)
}
n := negroni.New()
n.Use(negroni.NewStatic(http.Dir(webHome)))
n.Use(ui.NewLogger())
n.Use(negroni.HandlerFunc(ui.UserMiddleware(userManager)))
n.UseHandler(router)
graceful.Run(settings.Ui.HttpListenAddr, requestTimeout, n)
evergreen.Logger.Logf(slogger.INFO, "UI server cleanly terminated")
}
示例2: New
// New returns an APIServer initialized with the given settings and plugins.
func New(settings *evergreen.Settings, plugins []plugin.APIPlugin) (*APIServer, error) {
authManager, err := auth.LoadUserManager(settings.AuthConfig)
if err != nil {
return nil, err
}
return &APIServer{render.New(render.Options{}), authManager, *settings, plugins}, nil
}
示例3: NewUIServer
func NewUIServer(settings *evergreen.Settings, home string) (*UIServer, error) {
uis := &UIServer{}
if settings.Ui.LogFile != "" {
evergreen.SetLogger(settings.Ui.LogFile)
}
db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings))
uis.Settings = *settings
uis.Home = home
userManager, err := auth.LoadUserManager(settings.AuthConfig)
if err != nil {
return nil, err
}
uis.UserManager = userManager
uis.CookieStore = sessions.NewCookieStore([]byte(settings.Ui.Secret))
uis.PluginTemplates = map[string]*htmlTemplate.Template{}
return uis, nil
}
示例4: TestGetTaskInfo
func TestGetTaskInfo(t *testing.T) {
userManager, err := auth.LoadUserManager(taskTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: taskTestConfig.Ui.Url,
Settings: *taskTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
Funcs: nil,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failure in uis.NewRouter()")
Convey("When finding info on a particular task", t, func() {
testutil.HandleTestingErr(db.Clear(model.TasksCollection), t,
"Error clearing '%v' collection", model.TasksCollection)
taskId := "my-task"
versionId := "my-version"
projectName := "project_test"
testResult := model.TestResult{
Status: "success",
TestFile: "some-test",
URL: "some-url",
StartTime: float64(time.Now().Add(-9 * time.Minute).Unix()),
EndTime: float64(time.Now().Add(-1 * time.Minute).Unix()),
}
task := &model.Task{
Id: taskId,
CreateTime: time.Now().Add(-20 * time.Minute),
ScheduledTime: time.Now().Add(-15 * time.Minute),
DispatchTime: time.Now().Add(-14 * time.Minute),
StartTime: time.Now().Add(-10 * time.Minute),
FinishTime: time.Now().Add(-5 * time.Second),
PushTime: time.Now().Add(-1 * time.Millisecond),
Version: versionId,
Project: projectName,
Revision: fmt.Sprintf("%x", rand.Int()),
Priority: 10,
LastHeartbeat: time.Now(),
Activated: false,
BuildId: "some-build-id",
DistroId: "some-distro-id",
BuildVariant: "some-build-variant",
DependsOn: []model.Dependency{{"some-other-task", ""}},
DisplayName: "My task",
HostId: "some-host-id",
Restarts: 0,
Execution: 0,
Archived: false,
RevisionOrderNumber: 42,
Requester: evergreen.RepotrackerVersionRequester,
Status: "success",
Details: apimodels.TaskEndDetail{
TimedOut: false,
Description: "some-stage",
},
Aborted: false,
TimeTaken: time.Duration(100 * time.Millisecond),
ExpectedDuration: time.Duration(99 * time.Millisecond),
TestResults: []model.TestResult{testResult},
MinQueuePos: 0,
}
So(task.Insert(), ShouldBeNil)
file := artifact.File{
Name: "Some Artifact",
Link: "some-url",
}
artifact := artifact.Entry{
TaskId: taskId,
Files: []artifact.File{file},
}
So(artifact.Upsert(), ShouldBeNil)
url, err := router.Get("task_info").URL("task_id", taskId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
Convey("response should match contents of database", func() {
var jsonBody map[string]interface{}
//.........這裏部分代碼省略.........
示例5: TestGetTaskStatus
func TestGetTaskStatus(t *testing.T) {
userManager, err := auth.LoadUserManager(taskTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: taskTestConfig.Ui.Url,
Settings: *taskTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
Funcs: nil,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failure in uis.NewRouter()")
Convey("When finding the status of a particular task", t, func() {
testutil.HandleTestingErr(db.Clear(model.TasksCollection), t,
"Error clearing '%v' collection", model.TasksCollection)
taskId := "my-task"
testResult := model.TestResult{
Status: "success",
TestFile: "some-test",
URL: "some-url",
StartTime: float64(time.Now().Add(-9 * time.Minute).Unix()),
EndTime: float64(time.Now().Add(-1 * time.Minute).Unix()),
}
task := &model.Task{
Id: taskId,
DisplayName: "My task",
Status: "success",
Details: apimodels.TaskEndDetail{
TimedOut: false,
Description: "some-stage",
},
TestResults: []model.TestResult{testResult},
}
So(task.Insert(), ShouldBeNil)
url, err := router.Get("task_status").URL("task_id", taskId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
Convey("response should match contents of database", func() {
var jsonBody map[string]interface{}
err = json.Unmarshal(response.Body.Bytes(), &jsonBody)
So(err, ShouldBeNil)
var rawJsonBody map[string]*json.RawMessage
err = json.Unmarshal(response.Body.Bytes(), &rawJsonBody)
So(err, ShouldBeNil)
So(jsonBody["task_id"], ShouldEqual, task.Id)
So(jsonBody["task_name"], ShouldEqual, task.DisplayName)
So(jsonBody["status"], ShouldEqual, task.Status)
_jsonStatusDetails, ok := jsonBody["status_details"]
So(ok, ShouldBeTrue)
jsonStatusDetails, ok := _jsonStatusDetails.(map[string]interface{})
So(ok, ShouldBeTrue)
So(jsonStatusDetails["timed_out"], ShouldEqual, task.Details.TimedOut)
So(jsonStatusDetails["timeout_stage"], ShouldEqual, task.Details.Description)
_jsonTestResults, ok := jsonBody["tests"]
So(ok, ShouldBeTrue)
jsonTestResults, ok := _jsonTestResults.(map[string]interface{})
So(ok, ShouldBeTrue)
So(len(jsonTestResults), ShouldEqual, 1)
_jsonTestResult, ok := jsonTestResults[testResult.TestFile]
So(ok, ShouldBeTrue)
jsonTestResult, ok := _jsonTestResult.(map[string]interface{})
So(ok, ShouldBeTrue)
So(jsonTestResult["status"], ShouldEqual, testResult.Status)
So(jsonTestResult["time_taken"], ShouldNotBeNil) // value correctness is unchecked
_jsonTestResultLogs, ok := jsonTestResult["logs"]
So(ok, ShouldBeTrue)
jsonTestResultLogs, ok := _jsonTestResultLogs.(map[string]interface{})
So(ok, ShouldBeTrue)
//.........這裏部分代碼省略.........
示例6: TestGetBuildInfo
func TestGetBuildInfo(t *testing.T) {
userManager, err := auth.LoadUserManager(buildTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: buildTestConfig.Ui.Url,
Settings: *buildTestConfig,
UserManager: userManager,
}
uis.InitPlugins()
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failed to create ui server router")
Convey("When finding info on a particular build", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t,
"Error clearing '%v' collection", build.Collection)
buildId := "my-build"
versionId := "my-version"
projectName := "mci-test"
err := modelutil.CreateTestLocalConfig(buildTestConfig, "mci-test", "")
So(err, ShouldBeNil)
err = modelutil.CreateTestLocalConfig(buildTestConfig, "render", "")
So(err, ShouldBeNil)
err = modelutil.CreateTestLocalConfig(buildTestConfig, "project_test", "")
task := build.TaskCache{
Id: "some-task-id",
DisplayName: "some-task-name",
Status: "success",
TimeTaken: time.Duration(100 * time.Millisecond),
}
build := &build.Build{
Id: buildId,
CreateTime: time.Now().Add(-20 * time.Minute),
StartTime: time.Now().Add(-10 * time.Minute),
FinishTime: time.Now().Add(-5 * time.Second),
PushTime: time.Now().Add(-1 * time.Millisecond),
Version: versionId,
Project: projectName,
Revision: fmt.Sprintf("%x", rand.Int()),
BuildVariant: "some-build-variant",
BuildNumber: "42",
Status: "success",
Activated: true,
ActivatedTime: time.Now().Add(-15 * time.Minute),
RevisionOrderNumber: rand.Int(),
Tasks: []build.TaskCache{task},
TimeTaken: time.Duration(10 * time.Minute),
DisplayName: "My build",
Requester: evergreen.RepotrackerVersionRequester,
}
So(build.Insert(), ShouldBeNil)
url, err := router.Get("build_info").URL("build_id", buildId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
Convey("response should match contents of database", func() {
var jsonBody map[string]interface{}
err = json.Unmarshal(response.Body.Bytes(), &jsonBody)
So(err, ShouldBeNil)
var rawJsonBody map[string]*json.RawMessage
err = json.Unmarshal(response.Body.Bytes(), &rawJsonBody)
So(err, ShouldBeNil)
So(jsonBody["id"], ShouldEqual, build.Id)
var createTime time.Time
err = json.Unmarshal(*rawJsonBody["create_time"], &createTime)
So(err, ShouldBeNil)
So(createTime, ShouldHappenWithin, TimePrecision, build.CreateTime)
var startTime time.Time
err = json.Unmarshal(*rawJsonBody["start_time"], &startTime)
So(err, ShouldBeNil)
So(startTime, ShouldHappenWithin, TimePrecision, build.StartTime)
//.........這裏部分代碼省略.........
示例7: TestGetBuildStatus
func TestGetBuildStatus(t *testing.T) {
userManager, err := auth.LoadUserManager(buildTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: buildTestConfig.Ui.Url,
Settings: *buildTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
})
uis.InitPlugins()
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failed to create ui server router")
Convey("When finding the status of a particular build", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t,
"Error clearing '%v' collection", build.Collection)
buildId := "my-build"
versionId := "my-version"
task := build.TaskCache{
Id: "some-task-id",
DisplayName: "some-task-name",
Status: "success",
TimeTaken: time.Duration(100 * time.Millisecond),
}
build := &build.Build{
Id: buildId,
Version: versionId,
BuildVariant: "some-build-variant",
DisplayName: "Some Build Variant",
Tasks: []build.TaskCache{task},
}
So(build.Insert(), ShouldBeNil)
url, err := router.Get("build_status").URL("build_id", buildId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
Convey("response should match contents of database", func() {
var jsonBody map[string]interface{}
err = json.Unmarshal(response.Body.Bytes(), &jsonBody)
So(err, ShouldBeNil)
var rawJsonBody map[string]*json.RawMessage
err = json.Unmarshal(response.Body.Bytes(), &rawJsonBody)
So(err, ShouldBeNil)
So(jsonBody["build_id"], ShouldEqual, build.Id)
So(jsonBody["build_variant"], ShouldEqual, build.BuildVariant)
_jsonTasks, ok := jsonBody["tasks"]
So(ok, ShouldBeTrue)
jsonTasks, ok := _jsonTasks.(map[string]interface{})
So(ok, ShouldBeTrue)
So(len(jsonTasks), ShouldEqual, 1)
_jsonTask, ok := jsonTasks[task.DisplayName]
So(ok, ShouldBeTrue)
jsonTask, ok := _jsonTask.(map[string]interface{})
So(ok, ShouldBeTrue)
So(jsonTask["task_id"], ShouldEqual, task.Id)
So(jsonTask["status"], ShouldEqual, task.Status)
So(jsonTask["time_taken"], ShouldEqual, task.TimeTaken)
})
})
Convey("When finding the status of a nonexistent build", t, func() {
buildId := "not-present"
url, err := router.Get("build_status").URL("build_id", buildId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
//.........這裏部分代碼省略.........
示例8: TestGetVersionStatus
func TestGetVersionStatus(t *testing.T) {
userManager, err := auth.LoadUserManager(versionTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: versionTestConfig.Ui.Url,
Settings: *versionTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
Funcs: nil,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failure in uis.NewRouter()")
Convey("When finding the status of a particular version", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t,
"Error clearing '%v' collection", build.Collection)
versionId := "my-version"
task := build.TaskCache{
Id: "some-task-id",
DisplayName: "some-task-name",
Status: "success",
TimeTaken: time.Duration(100 * time.Millisecond),
}
build := &build.Build{
Id: "some-build-id",
Version: versionId,
BuildVariant: "some-build-variant",
DisplayName: "Some Build Variant",
Tasks: []build.TaskCache{task},
}
So(build.Insert(), ShouldBeNil)
Convey("grouped by tasks", func() {
groupBy := "tasks"
url, err := router.Get("version_status").URL("version_id", versionId)
So(err, ShouldBeNil)
query := url.Query()
query.Set("groupby", groupBy)
url.RawQuery = query.Encode()
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
Convey("response should match contents of database", func() {
var jsonBody map[string]interface{}
err = json.Unmarshal(response.Body.Bytes(), &jsonBody)
So(err, ShouldBeNil)
So(jsonBody["version_id"], ShouldEqual, versionId)
_jsonTasks, ok := jsonBody["tasks"]
So(ok, ShouldBeTrue)
jsonTasks, ok := _jsonTasks.(map[string]interface{})
So(ok, ShouldBeTrue)
So(len(jsonTasks), ShouldEqual, 1)
_jsonTask, ok := jsonTasks[task.DisplayName]
So(ok, ShouldBeTrue)
jsonTask, ok := _jsonTask.(map[string]interface{})
So(ok, ShouldBeTrue)
_jsonBuild, ok := jsonTask[build.BuildVariant]
So(ok, ShouldBeTrue)
jsonBuild, ok := _jsonBuild.(map[string]interface{})
So(ok, ShouldBeTrue)
So(jsonBuild["task_id"], ShouldEqual, task.Id)
So(jsonBuild["status"], ShouldEqual, task.Status)
So(jsonBuild["time_taken"], ShouldEqual, task.TimeTaken)
})
Convey("is the default option", func() {
url, err := router.Get("version_status").URL("version_id", versionId)
So(err, ShouldBeNil)
request, err := http.NewRequest("GET", url.String(), nil)
So(err, ShouldBeNil)
_response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
//.........這裏部分代碼省略.........
示例9: TestActivateVersion
func TestActivateVersion(t *testing.T) {
userManager, err := auth.LoadUserManager(versionTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: versionTestConfig.Ui.Url,
Settings: *versionTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
Funcs: nil,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failure in uis.NewRouter()")
Convey("When marking a particular version as active", t, func() {
testutil.HandleTestingErr(db.Clear(version.Collection), t,
"Error clearing '%v' collection", version.Collection)
versionId := "my-version"
projectName := "project_test"
build := &build.Build{
Id: "some-build-id",
BuildVariant: "some-build-variant",
}
So(build.Insert(), ShouldBeNil)
v := &version.Version{
Id: versionId,
CreateTime: time.Now().Add(-20 * time.Minute),
StartTime: time.Now().Add(-10 * time.Minute),
FinishTime: time.Now().Add(-5 * time.Second),
Revision: fmt.Sprintf("%x", rand.Int()),
Author: "some-author",
AuthorEmail: "some-email",
Message: "some-message",
Status: "success",
BuildIds: []string{build.Id},
BuildVariants: []version.BuildStatus{{"some-build-variant", true, time.Now().Add(-20 * time.Minute), "some-build-id"}},
RevisionOrderNumber: rand.Int(),
Owner: "some-owner",
Repo: "some-repo",
Branch: "some-branch",
RepoKind: "github",
Identifier: projectName,
Remote: false,
RemotePath: "",
Requester: evergreen.RepotrackerVersionRequester,
}
So(v.Insert(), ShouldBeNil)
url, err := router.Get("version_info").URL("version_id", versionId)
So(err, ShouldBeNil)
var body = map[string]interface{}{
"activated": true,
}
jsonBytes, err := json.Marshal(body)
So(err, ShouldBeNil)
bodyReader := bytes.NewReader(jsonBytes)
request, err := http.NewRequest("PATCH", url.String(), bodyReader)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
// in the actual handler function
router.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusOK)
validateVersionInfo(v, response)
})
Convey("When marking a nonexistent version as active", t, func() {
versionId := "not-present"
url, err := router.Get("version_info").URL("version_id", versionId)
So(err, ShouldBeNil)
var body = map[string]interface{}{
"activated": true,
}
jsonBytes, err := json.Marshal(body)
So(err, ShouldBeNil)
bodyReader := bytes.NewReader(jsonBytes)
request, err := http.NewRequest("PATCH", url.String(), bodyReader)
So(err, ShouldBeNil)
response := httptest.NewRecorder()
// Need match variables to be set so can call mux.Vars(request)
//.........這裏部分代碼省略.........
示例10: TestGetRecentVersions
func TestGetRecentVersions(t *testing.T) {
userManager, err := auth.LoadUserManager(versionTestConfig.AuthConfig)
testutil.HandleTestingErr(err, t, "Failure in loading UserManager from config")
uis := UIServer{
RootURL: versionTestConfig.Ui.Url,
Settings: *versionTestConfig,
UserManager: userManager,
}
home := evergreen.FindEvergreenHome()
uis.Render = render.New(render.Options{
Directory: filepath.Join(home, WebRootPath, Templates),
DisableCache: true,
Funcs: nil,
})
router, err := uis.NewRouter()
testutil.HandleTestingErr(err, t, "Failure in uis.NewRouter()")
err = testutil.CreateTestLocalConfig(buildTestConfig, "mci-test", "")
testutil.HandleTestingErr(err, t, "Error loading local config mci-test")
err = testutil.CreateTestLocalConfig(buildTestConfig, "render", "")
testutil.HandleTestingErr(err, t, "Error loading local config render")
Convey("When finding recent versions", t, func() {
testutil.HandleTestingErr(db.ClearCollections(version.Collection, build.Collection), t,
"Error clearing '%v' collection", version.Collection)
projectName := "project_test"
err = testutil.CreateTestLocalConfig(buildTestConfig, projectName, "")
So(err, ShouldBeNil)
otherProjectName := "my-other-project"
So(projectName, ShouldNotEqual, otherProjectName) // sanity-check
buildIdPreface := "build-id-for-version%v"
So(rest.NumRecentVersions, ShouldBeGreaterThan, 0)
versions := make([]*version.Version, 0, rest.NumRecentVersions)
// Insert a bunch of versions into the database
for i := 0; i < rest.NumRecentVersions; i++ {
v := &version.Version{
Id: fmt.Sprintf("version%v", i),
Identifier: projectName,
Author: fmt.Sprintf("author%v", i),
Revision: fmt.Sprintf("%x", rand.Int()),
Message: fmt.Sprintf("message%v", i),
RevisionOrderNumber: i + 1,
Requester: evergreen.RepotrackerVersionRequester,
}
So(v.Insert(), ShouldBeNil)
versions = append(versions, v)
}
// Construct a version that should not be present in the response
// since the length of the build ids slice is different than that
// of the build variants slice
earlyVersion := &version.Version{
Id: "some-id",
Identifier: projectName,
Author: "some-author",
Revision: fmt.Sprintf("%x", rand.Int()),
Message: "some-message",
RevisionOrderNumber: 0,
Requester: evergreen.RepotrackerVersionRequester,
}
So(earlyVersion.Insert(), ShouldBeNil)
// Construct a version that should not be present in the response
// since it belongs to a different project
otherVersion := &version.Version{
Id: "some-other-id",
Identifier: otherProjectName,
Author: "some-other-author",
Revision: fmt.Sprintf("%x", rand.Int()),
Message: "some-other-message",
RevisionOrderNumber: rest.NumRecentVersions + 1,
Requester: evergreen.RepotrackerVersionRequester,
}
So(otherVersion.Insert(), ShouldBeNil)
builds := make([]*build.Build, 0, rest.NumRecentVersions)
task := build.TaskCache{
Id: "some-task-id",
DisplayName: "some-task-name",
Status: "success",
TimeTaken: time.Duration(100 * time.Millisecond),
}
for i := 0; i < rest.NumRecentVersions; i++ {
build := &build.Build{
Id: fmt.Sprintf(buildIdPreface, i),
Version: versions[i].Id,
BuildVariant: "some-build-variant",
DisplayName: "Some Build Variant",
//.........這裏部分代碼省略.........