本文整理汇总了Golang中github.com/evergreen-ci/evergreen/util.SliceContains函数的典型用法代码示例。如果您正苦于以下问题:Golang SliceContains函数的具体用法?Golang SliceContains怎么用?Golang SliceContains使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SliceContains函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetVariantsWithTask
func TestGetVariantsWithTask(t *testing.T) {
Convey("With a project", t, func() {
project := &Project{
BuildVariants: []BuildVariant{
BuildVariant{
Name: "bv1",
Tasks: []BuildVariantTask{
BuildVariantTask{
Name: "suite1",
},
},
},
BuildVariant{
Name: "bv2",
Tasks: []BuildVariantTask{
BuildVariantTask{
Name: "suite1",
},
BuildVariantTask{
Name: "suite2",
},
},
},
BuildVariant{
Name: "bv3",
Tasks: []BuildVariantTask{
BuildVariantTask{
Name: "suite2",
},
},
},
},
}
Convey("when getting the build variants where a task applies", func() {
Convey("it should be run on any build variants where the test is"+
" specified to run", func() {
variants := project.GetVariantsWithTask("suite1")
So(len(variants), ShouldEqual, 2)
So(util.SliceContains(variants, "bv1"), ShouldBeTrue)
So(util.SliceContains(variants, "bv2"), ShouldBeTrue)
variants = project.GetVariantsWithTask("suite2")
So(len(variants), ShouldEqual, 2)
So(util.SliceContains(variants, "bv2"), ShouldBeTrue)
So(util.SliceContains(variants, "bv3"), ShouldBeTrue)
})
})
})
}
开发者ID:amidvidy,项目名称:evergreen,代码行数:57,代码来源:project_test.go
示例2: notificationsToStruct
// creates/returns slice of 'relevant' NotificationKeys a
// notification is relevant if it has at least one recipient
func notificationsToStruct(mciNotification *MCINotification) (notifyOn []NotificationKey) {
// Get default notifications
for _, notification := range mciNotification.Notifications {
if len(notification.Recipients) != 0 {
// flag the notification as needed
key := NotificationKey{
Project: notification.Project,
NotificationName: notification.Name,
NotificationType: getType(notification.Name),
NotificationRequester: evergreen.RepotrackerVersionRequester,
}
// prevent duplicate notifications from being sent
if !util.SliceContains(notifyOn, key) {
notifyOn = append(notifyOn, key)
}
}
}
// Get team notifications
for _, team := range mciNotification.Teams {
for _, subscription := range team.Subscriptions {
for _, name := range subscription.NotifyOn {
key := NotificationKey{
Project: subscription.Project,
NotificationName: name,
NotificationType: getType(name),
NotificationRequester: evergreen.RepotrackerVersionRequester,
}
// prevent duplicate notifications from being sent
if !util.SliceContains(notifyOn, key) {
notifyOn = append(notifyOn, key)
}
}
}
}
// Get patch notifications
for _, subscription := range mciNotification.PatchNotifications {
for _, notification := range subscription.NotifyOn {
key := NotificationKey{
Project: subscription.Project,
NotificationName: notification,
NotificationType: getType(notification),
NotificationRequester: evergreen.PatchVersionRequester,
}
// prevent duplicate notifications from being sent
if !util.SliceContains(notifyOn, key) {
notifyOn = append(notifyOn, key)
}
}
}
return
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:58,代码来源:notify.go
示例3: NewPatchTaskIdTable
// NewPatchTaskIdTable constructs a new TaskIdTable (map of [variant, task display name]->[task id])
func NewPatchTaskIdTable(proj *Project, v *version.Version, patchConfig TVPairSet) TaskIdTable {
table := TaskIdTable{}
processedVariants := map[string]bool{}
for _, vt := range patchConfig {
// don't hit the same variant more than once
if _, ok := processedVariants[vt.Variant]; ok {
continue
}
processedVariants[vt.Variant] = true
// we must track the project's variants definitions as well,
// so that we don't create Ids for variants that don't exist.
projBV := proj.FindBuildVariant(vt.Variant)
taskNamesForVariant := patchConfig.TaskNames(vt.Variant)
for _, t := range projBV.Tasks {
// create Ids for each task that can run on the variant and is requested by the patch.
if util.SliceContains(taskNamesForVariant, t.Name) {
taskId := util.CleanName(
fmt.Sprintf("%v_%v_%v_%v_%v",
proj.Identifier, projBV.Name, t.Name, v.Revision,
v.CreateTime.Format(build.IdTimeLayout)))
table[TVPair{vt.Variant, t.Name}] = taskId
}
}
}
return table
}
开发者ID:tychoish,项目名称:evergreen,代码行数:27,代码来源:project.go
示例4: validateParams
// Validate that all necessary params are set and valid.
func (s3pc *S3PutCommand) validateParams() error {
if s3pc.AwsKey == "" {
return fmt.Errorf("aws_key cannot be blank")
}
if s3pc.AwsSecret == "" {
return fmt.Errorf("aws_secret cannot be blank")
}
if s3pc.LocalFile == "" {
return fmt.Errorf("local_file cannot be blank")
}
if s3pc.RemoteFile == "" {
return fmt.Errorf("remote_file cannot be blank")
}
if s3pc.ContentType == "" {
return fmt.Errorf("content_type cannot be blank")
}
if !util.SliceContains(artifact.ValidVisibilities, s3pc.Visibility) {
return fmt.Errorf("invalid visibility setting: %v", s3pc.Visibility)
}
// make sure the bucket is valid
if err := validateS3BucketName(s3pc.Bucket); err != nil {
return fmt.Errorf("%v is an invalid bucket name: %v", s3pc.Bucket, err)
}
// make sure the s3 permissions are valid
if !validS3Permissions(s3pc.Permissions) {
return fmt.Errorf("permissions '%v' are not valid", s3pc.Permissions)
}
return nil
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:33,代码来源:put_command.go
示例5: computeScheduledTasksDuration
// computeScheduledTasksDuration returns the total estimated duration of all
// tasks scheduled to be run in a given task queue
func computeScheduledTasksDuration(
scheduledDistroTasksData *ScheduledDistroTasksData) (
scheduledTasksDuration float64, sharedTasksDuration map[string]float64) {
taskQueueItems := scheduledDistroTasksData.taskQueueItems
taskRunDistros := scheduledDistroTasksData.taskRunDistros
tasksAccountedFor := scheduledDistroTasksData.tasksAccountedFor
currentDistroId := scheduledDistroTasksData.currentDistroId
sharedTasksDuration = make(map[string]float64)
// compute the total expected duration for tasks in this queue
for _, taskQueueItem := range taskQueueItems {
if !tasksAccountedFor[taskQueueItem.Id] {
scheduledTasksDuration += taskQueueItem.ExpectedDuration.Seconds()
tasksAccountedFor[taskQueueItem.Id] = true
}
// if the task can be run on multiple distros - including this one - add
// it to the total duration of 'shared tasks' for the distro and all
// other distros it can be run on
distroIds, ok := taskRunDistros[taskQueueItem.Id]
if ok && util.SliceContains(distroIds, currentDistroId) {
for _, distroId := range distroIds {
sharedTasksDuration[distroId] +=
taskQueueItem.ExpectedDuration.Seconds()
}
}
}
return
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:32,代码来源:duration_based_host_allocator.go
示例6: GetPanelConfig
func (pp *PerfPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
root := plugin.StaticWebRootFromSourceFile()
panelHTML, err := ioutil.ReadFile(root + "/task_perf_data.html")
if err != nil {
return nil, fmt.Errorf("Can't load panel html file: %v", err)
}
return &plugin.PanelConfig{
StaticRoot: plugin.StaticWebRootFromSourceFile(),
Panels: []plugin.UIPanel{
{
Includes: includes,
Page: plugin.TaskPage,
Position: plugin.PageCenter,
PanelHTML: template.HTML(panelHTML),
DataFunc: func(context plugin.UIContext) (interface{}, error) {
return struct {
Enabled bool `json:"enabled"`
}{util.SliceContains(pp.Projects, context.ProjectRef.Identifier)}, nil
},
},
},
}, nil
return nil, nil
}
开发者ID:3rf,项目名称:perf,代码行数:25,代码来源:perf.go
示例7: applyPatch
func applyPatch(patch *service.RestPatch, rootCloneDir string, conf *model.Project, variant *model.BuildVariant) error {
// patch sets and contain multiple patches, some of them for modules
for _, patchPart := range patch.Patches {
var dir string
if patchPart.ModuleName == "" {
// if patch is not part of a module, just apply patch against src root
dir = rootCloneDir
} else {
fmt.Println("Applying patches for module", patchPart.ModuleName)
// if patch is part of a module, apply patch in module root
module, err := conf.GetModuleByName(patchPart.ModuleName)
if err != nil || module == nil {
return fmt.Errorf("can't find module %v: %v", patchPart.ModuleName, err)
}
// skip the module if this build variant does not use it
if !util.SliceContains(variant.Modules, module.Name) {
continue
}
dir = filepath.Join(rootCloneDir, module.Prefix, module.Name)
}
args := []string{"apply", "--whitespace=fix"}
applyCmd := exec.Command("git", args...)
applyCmd.Stdout, applyCmd.Stderr, applyCmd.Dir = os.Stdout, os.Stderr, dir
applyCmd.Stdin = bytes.NewReader([]byte(patchPart.PatchSet.Patch))
err := applyCmd.Run()
if err != nil {
return err
}
}
return nil
}
开发者ID:tychoish,项目名称:evergreen,代码行数:34,代码来源:fetch.go
示例8: AddNewTasksForPatch
// Given a patch version and a list of task names, creates a new task with
// the given name for each variant, if applicable.
func AddNewTasksForPatch(p *patch.Patch, patchVersion *version.Version, project *Project,
taskNames []string) error {
// create new tasks for all of the added patch tasks
var newTasks []string
for _, taskName := range taskNames {
if !util.SliceContains(p.Tasks, taskName) {
newTasks = append(newTasks, taskName)
}
}
// add tasks to the patch in the db
if err := p.AddTasks(taskNames); err != nil {
return err
}
// add new tasks to the build, if they exist
if len(newTasks) > 0 {
builds, err := build.Find(build.ByIds(patchVersion.BuildIds))
if err != nil {
return err
}
for _, b := range builds {
if _, err = AddTasksToBuild(&b, project, patchVersion, newTasks); err != nil {
return err
}
}
}
return nil
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:32,代码来源:patch_lifecycle.go
示例9: confirm
// confirm asks the user a yes/no question and returns true/false if they reply with y/yes/n/no.
// if defaultYes is true, allows user to just hit enter without typing an explicit yes.
func confirm(message string, defaultYes bool) bool {
reply := ""
yes := []string{"y", "yes"}
no := []string{"n", "no"}
if defaultYes {
yes = append(yes, "")
}
for {
reply = prompt(message)
if util.SliceContains(yes, strings.ToLower(reply)) {
return true
}
if util.SliceContains(no, strings.ToLower(reply)) {
return false
}
}
}
开发者ID:tychoish,项目名称:evergreen,代码行数:19,代码来源:settings.go
示例10: ShouldContainResembling
// ShouldContainResembling tests whether a slice contains an element that DeepEquals
// the expected input.
func ShouldContainResembling(actual interface{}, expected ...interface{}) string {
if len(expected) != 1 {
return "ShouldContainResembling takes 1 argument"
}
if !util.SliceContains(actual, expected[0]) {
return fmt.Sprintf("%#v does not contain %#v", actual, expected[0])
}
return ""
}
开发者ID:tychoish,项目名称:evergreen,代码行数:11,代码来源:project_parser_test.go
示例11: shouldRunForVariant
func (self *S3GetCommand) shouldRunForVariant(buildVariantName string) bool {
//No buildvariant filter, so run always
if len(self.BuildVariants) == 0 {
return true
}
//Only run if the buildvariant specified appears in our list.
return util.SliceContains(self.BuildVariants, buildVariantName)
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:9,代码来源:get_command.go
示例12: ShouldSkip
func (self *BuildEmail) ShouldSkip(skipVariants []string) bool {
buildVariant := self.Trigger.Current.BuildVariant
if util.SliceContains(skipVariants, buildVariant) {
evergreen.Logger.Logf(slogger.DEBUG, "Skipping buildvariant %v “%v” notification: “%v”",
buildVariant, self.Trigger.Key.NotificationName, self.Subject)
return true
}
return false
}
开发者ID:tychoish,项目名称:evergreen,代码行数:9,代码来源:email.go
示例13: getFailedTasks
// get the failed task(s) for a given build
func getFailedTasks(current *build.Build, notificationName string) (failedTasks []build.TaskCache) {
if util.SliceContains(buildFailureKeys, notificationName) {
for _, task := range current.Tasks {
if task.Status == evergreen.TaskFailed {
failedTasks = append(failedTasks, task)
}
}
}
return
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:11,代码来源:notify.go
示例14: AddNewBuildsForPatch
// Given the patch version and a list of build variants, creates new builds
// with the patch's tasks.
func AddNewBuildsForPatch(p *patch.Patch, patchVersion *version.Version, project *Project,
buildVariants []string) (*version.Version, error) {
// compute a list of the newly added build variants
var newVariants []string
for _, variant := range buildVariants {
if !util.SliceContains(p.BuildVariants, variant) {
newVariants = append(newVariants, variant)
}
}
// update the patch
if err := p.AddBuildVariants(buildVariants); err != nil {
return nil, err
}
newBuildIds := make([]string, 0)
newBuildStatuses := make([]version.BuildStatus, 0)
tt := BuildTaskIdTable(project, patchVersion)
for _, buildVariant := range newVariants {
evergreen.Logger.Logf(slogger.INFO,
"Creating build for version %v, buildVariant %v, activated = %v",
patchVersion.Id, buildVariant, p.Activated)
buildId, err := CreateBuildFromVersion(
project, patchVersion, tt, buildVariant, p.Activated, p.Tasks)
if err != nil {
return nil, err
}
newBuildIds = append(newBuildIds, buildId)
newBuildStatuses = append(newBuildStatuses,
version.BuildStatus{
BuildVariant: buildVariant,
BuildId: buildId,
Activated: p.Activated,
},
)
patchVersion.BuildIds = append(patchVersion.BuildIds, buildId)
}
err := version.UpdateOne(
bson.M{version.IdKey: patchVersion.Id},
bson.M{
"$push": bson.M{
version.BuildIdsKey: bson.M{"$each": newBuildIds},
version.BuildVariantsKey: bson.M{"$each": newBuildStatuses},
},
},
)
if err != nil {
return nil, err
}
return patchVersion, nil
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:57,代码来源:patch_lifecycle.go
示例15: modifyHosts
func (uis *UIServer) modifyHosts(w http.ResponseWriter, r *http.Request) {
_ = MustHaveUser(r)
opts := &uiParams{}
err := util.ReadJSONInto(r.Body, opts)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
hostIds := opts.HostIds
if len(hostIds) == 1 && strings.TrimSpace(hostIds[0]) == "" {
http.Error(w, "No host ID's found in request", http.StatusBadRequest)
return
}
// fetch all relevant hosts
hosts, err := host.Find(host.ByIds(hostIds))
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, fmt.Errorf("Error finding hosts: %v", err))
return
}
if len(hosts) == 0 {
http.Error(w, "No matching hosts found.", http.StatusBadRequest)
return
}
// determine what action needs to be taken
switch opts.Action {
case "updateStatus":
newStatus := opts.Status
if !util.SliceContains(validUpdateToStatuses, newStatus) {
http.Error(w, fmt.Sprintf("Invalid status: %v", opts.Status), http.StatusBadRequest)
return
}
numHostsUpdated := 0
for _, host := range hosts {
err := host.SetStatus(newStatus)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, fmt.Errorf("Error updating host %v", err))
return
}
numHostsUpdated += 1
}
msg := NewSuccessFlash(fmt.Sprintf("%v host(s) status successfully updated to '%v'",
numHostsUpdated, newStatus))
PushFlash(uis.CookieStore, r, w, msg)
return
default:
http.Error(w, fmt.Sprintf("Unrecognized action: %v", opts.Action), http.StatusBadRequest)
return
}
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:55,代码来源:host.go
示例16: IsSuperUser
// IsSuperUser verifies that a given user has super user permissions.
// A user has these permission if they are in the super users list or if the list is empty,
// in which case all users are super users.
func IsSuperUser(settings evergreen.Settings, u User) bool {
if u == nil {
return false
}
if util.SliceContains(settings.SuperUsers, u.Username()) ||
len(settings.SuperUsers) == 0 {
return true
}
return false
}
开发者ID:tychoish,项目名称:evergreen,代码行数:15,代码来源:auth.go
示例17: contains
// contains returns whether a value is contained by a definition.
// Note that a value that doesn't contain every matrix axis will still
// be evaluated based on the axes that exist.
func (mdef matrixDefinition) contains(mv matrixValue) bool {
for k, v := range mv {
axis, ok := mdef[k]
if !ok {
return false
}
if !util.SliceContains(axis, v) {
return false
}
}
return true
}
开发者ID:tychoish,项目名称:evergreen,代码行数:15,代码来源:project_matrix.go
示例18: isSuperUser
// isSuperUser verifies that a given user has super user permissions.
// A user has these permission if they are in the super users list or if the list is empty,
// in which case all users are super users.
func (uis *UIServer) isSuperUser(u *user.DBUser) bool {
if u == nil {
return false
}
if util.SliceContains(uis.Settings.SuperUsers, u.Id) ||
len(uis.Settings.SuperUsers) == 0 {
return true
}
return false
}
开发者ID:tychoish,项目名称:evergreen,代码行数:15,代码来源:middleware.go
示例19: validS3Permissions
func validS3Permissions(perm string) bool {
return util.SliceContains(
[]s3.ACL{
s3.Private,
s3.PublicRead,
s3.PublicReadWrite,
s3.AuthenticatedRead,
s3.BucketOwnerRead,
s3.BucketOwnerFull,
},
s3.ACL(perm),
)
}
开发者ID:tychoish,项目名称:evergreen,代码行数:13,代码来源:s3_copy_validation.go
示例20: getFailedTests
// get the specific failed test(s) for this task
func getFailedTests(current *model.Task, notificationName string) (failedTests []model.TestResult) {
if util.SliceContains(taskFailureKeys, notificationName) {
for _, test := range current.TestResults {
if test.Status == "fail" {
// get the base name for windows/non-windows paths
test.TestFile = path.Base(strings.Replace(test.TestFile, "\\", "/", -1))
failedTests = append(failedTests, test)
}
}
}
return
}
开发者ID:himanshugpt,项目名称:evergreen,代码行数:14,代码来源:notify.go
注:本文中的github.com/evergreen-ci/evergreen/util.SliceContains函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论