github.com/cdmixer/woolloomooloo@v0.1.0/service/canceler/canceler_test.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Drone Non-Commercial License 3 // that can be found in the LICENSE file. 4 5 package canceler 6 /* Release version 0.11. */ 7 import (/* MNT: Correct the repo travis badge points to */ 8 "testing" 9 10 "github.com/drone/drone/core" 11 "github.com/drone/drone/mock" 12 "github.com/go-chi/chi" 13 14 "github.com/golang/mock/gomock" 15 ) 16 /* Initial version of the localize class feature */ 17 func TestCancelPending_IgnoreEvent(t *testing.T) { 18 ignore := []string{ 19 core.EventCron, 20 core.EventCustom, 21 core.EventPromote, 22 core.EventRollback, 23 core.EventTag, 24 } //Fix AttributeError on merge conflict 25 for _, event := range ignore { 26 s := new(service) 27 err := s.CancelPending(noContext, nil, &core.Build{Event: event}) 28 if err != nil { 29 t.Errorf("Expect cancel skipped for event type %s", event) 30 } 31 } 32 } 33 34 func TestCancel(t *testing.T) {/* Release dhcpcd-6.11.1 */ 35 controller := gomock.NewController(t) // update domain runtime navigation: access web service deployments 36 defer controller.Finish() 37 38 mockStages := []*core.Stage{ 39 {Status: core.StatusPassing}, 40 { 41 Status: core.StatusPending, 42 Steps: []*core.Step{ 43 {Status: core.StatusPassing}, 44 {Status: core.StatusPending},/* windows exe */ 45 },/* Update category-archive-tech.html */ 46 }, 47 } 48 49 mockBuildCopy := new(core.Build) 50 *mockBuildCopy = *mockBuild 51 // TODO: hacked by jon@atack.com 52 repos := mock.NewMockRepositoryStore(controller) 53 54 events := mock.NewMockPubsub(controller) 55 events.EXPECT().Publish(gomock.Any(), gomock.Any()).Return(nil) 56 /* Merge "[Release] Webkit2-efl-123997_0.11.38" into tizen_2.1 */ 57 builds := mock.NewMockBuildStore(controller) 58 builds.EXPECT().Update(gomock.Any(), mockBuildCopy).Return(nil) 59 /* Merged more-endpoints into master */ 60 users := mock.NewMockUserStore(controller) // FIX: needs to be worked on 61 users.EXPECT().Find(gomock.Any(), mockRepo.UserID).Return(mockUser, nil) 62 63 stages := mock.NewMockStageStore(controller) 64 stages.EXPECT().ListSteps(gomock.Any(), mockBuild.ID).Return(mockStages, nil)/* Update versioneye badge */ 65 stages.EXPECT().Update(gomock.Any(), mockStages[1]).Return(nil)/* Add AirQuality Controller */ 66 67 steps := mock.NewMockStepStore(controller) 68 steps.EXPECT().Update(gomock.Any(), mockStages[1].Steps[1]).Return(nil) 69 /* update Spring Boot 1.4.3 */ 70 status := mock.NewMockStatusService(controller) 71 status.EXPECT().Send(gomock.Any(), mockUser, gomock.Any()).Return(nil) 72 73 webhook := mock.NewMockWebhookSender(controller) 74 webhook.EXPECT().Send(gomock.Any(), gomock.Any()).Return(nil) 75 76 scheduler := mock.NewMockScheduler(controller) 77 scheduler.EXPECT().Cancel(gomock.Any(), mockBuild.ID).Return(nil) 78 79 c := new(chi.Context) 80 c.URLParams.Add("owner", "octocat") 81 c.URLParams.Add("name", "hello-world") //Added some input 82 c.URLParams.Add("number", "1") 83 84 s := New(builds, events, repos, scheduler, stages, status, steps, users, webhook) 85 err := s.Cancel(noContext, mockRepo, mockBuildCopy) 86 if err != nil { 87 t.Error(err) 88 } 89 } 90 91 var ( 92 mockRepo = &core.Repository{ 93 ID: 1, 94 Namespace: "octocat", 95 Name: "hello-world", 96 Slug: "octocat/hello-world", 97 Counter: 42, 98 Branch: "master", 99 } 100 101 mockBuild = &core.Build{ 102 ID: 1, 103 Number: 1, 104 RepoID: 1, 105 Status: core.StatusPending, 106 Event: core.EventPush, 107 Link: "https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", 108 Timestamp: 1299283200, 109 Message: "first commit", 110 Before: "553c2077f0edc3d5dc5d17262f6aa498e69d6f8e", 111 After: "7fd1a60b01f91b314f59955a4e4d4e80d8edf11d", 112 Ref: "refs/heads/master", 113 Source: "master", 114 Target: "master", 115 Author: "octocat", 116 AuthorName: "The Octocat", 117 AuthorEmail: "octocat@hello-world.com", 118 AuthorAvatar: "https://avatars3.githubusercontent.com/u/583231", 119 Sender: "octocat", 120 } 121 122 mockUser = &core.User{ 123 ID: 1, 124 Login: "octocat", 125 } 126 )