fix compiler unit tests, hook up daemon
This commit is contained in:
@@ -4,7 +4,11 @@
|
||||
|
||||
package image
|
||||
|
||||
import "github.com/docker/distribution/reference"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
)
|
||||
|
||||
// Trim returns the short image name without tag.
|
||||
func Trim(name string) string {
|
||||
@@ -69,3 +73,9 @@ func MatchHostname(image, hostname string) bool {
|
||||
}
|
||||
return reference.Domain(named) == hostname
|
||||
}
|
||||
|
||||
// IsLatest parses the image and returns true if
|
||||
// the image uses the :latest tag.
|
||||
func IsLatest(s string) bool {
|
||||
return strings.HasSuffix(Expand(s), ":latest")
|
||||
}
|
||||
|
||||
@@ -297,3 +297,41 @@ func Test_matchTag(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Test_isLatest(t *testing.T) {
|
||||
testdata := []struct {
|
||||
name string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "golang:1",
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "golang",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "golang:latest",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "docker.io/library/golang",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "docker.io/library/golang:latest",
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "docker.io/library/golang:1",
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, test := range testdata {
|
||||
got, want := IsLatest(test.name), test.want
|
||||
if got != want {
|
||||
t.Errorf("Want image %q isLatest %v", test.name, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
79
internal/mock/mock_engine_gen.go
Normal file
79
internal/mock/mock_engine_gen.go
Normal file
@@ -0,0 +1,79 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/drone-runners/drone-runner-docker/engine (interfaces: Engine)
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
engine "github.com/drone-runners/drone-runner-docker/engine"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
io "io"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockEngine is a mock of Engine interface
|
||||
type MockEngine struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockEngineMockRecorder
|
||||
}
|
||||
|
||||
// MockEngineMockRecorder is the mock recorder for MockEngine
|
||||
type MockEngineMockRecorder struct {
|
||||
mock *MockEngine
|
||||
}
|
||||
|
||||
// NewMockEngine creates a new mock instance
|
||||
func NewMockEngine(ctrl *gomock.Controller) *MockEngine {
|
||||
mock := &MockEngine{ctrl: ctrl}
|
||||
mock.recorder = &MockEngineMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockEngine) EXPECT() *MockEngineMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Destroy mocks base method
|
||||
func (m *MockEngine) Destroy(arg0 context.Context, arg1 *engine.Spec) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Destroy", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Destroy indicates an expected call of Destroy
|
||||
func (mr *MockEngineMockRecorder) Destroy(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Destroy", reflect.TypeOf((*MockEngine)(nil).Destroy), arg0, arg1)
|
||||
}
|
||||
|
||||
// Run mocks base method
|
||||
func (m *MockEngine) Run(arg0 context.Context, arg1 *engine.Spec, arg2 *engine.Step, arg3 io.Writer) (*engine.State, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Run", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].(*engine.State)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// Run indicates an expected call of Run
|
||||
func (mr *MockEngineMockRecorder) Run(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Run", reflect.TypeOf((*MockEngine)(nil).Run), arg0, arg1, arg2, arg3)
|
||||
}
|
||||
|
||||
// Setup mocks base method
|
||||
func (m *MockEngine) Setup(arg0 context.Context, arg1 *engine.Spec) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Setup", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Setup indicates an expected call of Setup
|
||||
func (mr *MockEngineMockRecorder) Setup(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Setup", reflect.TypeOf((*MockEngine)(nil).Setup), arg0, arg1)
|
||||
}
|
||||
50
internal/mock/mock_execer_gen.go
Normal file
50
internal/mock/mock_execer_gen.go
Normal file
@@ -0,0 +1,50 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/drone-runners/drone-runner-docker/runtime (interfaces: Execer)
|
||||
|
||||
// Package mock is a generated GoMock package.
|
||||
package mock
|
||||
|
||||
import (
|
||||
context "context"
|
||||
engine "github.com/drone-runners/drone-runner-docker/engine"
|
||||
pipeline "github.com/drone/runner-go/pipeline"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
reflect "reflect"
|
||||
)
|
||||
|
||||
// MockExecer is a mock of Execer interface
|
||||
type MockExecer struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockExecerMockRecorder
|
||||
}
|
||||
|
||||
// MockExecerMockRecorder is the mock recorder for MockExecer
|
||||
type MockExecerMockRecorder struct {
|
||||
mock *MockExecer
|
||||
}
|
||||
|
||||
// NewMockExecer creates a new mock instance
|
||||
func NewMockExecer(ctrl *gomock.Controller) *MockExecer {
|
||||
mock := &MockExecer{ctrl: ctrl}
|
||||
mock.recorder = &MockExecerMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use
|
||||
func (m *MockExecer) EXPECT() *MockExecerMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Exec mocks base method
|
||||
func (m *MockExecer) Exec(arg0 context.Context, arg1 *engine.Spec, arg2 *pipeline.State) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Exec", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Exec indicates an expected call of Exec
|
||||
func (mr *MockExecerMockRecorder) Exec(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Exec", reflect.TypeOf((*MockExecer)(nil).Exec), arg0, arg1, arg2)
|
||||
}
|
||||
Reference in New Issue
Block a user