Browse Source

Use byte slice instead of string slice for DeserializePipelines

feature/add-pipeline-loading
Fabian Vowie 2 years ago
parent
commit
836d699400
No known key found for this signature in database GPG Key ID: C27317C33B27C410
  1. 24
      pipeline.go
  2. 2
      pipeline_test.go

24
pipeline.go

@ -1,6 +1,10 @@
package main
import "encoding/json"
import (
"encoding/json"
)
var Pipelines []Pipeline
type PipelineType int
type PipelineStepType int
@ -28,14 +32,28 @@ type Step struct {
Type PipelineStepType
}
func DeserializePipelines(pipelines []string) []Pipeline {
func DeserializePipelines(pipelines [][]byte) []Pipeline {
values := make([]Pipeline, len(pipelines))
for index, pipeline := range pipelines {
var deserializedObject Pipeline
json.Unmarshal([]byte(pipeline), &deserializedObject)
json.Unmarshal(pipeline, &deserializedObject)
values[index] = deserializedObject
}
return values
}
// func LoadPipelines() {
// var files []string
// err := filepath.Walk("./pipelines", func(path string, info fs.FileInfo, err error) error {
// data, err := os.ReadFile(path)
// return nil
// })
// if err != nil {
// panic(err)
// }
// }

2
pipeline_test.go

@ -24,7 +24,7 @@ const ValidPayload string = `{
func TestPipelineDeserialization(t *testing.T) {
t.Run("Pipelines deserialization is successful", func(t *testing.T) {
values := DeserializePipelines([]string{ValidPayload})
values := DeserializePipelines([][]byte{[]byte(ValidPayload)})
assert.Equal(t, 1, len(values), "Output should contain one element")
assert.Equal(t, "example pipeline", values[0].Name)

Loading…
Cancel
Save