minor restructuring

This commit is contained in:
Brad Rydzewski 2015-04-30 21:20:59 -07:00
parent 7ead6c82dd
commit acc6bb76ee
3 changed files with 37 additions and 11 deletions

View file

@ -1,14 +1,20 @@
package mocks package mocks
import "github.com/stretchr/testify/mock" import (
"io"
import "io" "github.com/drone/drone/common"
import "github.com/drone/drone/common" "github.com/stretchr/testify/mock"
)
type Datastore struct { type Datastore struct {
mock.Mock mock.Mock
} }
func New() *Datastore {
return new(Datastore)
}
func (m *Datastore) User(_a0 string) (*common.User, error) { func (m *Datastore) User(_a0 string) (*common.User, error) {
ret := m.Called(_a0) ret := m.Called(_a0)
@ -230,6 +236,17 @@ func (m *Datastore) BuildLast(_a0 string) (*common.Build, error) {
return r0, r1 return r0, r1
} }
func (m *Datastore) BuildAgent(_a0 string, _a1 int) (*common.Agent, error) {
ret := m.Called(_a0, _a1)
var r0 *common.Agent
if ret.Get(0) != nil {
r0 = ret.Get(0).(*common.Agent)
}
r1 := ret.Error(1)
return r0, r1
}
func (m *Datastore) SetBuild(_a0 string, _a1 *common.Build) error { func (m *Datastore) SetBuild(_a0 string, _a1 *common.Build) error {
ret := m.Called(_a0, _a1) ret := m.Called(_a0, _a1)
@ -302,3 +319,11 @@ func (m *Datastore) SetBuildTask(_a0 string, _a1 int, _a2 *common.Task) error {
return r0 return r0
} }
func (m *Datastore) SetBuildAgent(_a0 string, _a1 int, _a2 *common.Agent) error {
return m.Called(_a0, _a1, _a2).Error(0)
}
func (m *Datastore) DelBuildAgent(_a0 string, _a1 int) error {
return m.Called(_a0, _a1).Error(0)
}

View file

@ -11,7 +11,8 @@ import (
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/common/ccmenu" "github.com/drone/drone/common/ccmenu"
"github.com/drone/drone/datastore" "github.com/drone/drone/datastore"
"github.com/drone/drone/mocks" "github.com/drone/drone/datastore/mock"
"github.com/drone/drone/server/recorder"
. "github.com/franela/goblin" . "github.com/franela/goblin"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -34,9 +35,9 @@ func TestBadge(t *testing.T) {
g.AfterEach(func() { g.AfterEach(func() {
}) })
cycleStateTester := func(expector gin.HandlerFunc, handle gin.HandlerFunc, validator func(state string, w *ResponseRecorder)) { cycleStateTester := func(expector gin.HandlerFunc, handle gin.HandlerFunc, validator func(state string, w *recorder.ResponseRecorder)) {
for idx, state := range []string{"", common.StateError, common.StateFailure, common.StateKilled, common.StatePending, common.StateRunning, common.StateSuccess} { for idx, state := range []string{"", common.StateError, common.StateFailure, common.StateKilled, common.StatePending, common.StateRunning, common.StateSuccess} {
w := NewResponseRecorder() w := recorder.NewResponseRecorder()
ctx.Writer = w ctx.Writer = w
repo.Last = &common.Build{ repo.Last = &common.Build{
@ -60,7 +61,7 @@ func TestBadge(t *testing.T) {
g.It("should provide SVG response", func() { g.It("should provide SVG response", func() {
{ {
// 1. verify no "last" build // 1. verify no "last" build
w := NewResponseRecorder() w := recorder.NewResponseRecorder()
ctx.Writer = w ctx.Writer = w
ctx.Request.URL.Path += "/status.svg" ctx.Request.URL.Path += "/status.svg"
@ -72,7 +73,7 @@ func TestBadge(t *testing.T) {
} }
// 2. verify a variety of "last" build states // 2. verify a variety of "last" build states
cycleStateTester(nil, GetBadge, func(state string, w *ResponseRecorder) { cycleStateTester(nil, GetBadge, func(state string, w *recorder.ResponseRecorder) {
g.Assert(w.Status()).Equal(200) g.Assert(w.Status()).Equal(200)
g.Assert(w.HeaderMap.Get("content-type")).Equal("image/svg+xml") g.Assert(w.HeaderMap.Get("content-type")).Equal("image/svg+xml")
@ -95,7 +96,7 @@ func TestBadge(t *testing.T) {
g.It("should provide CCTray response", func() { g.It("should provide CCTray response", func() {
{ {
// 1. verify no "last" build // 1. verify no "last" build
w := NewResponseRecorder() w := recorder.NewResponseRecorder()
ctx.Writer = w ctx.Writer = w
ctx.Request.URL.Path += "/cc.xml" ctx.Request.URL.Path += "/cc.xml"
@ -116,7 +117,7 @@ func TestBadge(t *testing.T) {
ds.On("BuildLast", fullName).Return(repo.Last, nil).Once() ds.On("BuildLast", fullName).Return(repo.Last, nil).Once()
}, },
GetCC, GetCC,
func(state string, w *ResponseRecorder) { func(state string, w *recorder.ResponseRecorder) {
g.Assert(w.Status()).Equal(200) g.Assert(w.Status()).Equal(200)
v := ccmenu.CCProjects{} v := ccmenu.CCProjects{}

View file

@ -1,4 +1,4 @@
package server package recorder
import ( import (
"bufio" "bufio"