diff --git a/engine/api/pipeline_import_test.go b/engine/api/pipeline_import_test.go index 03edfe85a1..2a6e6866cd 100644 --- a/engine/api/pipeline_import_test.go +++ b/engine/api/pipeline_import_test.go @@ -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() diff --git a/sdk/exportentities/pipeline.go b/sdk/exportentities/pipeline.go index b89a2b8d3c..72bd7dba83 100644 --- a/sdk/exportentities/pipeline.go +++ b/sdk/exportentities/pipeline.go @@ -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: