From ea794f9c18132ca957a42f79f43fd99cfb87c953 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Sat, 15 Jan 2022 12:38:15 +0100 Subject: [PATCH 1/3] Make pipeline deserialization more abstract --- go.mod | 8 +++++ go.sum | 56 ++++++++++++++++++++++++++++++ pipeline.go | 88 ++++++++++++++++++++++++++++++++++++------------ pipeline_test.go | 40 ++++++++++++++++++---- 4 files changed, 164 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index 7829019..3641441 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,15 @@ require github.com/gorilla/mux v1.8.0 require ( github.com/davecgh/go-spew v1.1.0 // indirect + github.com/google/go-cmp v0.5.6 // indirect + github.com/hexops/valast v1.4.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 // indirect github.com/stretchr/testify v1.7.0 // indirect + golang.org/x/mod v0.5.1 // indirect + golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 // indirect + golang.org/x/tools v0.1.8-0.20211102182255-bb4add04ddef // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + mvdan.cc/gofumpt v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index e2ff782..849fa9a 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,68 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.0/go.mod h1:NeW+ay9A/U67EYXNFA1nPE8e/tnQv/09mUdL/ijj8og= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/hexops/autogold v0.8.1/go.mod h1:97HLDXyG23akzAoRYJh/2OBs3kd80eHyKPvZw0S5ZBY= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/hexops/valast v1.4.1 h1:vlB+usah+MLacCyDDqACn2yhAoCDlpHYkpEKtej+RXE= +github.com/hexops/valast v1.4.1/go.mod h1:G+D6TExWuKs5he+hYlPMfYyhQ8w8qbc2vm4gDWwLdDg= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc= +github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI= +golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.8-0.20211102182255-bb4add04ddef h1:/DaKawnTFFxdq/mJT3pM+OkeJlq5gc3ZhkbGVYbqOCw= +golang.org/x/tools v0.1.8-0.20211102182255-bb4add04ddef/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +mvdan.cc/gofumpt v0.2.0 h1:AInyCTHfhp4bFrP2VYC5kR2wPwgWj7eGSb+7437zn7I= +mvdan.cc/gofumpt v0.2.0/go.mod h1:TiGmrf914DAuT6+hDIxOqoDb4QXIzAuEUSXqEf9hGKY= diff --git a/pipeline.go b/pipeline.go index 431aa8a..8bc386f 100644 --- a/pipeline.go +++ b/pipeline.go @@ -4,51 +4,97 @@ import ( "encoding/json" "fmt" "io/fs" + "log" "os" "path/filepath" ) -var Pipelines []Pipeline - -type PipelineType int -type PipelineStepType int +// Pipelines const ( Image PipelineType = iota Video ) -const ( - Resize PipelineStepType = iota - Compress - Encode -) +type PipelineType int + +type IPipeline interface { + GetName() string + GetType() PipelineType + GetSteps() []Step +} type Pipeline struct { - Name string - Type PipelineType - RemoveMetadata bool - Steps []Step + Name string `json:"name"` + Type PipelineType `json:"type"` + RemoveMetadata bool `json:"remove_metadata"` + Steps []Step `json:"steps"` +} + +func (p Pipeline) GetName() string { + return p.Name +} + +func (p Pipeline) GetType() PipelineType { + return p.Type +} + +func (p Pipeline) GetSteps() []Step { + return p.Steps +} + +type ImagePipeline struct { + Pipeline +} + +type VideoPipeline struct { + Pipeline +} + +// Steps + +type IStep interface { + Run() + GetName() string } type Step struct { Name string - Type PipelineStepType + Type int +} + +func (s Step) Run() {} + +func (s Step) GetName() string { + return s.Name +} + +type ResizeImageStep struct { + Step } -func DeserializePipelines(pipelines [][]byte) []Pipeline { - values := make([]Pipeline, len(pipelines)) +type CompressImageStep struct { + Step +} - for index, pipeline := range pipelines { +// Deserialization + +func DeserializePipelines(pipelines [][]byte) []IPipeline { + var values []IPipeline + + for _, pipeline := range pipelines { var deserializedObject Pipeline - json.Unmarshal(pipeline, &deserializedObject) - values[index] = deserializedObject + err := json.Unmarshal(pipeline, &deserializedObject) + if err != nil { + log.Fatalf("Could not deserialize pipelines config: %s", err) + } + values = append(values, deserializedObject) } return values } -func LoadPipelines() { +func LoadPipelines() []IPipeline { var files [][]byte path, _ := os.Getwd() @@ -67,5 +113,5 @@ func LoadPipelines() { panic(err) } - Pipelines = DeserializePipelines(files) + return DeserializePipelines(files) } diff --git a/pipeline_test.go b/pipeline_test.go index 59450d8..ef6bbfa 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -1,12 +1,11 @@ package main import ( - "testing" - "github.com/stretchr/testify/assert" + "testing" ) -const ValidPayload string = `{ +const ValidImagePayload string = `{ "name": "example pipeline", "type": 0, "removeMetadata": false, @@ -22,11 +21,38 @@ const ValidPayload string = `{ ] }` -func TestPipelineDeserialization(t *testing.T) { - t.Run("Pipelines deserialization is successful", func(t *testing.T) { - values := DeserializePipelines([][]byte{[]byte(ValidPayload)}) +func TestImagePipelineDeserialization(t *testing.T) { + t.Run("Image pipeline deserialization is successful", func(t *testing.T) { + values := DeserializePipelines([][]byte{[]byte(ValidImagePayload)}) + + assert.Equal(t, 1, len(values), "Output should contain one element") + assert.Equal(t, "example pipeline", values[0].GetName()) + assert.Equal(t, Image, values[0].GetType()) + }) +} + +const ValidVideoPayload string = `{ + "name": "example pipeline", + "type": 1, + "removeMetadata": false, + "steps": [ + { + "name": "resize image", + "type": 0 + }, + { + "name": "compress image", + "type": 1 + } + ] +}` + +func TestVideoPipelineDeserialization(t *testing.T) { + t.Run("Video pipelines deserialization is successful", func(t *testing.T) { + values := DeserializePipelines([][]byte{[]byte(ValidVideoPayload)}) assert.Equal(t, 1, len(values), "Output should contain one element") - assert.Equal(t, "example pipeline", values[0].Name) + assert.Equal(t, "example pipeline", values[0].GetName()) + assert.Equal(t, Video, values[0].GetType()) }) } From f2418104bcaced2f9a73804ffe5d3257c9eb7d67 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Sat, 15 Jan 2022 13:01:04 +0100 Subject: [PATCH 2/3] Add abstract pipeline steps --- pipeline.go | 48 +++++++++++++++++--- pipeline_test.go | 116 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 124 insertions(+), 40 deletions(-) diff --git a/pipeline.go b/pipeline.go index 8bc386f..55894ae 100644 --- a/pipeline.go +++ b/pipeline.go @@ -53,30 +53,66 @@ type VideoPipeline struct { // Steps -type IStep interface { - Run() - GetName() string -} +type StepType int + +const ( + TypeResizeImageStep StepType = iota + TypeCompressImageStep +) type Step struct { Name string - Type int + Type StepType +} + +func (s Step) Translate() IExecutableStep { + var step IExecutableStep + switch s.GetType() { + case TypeResizeImageStep: + step = ResizeImageStep{s} + case TypeCompressImageStep: + step = CompressImageStep{s} + } + + if step == nil { + panic("invalid step") + } + + return step } -func (s Step) Run() {} +func (s Step) GetType() StepType { + return s.Type +} func (s Step) GetName() string { return s.Name } +type IExecutableStep interface { + Execute() +} + +// Resize image + type ResizeImageStep struct { Step } +func (s ResizeImageStep) Execute() { + // TODO +} + +// Compress image + type CompressImageStep struct { Step } +func (s CompressImageStep) Execute() { + // TODO +} + // Deserialization func DeserializePipelines(pipelines [][]byte) []IPipeline { diff --git a/pipeline_test.go b/pipeline_test.go index ef6bbfa..83bb355 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -5,25 +5,25 @@ import ( "testing" ) -const ValidImagePayload string = `{ - "name": "example pipeline", - "type": 0, - "removeMetadata": false, - "steps": [ - { - "name": "resize image", - "type": 0 - }, - { - "name": "compress image", - "type": 1 - } - ] -}` - func TestImagePipelineDeserialization(t *testing.T) { + const Payload string = `{ + "name": "example pipeline", + "type": 0, + "removeMetadata": false, + "steps": [ + { + "name": "resize image", + "type": 0 + }, + { + "name": "compress image", + "type": 1 + } + ] + }` + t.Run("Image pipeline deserialization is successful", func(t *testing.T) { - values := DeserializePipelines([][]byte{[]byte(ValidImagePayload)}) + values := DeserializePipelines([][]byte{[]byte(Payload)}) assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, "example pipeline", values[0].GetName()) @@ -31,28 +31,76 @@ func TestImagePipelineDeserialization(t *testing.T) { }) } -const ValidVideoPayload string = `{ - "name": "example pipeline", - "type": 1, - "removeMetadata": false, - "steps": [ - { - "name": "resize image", - "type": 0 - }, - { - "name": "compress image", - "type": 1 - } - ] -}` - func TestVideoPipelineDeserialization(t *testing.T) { + const Payload string = `{ + "name": "example pipeline", + "type": 1, + "removeMetadata": false, + "steps": [ + { + "name": "resize image", + "type": 0 + }, + { + "name": "compress image", + "type": 1 + } + ] + }` + t.Run("Video pipelines deserialization is successful", func(t *testing.T) { - values := DeserializePipelines([][]byte{[]byte(ValidVideoPayload)}) + values := DeserializePipelines([][]byte{[]byte(Payload)}) assert.Equal(t, 1, len(values), "Output should contain one element") assert.Equal(t, "example pipeline", values[0].GetName()) assert.Equal(t, Video, values[0].GetType()) }) } + +func TestTranslateStep(t *testing.T) { + const Payload string = `{ + "name": "example pipeline", + "type": 1, + "removeMetadata": false, + "steps": [ + { + "name": "resize image", + "type": 0 + } + ] + }` + + t.Run("step type deserialization is successful", func(t *testing.T) { + values := DeserializePipelines([][]byte{[]byte(Payload)}) + pipeline := values[0] + steps := pipeline.GetSteps() + + assert.Equal(t, 1, len(steps), "Output steps should contain one element") + assert.Equal(t, "resize image", steps[0].GetName()) + assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) + }) +} + +func TestInvalidStepType(t *testing.T) { + const Payload string = `{ + "name": "example pipeline", + "type": 1, + "removeMetadata": false, + "steps": [ + { + "name": "resize image", + "type": 0 + } + ] + }` + + t.Run("Video pipelines deserialization is successful", func(t *testing.T) { + values := DeserializePipelines([][]byte{[]byte(Payload)}) + pipeline := values[0] + steps := pipeline.GetSteps() + + assert.Equal(t, 1, len(steps), "Output steps should contain one element") + assert.Equal(t, "resize image", steps[0].GetName()) + assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) + }) +} From 74800196c067061f3fc1ce5195efeefa58971bb0 Mon Sep 17 00:00:00 2001 From: Roman Zipp Date: Sat, 15 Jan 2022 13:12:39 +0100 Subject: [PATCH 3/3] Return error on invalid pipeline type --- pipeline.go | 7 ++++--- pipeline_test.go | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pipeline.go b/pipeline.go index 55894ae..0fd1ca3 100644 --- a/pipeline.go +++ b/pipeline.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "io/fs" "log" @@ -65,7 +66,7 @@ type Step struct { Type StepType } -func (s Step) Translate() IExecutableStep { +func (s Step) Translate() (IExecutableStep, error) { var step IExecutableStep switch s.GetType() { case TypeResizeImageStep: @@ -75,10 +76,10 @@ func (s Step) Translate() IExecutableStep { } if step == nil { - panic("invalid step") + return nil, errors.New("invalid type") } - return step + return step, nil } func (s Step) GetType() StepType { diff --git a/pipeline_test.go b/pipeline_test.go index 83bb355..38c16e6 100644 --- a/pipeline_test.go +++ b/pipeline_test.go @@ -78,6 +78,10 @@ func TestTranslateStep(t *testing.T) { assert.Equal(t, 1, len(steps), "Output steps should contain one element") assert.Equal(t, "resize image", steps[0].GetName()) assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) + + translated, err := steps[0].Translate() + assert.Equal(t, err, nil) + assert.IsType(t, ResizeImageStep{}, translated) }) } @@ -89,7 +93,7 @@ func TestInvalidStepType(t *testing.T) { "steps": [ { "name": "resize image", - "type": 0 + "type": 99999 } ] }` @@ -101,6 +105,10 @@ func TestInvalidStepType(t *testing.T) { assert.Equal(t, 1, len(steps), "Output steps should contain one element") assert.Equal(t, "resize image", steps[0].GetName()) - assert.Equal(t, TypeResizeImageStep, steps[0].GetType()) + assert.Equal(t, StepType(99999), steps[0].GetType()) + + translated, err := steps[0].Translate() + assert.EqualError(t, err, "invalid type") + assert.Nil(t, translated) }) }