Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): avoid panic during import pipeline #6343

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}