Skip to content

Commit

Permalink
fix(sdk): avoid panic during import pipeline (#6343)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Oct 21, 2022
1 parent d8168ff commit 32272d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sdk/exportentities/pipeline.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exportentities

import (
"fmt"
"sort"

"github.com/ovh/cds/sdk"
Expand Down Expand Up @@ -68,7 +69,7 @@ type ServiceRequirement struct {
Value string `json:"value,omitempty" yaml:"value,omitempty"`
}

//NewPipelineV1 creates an exportable pipeline from a sdk.Pipeline
// NewPipelineV1 creates an exportable pipeline from a sdk.Pipeline
func NewPipelineV1(pip sdk.Pipeline) (p PipelineV1) {
p.Name = pip.Name
p.Description = pip.Description
Expand Down Expand Up @@ -276,7 +277,7 @@ func computeJob(name string, j Job) (*sdk.Job, error) {
return &job, nil
}

//Pipeline returns a sdk.Pipeline entity
// Pipeline returns a sdk.Pipeline entity
func (p PipelineV1) Pipeline() (pip *sdk.Pipeline, err error) {
pip = new(sdk.Pipeline)
pip.Name = p.Name
Expand Down Expand Up @@ -372,7 +373,8 @@ func ParsePipeline(format Format, data []byte) (Pipeliner, error) {

version := PipelineVersion1
if v, ok := rawPayload["version"]; ok {
switch v.(string) {
vString := fmt.Sprintf("%v", v)
switch vString {
case PipelineVersion1:
version = PipelineVersion1
default:
Expand Down
11 changes: 11 additions & 0 deletions sdk/exportentities/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exportentities_test

import (
"encoding/json"
"github.com/stretchr/testify/require"
"testing"

"github.com/ovh/cds/sdk/exportentities"
Expand Down Expand Up @@ -900,3 +901,13 @@ func TestExportAndImportPipelineV1_YAML(t *testing.T) {
}
}
}

func Test_ImportPipelineWithFloatVersion(t *testing.T) {
in := `version: 1.0
name: echo
jobs:
- job: New Job
`
_, err := exportentities.ParsePipeline(exportentities.FormatYAML, []byte(in))
require.Error(t, err)
}

0 comments on commit 32272d8

Please sign in to comment.