Skip to content

Commit

Permalink
Complete the creational functions for spec builder
Browse files Browse the repository at this point in the history
  • Loading branch information
baskarap committed Aug 27, 2019
1 parent 21aa36c commit 8512126
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
23 changes: 22 additions & 1 deletion pkg/service/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type Spec struct {

type SpecBuilder interface {
WithScope(scope string) SpecBuilder
WithImageData(img []byte) SpecBuilder
WithParams(params map[string]string) SpecBuilder
WithFormats(formats []string) SpecBuilder
Build() Spec
}

Expand All @@ -28,9 +31,27 @@ func (sb *specBuilder) WithScope(scope string) SpecBuilder {
return sb
}

func (sb *specBuilder) WithImageData(img []byte) SpecBuilder {
sb.imageData = img
return sb
}

func (sb *specBuilder) WithParams(params map[string]string) SpecBuilder {
sb.params = params
return sb
}

func (sb *specBuilder) WithFormats(formats []string) SpecBuilder {
sb.formats = formats
return sb
}

func (sb *specBuilder) Build() Spec {
return Spec{
Scope: sb.scope,
Scope: sb.scope,
ImageData: sb.imageData,
Params: sb.params,
Formats: sb.formats,
}
}

Expand Down
16 changes: 15 additions & 1 deletion pkg/service/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ import (

func TestSpecBuilder_Build(t *testing.T) {
scope := "scope"
spec := NewSpecBuilder().WithScope(scope).Build()
img := []byte("imageData")
params := make(map[string]string)
params["foo"] = "bar"
formats := []string{"image/webp", "image/apng"}

spec := NewSpecBuilder().
WithScope(scope).
WithImageData(img).
WithParams(params).
WithFormats(formats).
Build()

assert.Equal(t, spec.Scope, scope)
assert.Equal(t, spec.ImageData, img)
assert.Equal(t, spec.Params, params)
assert.Equal(t, spec.Formats, formats)
}

0 comments on commit 8512126

Please sign in to comment.