Skip to content

Commit

Permalink
fix(api): default version is 1 for pipeline (#5036)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored Mar 3, 2020
1 parent 8355c7f commit 4077bb8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions engine/api/pipeline_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,33 @@ jobs:
assert.Equal(t, 400, rec.Code)
}

func Test_putPipelineImportJSONWithoutVersionHandler(t *testing.T) {
api, db, _, end := newTestAPI(t)
defer end()

u, pass := assets.InsertAdminUser(t, db)
proj := assets.InsertTestProject(t, db, api.Cache, sdk.RandomString(10), sdk.RandomString(10))
test.NotNil(t, proj)

//Prepare request
vars := map[string]string{
"permProjectKey": proj.Key,
"pipelineKey": "testest",
}
uri := api.Router.GetRoute("PUT", api.putImportPipelineHandler, vars)
test.NotEmpty(t, uri)
req := assets.NewAuthentifiedRequest(t, u, pass, "PUT", uri+"?format=json", nil)

bodyjson := `{"name":"testest","stages":["Stage 1"],"jobs":[{"job":"echo with default","stage":"Stage 1","steps":[{"script":["echo \"test\"","echo {{.limit | default \"\"}}"]}]}]}`
req.Body = ioutil.NopCloser(strings.NewReader(bodyjson))
req.Header.Set("Content-Type", "application/json")

//Do the request
rec := httptest.NewRecorder()
api.Router.Mux.ServeHTTP(rec, req)
assert.Equal(t, 200, rec.Code)
}

func Test_putPipelineImportDifferentStageHandler(t *testing.T) {
api, db, _, end := newTestAPI(t)
defer end()
Expand Down
2 changes: 1 addition & 1 deletion sdk/exportentities/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func ParsePipeline(format string, data []byte) (Pipeliner, error) {
return nil, sdk.NewError(sdk.ErrWrongRequest, err)
}

var version PipelineVersion
version := PipelineVersion1
if v, ok := rawPayload["version"]; ok {
switch v.(string) {
case PipelineVersion1:
Expand Down

0 comments on commit 4077bb8

Please sign in to comment.