Skip to content

Commit

Permalink
Rename Spec -> ProcessSpec, fix failing tests due to the renaming stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
baskarap committed Aug 27, 2019
1 parent bf98288 commit 93c8ea9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/handler/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *ImageHandlerTestSuite) TestImageHandlerWithQueryParameters() {
params["w"] = "100"
params["h"] = "100"
s.storage.On("Get", mock.Anything, "/image-valid").Return([]byte("validData"), http.StatusOK, nil)
s.manipulator.On("Process", mock.AnythingOfType("service.spec")).Return([]byte("processedData"), nil)
s.manipulator.On("Process", mock.AnythingOfType("service.processSpec")).Return([]byte("processedData"), nil)

ImageHandler(s.deps).ServeHTTP(rr, r)

Expand All @@ -80,7 +80,7 @@ func (s *ImageHandlerTestSuite) TestImageHandlerWithQueryParametersAndProcessing
params["w"] = "100"
params["h"] = "100"
s.storage.On("Get", mock.Anything, "/image-valid").Return([]byte("validData"), http.StatusOK, nil)
s.manipulator.On("Process", mock.AnythingOfType("service.spec")).Return([]byte(nil), errors.New("error"))
s.manipulator.On("Process", mock.AnythingOfType("service.processSpec")).Return([]byte(nil), errors.New("error"))

ImageHandler(s.deps).ServeHTTP(rr, r)

Expand Down
13 changes: 3 additions & 10 deletions pkg/router/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestNewRouter(t *testing.T) {
router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &mockManipulator{}})
router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &service.MockManipulator{}})
assert.NotNil(t, router)
}

Expand All @@ -21,7 +21,7 @@ func TestNewRouterInDebugMode(t *testing.T) {
v.Set("debug", "true")
config.Update()

router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &mockManipulator{}})
router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &service.MockManipulator{}})
assert.NotNil(t, router)
}

Expand All @@ -31,7 +31,7 @@ func TestNewRouterWithPathPrefix(t *testing.T) {
v.Set("source.pathPrefix", "/path/to/folder")
config.Update()

router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &mockManipulator{}})
router := NewRouter(&service.Dependencies{Storage: &mockStorage{}, Manipulator: &service.MockManipulator{}})
assert.NotNil(t, router)
}

Expand All @@ -41,10 +41,3 @@ type mockStorage struct {
func (m *mockStorage) Get(ctx context.Context, path string) storage.IResponse {
return storage.NewResponse([]byte(nil), http.StatusOK, nil)
}

type mockManipulator struct {
}

func (m *mockManipulator) Process(spec service.ProcessSpec) ([]byte, error) {
return nil, nil
}
6 changes: 3 additions & 3 deletions pkg/service/manipulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
// Manipulator interface sets the contract on the implementation for common processing support in darkroom
type Manipulator interface {
// Process takes ProcessSpec as an argument and returns []byte, error
Process(spec spec) ([]byte, error)
Process(spec processSpec) ([]byte, error)
}

type manipulator struct {
Expand All @@ -50,7 +50,7 @@ type manipulator struct {

// Process takes ProcessSpec as an argument and returns []byte, error
// This manipulator uses bild to do the actual image manipulations
func (m *manipulator) Process(spec spec) ([]byte, error) {
func (m *manipulator) Process(spec processSpec) ([]byte, error) {
params := spec.Params
var err error
t := time.Now()
Expand Down Expand Up @@ -155,7 +155,7 @@ func GetCropPoint(input string) processor.CropPoint {
}
}

func trackDuration(name string, start time.Time, spec spec) *metrics.UpdateOption {
func trackDuration(name string, start time.Time, spec processSpec) *metrics.UpdateOption {
ext := strings.Split(http.DetectContentType(spec.ImageData), "/")[1]
updateOption := metrics.UpdateOption{
Name: fmt.Sprintf("%s.%s.%s", name, metrics.GetImageSizeCluster(spec.ImageData), ext),
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type MockManipulator struct {
mock.Mock
}

func (m *MockManipulator) Process(spec spec) ([]byte, error) {
func (m *MockManipulator) Process(spec processSpec) ([]byte, error) {
args := m.Called(spec)
return args.Get(0).([]byte), args.Error(1)
}
14 changes: 7 additions & 7 deletions pkg/service/spec.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package service

type Spec interface {
type ProcessSpec interface {
// IsWebPSupported() will tell if WebP is supported based on the accepted formats
IsWebPSupported() bool
}

type spec struct {
type processSpec struct {
// Scope defines a scope for the image manipulation job, it can be used for logging/mertrics collection purposes
Scope string
// ImageData holds the actual image contents to processed
Expand All @@ -16,8 +16,8 @@ type spec struct {
formats []string
}

func (s *spec) IsWebPSupported() bool {
for _, f := range s.formats {
func (ps *processSpec) IsWebPSupported() bool {
for _, f := range ps.formats {
if f == "image/webp" {
return true
}
Expand All @@ -30,7 +30,7 @@ type SpecBuilder interface {
WithImageData(img []byte) SpecBuilder
WithParams(params map[string]string) SpecBuilder
WithFormats(formats []string) SpecBuilder
Build() spec
Build() processSpec
}

type specBuilder struct {
Expand Down Expand Up @@ -60,8 +60,8 @@ func (sb *specBuilder) WithFormats(formats []string) SpecBuilder {
return sb
}

func (sb *specBuilder) Build() spec {
return spec{
func (sb *specBuilder) Build() processSpec {
return processSpec{
Scope: sb.scope,
ImageData: sb.imageData,
Params: sb.params,
Expand Down

0 comments on commit 93c8ea9

Please sign in to comment.