func TestBuild(t *testing.T) { c := new(mockConveyor) b := &Slack{ client: c, URLTemplate: template.Must(template.New("url").Parse("http://conveyor/logs/{{.ID}}")), } ctx := slash.WithParams(context.Background(), map[string]string{ "owner": "remind101", "repo": "acme-inc", "branch": "master", }) c.On("Build", conveyor.BuildRequest{ Repository: "remind101/acme-inc", Branch: "master", }).Return(&conveyor.Build{ ID: fakeUUID, }, nil) rec := &fakeResponder{responses: make(chan slash.Response, 2)} err := b.Build(ctx, rec, slash.Command{}) resp := <-rec.responses assert.Equal(t, "One moment...", resp.Text) assert.NoError(t, err) resp = <-rec.responses assert.Equal(t, "Building remind101/acme-inc@master: http://conveyor/logs/01234567-89ab-cdef-0123-456789abcdef", resp.Text) }
func TestEnable(t *testing.T) { hook := &github.Hook{} g := new(mockHooker) h := &Enable{ Hook: hook, hooker: g, } g.On("ListHooks", "remind101", "acme-inc").Return([]github.Hook{}, nil) g.On("CreateHook", "remind101", "acme-inc", hook).Return(nil) ctx := slash.WithParams(context.Background(), map[string]string{ "owner": "remind101", "repo": "acme-inc", }) resp, err := h.ServeCommand(ctx, nil, slash.Command{ Token: slackToken, Command: "/conveyor", Text: "setup remind101/acme-inc", }) assert.NoError(t, err) assert.Equal(t, "Added webhook to remind101/acme-inc", resp.Text) g.AssertExpectations(t) }
func TestBuild(t *testing.T) { q := new(mockBuildQueue) r := new(mockBranchResolver) b := &Build{ Queue: q, branchResolver: r, urlTmpl: template.Must(template.New("url").Parse("http://conveyor/logs/{{.ID}}")), } ctx := slash.WithParams(context.Background(), map[string]string{ "owner": "remind101", "repo": "acme-inc", "branch": "master", }) r.On("resolveBranch", "remind101", "acme-inc", "master").Return("sha", nil) q.On("Push", ctx, builder.BuildOptions{ ID: fakeUUID, Repository: "remind101/acme-inc", Sha: "sha", Branch: "master", }).Return(nil) rec := &fakeResponder{responses: make(chan slash.Response, 1)} resp, err := b.ServeCommand(ctx, rec, slash.Command{}) assert.Equal(t, "One moment...", resp.Text) assert.NoError(t, err) resp = <-rec.responses assert.Equal(t, "Building remind101/acme-inc@master: http://conveyor/logs/01234567-89ab-cdef-0123-456789abcdef", resp.Text) }
func TestEnable_Exists(t *testing.T) { hook := &github.Hook{ Name: github.String("web"), Config: map[string]interface{}{ "url": "http://www.google.com", }, } g := new(mockHooker) h := &Enable{ Hook: hook, hooker: g, } g.On("ListHooks", "remind101", "acme-inc").Return([]github.Hook{ { ID: github.Int(1), Name: github.String("web"), Config: map[string]interface{}{ "url": "http://www.google.com", }, }, }, nil) g.On("EditHook", "remind101", "acme-inc", 1, hook).Return(nil) ctx := slash.WithParams(context.Background(), map[string]string{ "owner": "remind101", "repo": "acme-inc", }) resp, err := h.ServeCommand(ctx, nil, slash.Command{ Token: slackToken, Command: "/conveyor", Text: "setup remind101/acme-inc", }) assert.NoError(t, err) assert.Equal(t, "Updated webhook on remind101/acme-inc", resp.Text) g.AssertExpectations(t) }