From 449ef4d25cf4a3d646dca8ef08109523766ab8ba Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Tue, 3 Mar 2020 17:30:15 +0100 Subject: [PATCH] feat(cdsctl): manage workflow label (#5028) * feat(cdsctl): manage workflow label close #5023 Signed-off-by: Yvonnick Esnault --- cli/cdsctl/admin_services.go | 5 +- cli/cdsctl/workflow.go | 1 + cli/cdsctl/workflow_label.go | 84 ++++++++++++++++ engine/api/project.go | 2 +- engine/api/workflow.go | 1 - go.mod | 16 +--- go.sum | 2 + sdk/cdsclient/client_workflow.go | 19 ++++ sdk/cdsclient/interface.go | 11 +++ .../mock_cdsclient/interface_mock.go | 95 +++++++++++++++++-- sdk/workflow.go | 2 +- tests/04_sc_workflow_simple_serve.yml | 19 +++- 12 files changed, 225 insertions(+), 32 deletions(-) create mode 100644 cli/cdsctl/workflow_label.go diff --git a/cli/cdsctl/admin_services.go b/cli/cdsctl/admin_services.go index ed1463b41b..425ff1f1bd 100644 --- a/cli/cdsctl/admin_services.go +++ b/cli/cdsctl/admin_services.go @@ -11,8 +11,9 @@ import ( ) var adminServicesCmd = cli.Command{ - Name: "services", - Short: "Manage CDS services", + Name: "services", + Aliases: []string{"service"}, + Short: "Manage CDS services", } func adminServices() *cobra.Command { diff --git a/cli/cdsctl/workflow.go b/cli/cdsctl/workflow.go index 4015cb3c5a..97689c2aa2 100644 --- a/cli/cdsctl/workflow.go +++ b/cli/cdsctl/workflow.go @@ -31,6 +31,7 @@ func workflow() *cobra.Command { cli.NewCommand(workflowPushCmd, workflowPushRun, nil, withAllCommandModifiers()...), cli.NewCommand(workflowFavoriteCmd, workflowFavoriteRun, nil, withAllCommandModifiers()...), cli.NewGetCommand(workflowTransformAsCodeCmd, workflowTransformAsCodeRun, nil, withAllCommandModifiers()...), + workflowLabel(), workflowArtifact(), workflowLog(), workflowAdvanced(), diff --git a/cli/cdsctl/workflow_label.go b/cli/cdsctl/workflow_label.go new file mode 100644 index 0000000000..c51e7af1dc --- /dev/null +++ b/cli/cdsctl/workflow_label.go @@ -0,0 +1,84 @@ +package main + +import ( + "github.com/spf13/cobra" + + "github.com/ovh/cds/cli" + "github.com/ovh/cds/sdk/cdsclient" +) + +var workflowLabelCmd = cli.Command{ + Name: "label", + Aliases: []string{"labels"}, + Short: "Manage Workflow Label", +} + +func workflowLabel() *cobra.Command { + return cli.NewCommand(workflowLabelCmd, nil, []*cobra.Command{ + cli.NewListCommand(workflowLabelListCmd, workflowLabelListRun, nil, withAllCommandModifiers()...), + cli.NewCommand(workflowLabelAddCmd, workflowLabelAddRun, nil, withAllCommandModifiers()...), + cli.NewCommand(workflowLabelDeleteCmd, workflowLabelDeleteRun, nil, withAllCommandModifiers()...), + }) +} + +var workflowLabelListCmd = cli.Command{ + Name: "list", + Short: "List labels of one workflow", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + {Name: _WorkflowName}, + }, +} + +func workflowLabelListRun(v cli.Values) (cli.ListResult, error) { + wf, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), cdsclient.WithLabels()) + if err != nil { + return nil, err + } + return cli.AsListResult(wf.Labels), nil +} + +var workflowLabelAddCmd = cli.Command{ + Name: "add", + Short: "Add label on one workflow", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + {Name: _WorkflowName}, + {Name: "label"}, + }, +} + +func workflowLabelAddRun(v cli.Values) error { + labelName := v.GetString("label") + err := client.WorkflowLabelAdd(v.GetString(_ProjectKey), v.GetString(_WorkflowName), labelName) + return err +} + +var workflowLabelDeleteCmd = cli.Command{ + Name: "delete", + Aliases: []string{"rm"}, + Short: "Delete label from one workflow", + Ctx: []cli.Arg{ + {Name: _ProjectKey}, + {Name: _WorkflowName}, + {Name: "label"}, + }, +} + +func workflowLabelDeleteRun(v cli.Values) error { + labelName := v.GetString("label") + wf, err := client.WorkflowGet(v.GetString(_ProjectKey), v.GetString(_WorkflowName), cdsclient.WithLabels()) + if err != nil { + return err + } + + var labelID int64 + for _, v := range wf.Labels { + if v.Name == labelName { + labelID = v.ID + break + } + } + + return client.WorkflowLabelDelete(v.GetString(_ProjectKey), v.GetString(_WorkflowName), labelID) +} diff --git a/engine/api/project.go b/engine/api/project.go index c5211367c6..ab2967b109 100644 --- a/engine/api/project.go +++ b/engine/api/project.go @@ -371,7 +371,7 @@ func (api *API) putProjectLabelsHandler() service.Handler { return err } - // Check is project exist + // Check if project exist proj, err := project.Load(db, api.Cache, key, project.LoadOptions.WithLabels) if err != nil { return err diff --git a/engine/api/workflow.go b/engine/api/workflow.go index 8a3914c882..da769524f2 100644 --- a/engine/api/workflow.go +++ b/engine/api/workflow.go @@ -249,7 +249,6 @@ func (api *API) postWorkflowLabelHandler() service.Handler { key := vars["key"] workflowName := vars["permWorkflowName"] db := api.mustDB() - //u := getAPIConsumer(ctx) var label sdk.Label if err := service.UnmarshalBody(r, &label); err != nil { diff --git a/go.mod b/go.mod index 84e84a9e37..d7e947f54c 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,6 @@ require ( github.com/circonus-labs/circonus-gometrics v2.2.4+incompatible // indirect github.com/circonus-labs/circonusllhist v0.0.0-20180430145027-5eb751da55c6 // indirect github.com/dancannon/gorethink v4.0.0+incompatible // indirect - github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dnaeon/go-vcr v0.0.0-20180920040454-5637cf3d8a31 // indirect github.com/docker/distribution v2.7.0-rc.0+incompatible // indirect @@ -62,7 +61,7 @@ require ( github.com/go-sql-driver/mysql v1.4.1 // indirect github.com/go-stomp/stomp v1.0.1 // indirect github.com/gocql/gocql v0.0.0-20181018123354-22229812a83e // indirect - github.com/golang/mock v1.4.0 + github.com/golang/mock v1.4.1 github.com/golang/protobuf v1.3.2 github.com/google/go-cmp v0.4.0 // indirect github.com/googleapis/gnostic v0.1.0 // indirect @@ -71,7 +70,6 @@ require ( github.com/gorhill/cronexpr v0.0.0-20161205141322-d520615e531a github.com/gorilla/handlers v0.0.0-20160816184729-a5775781a543 github.com/gorilla/mux v1.6.2 - github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect github.com/grpc-ecosystem/grpc-gateway v1.9.6 // indirect github.com/hashicorp/consul v1.3.0 // indirect @@ -95,14 +93,12 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/itsjamie/gin-cors v0.0.0-20160420130702-97b4a9da7933 github.com/jefferai/jsonx v0.0.0-20160721235117-9cc31c3135ee // indirect - github.com/jtolds/gls v4.2.1+incompatible // indirect github.com/juju/errors v0.0.0-20190207033735-e65537c515d7 // indirect github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8 // indirect github.com/juju/testing v0.0.0-20190429233213-dfc56b8c09fc // indirect github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect - github.com/keybase/go-crypto v0.0.0-20181127160227-255a5089e85a github.com/keybase/go-keychain v0.0.0-20190828020956-aa639f275ae1 github.com/keybase/go.dbus v0.0.0-20190710215703-a33a09c8a604 @@ -110,7 +106,6 @@ require ( github.com/kr/pty v1.1.8 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/lib/pq v1.0.0 - github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 github.com/magiconair/properties v1.8.1 // indirect github.com/mailru/easyjson v0.0.0-20171120080333-32fa128f234d @@ -134,23 +129,18 @@ require ( github.com/mndrix/tap-go v0.0.0-20170113192335-56cca451570b // indirect github.com/mum4k/termdash v0.10.0 github.com/nbutton23/zxcvbn-go v0.0.0-20180912185939-ae427f1e4c1d - github.com/ncw/swift v0.0.0-20171019114456-c95c6e5c2d1a github.com/nsf/termbox-go v0.0.0-20190817171036-93860e161317 // indirect github.com/nwaples/rardecode v1.0.0 // indirect github.com/olekukonko/tablewriter v0.0.0-20160621093029-daf2955e742c github.com/olivere/elastic v6.2.17+incompatible // indirect - github.com/opencontainers/go-digest v1.0.0-rc1 // indirect - github.com/opencontainers/image-spec v1.0.1 // indirect github.com/ory-am/common v0.4.0 // indirect github.com/ovh/cds/sdk/interpolate v0.0.0-20190319104452-71125b036b25 - github.com/ovh/cds/sdk/izanami v0.0.0-20190703081656-683453b50b2a github.com/ovh/configstore v0.3.2 github.com/ovh/symmecrypt v0.4.0 - github.com/ovh/venom v0.25.0 github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect github.com/patrickmn/go-cache v2.1.0+incompatible @@ -158,7 +148,6 @@ require ( github.com/pelletier/go-toml v1.4.0 github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pierrec/lz4 v2.3.0+incompatible // indirect - github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15 github.com/pkg/errors v0.8.1 github.com/poy/onpar v0.0.0-20190519213022-ee068f8ea4d1 // indirect @@ -194,7 +183,6 @@ require ( github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect github.com/yesnault/go-toml v0.0.0-20191205182532-f5ef6cee7945 github.com/yesnault/gorp v2.0.0+incompatible // indirect - github.com/yuin/gluare v0.0.0-20170607022532-d7c94f1a80ed github.com/yuin/gopher-lua v0.0.0-20170901023928-8c2befcd3908 github.com/ziutek/mymysql v1.5.4 // indirect @@ -214,11 +202,9 @@ require ( gopkg.in/go-playground/assert.v1 v1.2.1 // indirect gopkg.in/go-playground/validator.v8 v8.18.2 // indirect gopkg.in/gorethink/gorethink.v4 v4.1.0 // indirect - gopkg.in/gorp.v1 v1.7.1 // indirect gopkg.in/h2non/gock.v1 v1.0.14 gopkg.in/ldap.v2 v2.5.1 - gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect gopkg.in/olivere/elastic.v6 v6.2.17 gopkg.in/ory-am/dockertest.v2 v2.2.3 // indirect diff --git a/go.sum b/go.sum index 2ddaccee25..8b647805a0 100644 --- a/go.sum +++ b/go.sum @@ -189,6 +189,8 @@ github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/mock v1.4.0 h1:Rd1kQnQu0Hq3qvJppYSG0HtP+f5LPPUiDswTLiEegLg= github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= +github.com/golang/mock v1.4.1 h1:ocYkMQY5RrXTYgXl7ICpV0IXwlEQGwKIsery4gyXa1U= +github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= diff --git a/sdk/cdsclient/client_workflow.go b/sdk/cdsclient/client_workflow.go index dcc57599f6..cc0f8a1ca6 100644 --- a/sdk/cdsclient/client_workflow.go +++ b/sdk/cdsclient/client_workflow.go @@ -41,6 +41,25 @@ func (c *client) WorkflowUpdate(projectKey, name string, wf *sdk.Workflow) error return nil } +func (c *client) WorkflowLabelAdd(projectKey, name, labelName string) error { + lbl := sdk.Label{ + Name: labelName, + } + url := fmt.Sprintf("/project/%s/workflows/%s/label", projectKey, name) + if _, err := c.PostJSON(context.Background(), url, lbl, nil); err != nil { + return err + } + return nil +} + +func (c *client) WorkflowLabelDelete(projectKey, name string, labelID int64) error { + url := fmt.Sprintf("/project/%s/workflows/%s/label/%d", projectKey, name, labelID) + if _, err := c.DeleteJSON(context.Background(), url, nil); err != nil { + return err + } + return nil +} + func (c *client) WorkflowGroupAdd(projectKey, name, groupName string, permission int) error { gp := sdk.GroupPermission{ Group: sdk.Group{Name: groupName}, diff --git a/sdk/cdsclient/interface.go b/sdk/cdsclient/interface.go index 6922f430e2..71257199e6 100644 --- a/sdk/cdsclient/interface.go +++ b/sdk/cdsclient/interface.go @@ -294,6 +294,8 @@ type WorkflowClient interface { WorkflowGet(projectKey, name string, opts ...RequestModifier) (*sdk.Workflow, error) WorkflowUpdate(projectKey, name string, wf *sdk.Workflow) error WorkflowDelete(projectKey string, workflowName string) error + WorkflowLabelAdd(projectKey, name, labelName string) error + WorkflowLabelDelete(projectKey, name string, labelID int64) error WorkflowGroupAdd(projectKey, name, groupName string, permission int) error WorkflowGroupDelete(projectKey, name, groupName string) error WorkflowRunGet(projectKey string, workflowName string, number int64) (*sdk.WorkflowRun, error) @@ -467,6 +469,15 @@ func WithWorkflows() RequestModifier { } } +// WithLabels allow a provider to retrieve a workflow with its labels +func WithLabels() RequestModifier { + return func(r *http.Request) { + q := r.URL.Query() + q.Set("withLabels", "true") + r.URL.RawQuery = q.Encode() + } +} + // AuthClient is the interface for authentication management. type AuthClient interface { AuthDriverList() (sdk.AuthDriverResponse, error) diff --git a/sdk/cdsclient/mock_cdsclient/interface_mock.go b/sdk/cdsclient/mock_cdsclient/interface_mock.go index 372d602a46..e08c536995 100644 --- a/sdk/cdsclient/mock_cdsclient/interface_mock.go +++ b/sdk/cdsclient/mock_cdsclient/interface_mock.go @@ -7,16 +7,15 @@ package mock_cdsclient import ( tar "archive/tar" context "context" - io "io" - http "net/http" - reflect "reflect" - time "time" - gomock "github.com/golang/mock/gomock" sdk "github.com/ovh/cds/sdk" cdsclient "github.com/ovh/cds/sdk/cdsclient" venom "github.com/ovh/venom" coverage "github.com/sguiheux/go-coverage" + io "io" + http "net/http" + reflect "reflect" + time "time" ) // MockTemplateClient is a mock of TemplateClient interface @@ -2128,10 +2127,10 @@ func (m *MockPipelineClient) EXPECT() *MockPipelineClientMockRecorder { } // PipelineGet mocks base method -func (m *MockInterface) PipelineGet(projectKey, name string, opts ...cdsclient.RequestModifier) (*sdk.Pipeline, error) { +func (m *MockPipelineClient) PipelineGet(projectKey, name string, mods ...cdsclient.RequestModifier) (*sdk.Pipeline, error) { m.ctrl.T.Helper() varargs := []interface{}{projectKey, name} - for _, a := range opts { + for _, a := range mods { varargs = append(varargs, a) } ret := m.ctrl.Call(m, "PipelineGet", varargs...) @@ -2141,10 +2140,10 @@ func (m *MockInterface) PipelineGet(projectKey, name string, opts ...cdsclient.R } // PipelineGet indicates an expected call of PipelineGet -func (mr *MockInterfaceMockRecorder) PipelineGet(projectKey, name interface{}, opts ...interface{}) *gomock.Call { +func (mr *MockPipelineClientMockRecorder) PipelineGet(projectKey, name interface{}, mods ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]interface{}{projectKey, name}, opts...) - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineGet", reflect.TypeOf((*MockInterface)(nil).PipelineGet), varargs...) + varargs := append([]interface{}{projectKey, name}, mods...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineGet", reflect.TypeOf((*MockPipelineClient)(nil).PipelineGet), varargs...) } // PipelineDelete mocks base method @@ -3522,6 +3521,34 @@ func (mr *MockWorkflowClientMockRecorder) WorkflowDelete(projectKey, workflowNam return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowDelete", reflect.TypeOf((*MockWorkflowClient)(nil).WorkflowDelete), projectKey, workflowName) } +// WorkflowLabelAdd mocks base method +func (m *MockWorkflowClient) WorkflowLabelAdd(projectKey, name, labelName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WorkflowLabelAdd", projectKey, name, labelName) + ret0, _ := ret[0].(error) + return ret0 +} + +// WorkflowLabelAdd indicates an expected call of WorkflowLabelAdd +func (mr *MockWorkflowClientMockRecorder) WorkflowLabelAdd(projectKey, name, labelName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowLabelAdd", reflect.TypeOf((*MockWorkflowClient)(nil).WorkflowLabelAdd), projectKey, name, labelName) +} + +// WorkflowLabelDelete mocks base method +func (m *MockWorkflowClient) WorkflowLabelDelete(projectKey, name string, labelID int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WorkflowLabelDelete", projectKey, name, labelID) + ret0, _ := ret[0].(error) + return ret0 +} + +// WorkflowLabelDelete indicates an expected call of WorkflowLabelDelete +func (mr *MockWorkflowClientMockRecorder) WorkflowLabelDelete(projectKey, name, labelID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowLabelDelete", reflect.TypeOf((*MockWorkflowClient)(nil).WorkflowLabelDelete), projectKey, name, labelID) +} + // WorkflowGroupAdd mocks base method func (m *MockWorkflowClient) WorkflowGroupAdd(projectKey, name, groupName string, permission int) error { m.ctrl.T.Helper() @@ -5887,6 +5914,26 @@ func (mr *MockInterfaceMockRecorder) Maintenance(enable, hooks interface{}) *gom return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Maintenance", reflect.TypeOf((*MockInterface)(nil).Maintenance), enable, hooks) } +// PipelineGet mocks base method +func (m *MockInterface) PipelineGet(projectKey, name string, mods ...cdsclient.RequestModifier) (*sdk.Pipeline, error) { + m.ctrl.T.Helper() + varargs := []interface{}{projectKey, name} + for _, a := range mods { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "PipelineGet", varargs...) + ret0, _ := ret[0].(*sdk.Pipeline) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// PipelineGet indicates an expected call of PipelineGet +func (mr *MockInterfaceMockRecorder) PipelineGet(projectKey, name interface{}, mods ...interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + varargs := append([]interface{}{projectKey, name}, mods...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PipelineGet", reflect.TypeOf((*MockInterface)(nil).PipelineGet), varargs...) +} + // PipelineDelete mocks base method func (m *MockInterface) PipelineDelete(projectKey, name string) error { m.ctrl.T.Helper() @@ -7026,6 +7073,34 @@ func (mr *MockInterfaceMockRecorder) WorkflowDelete(projectKey, workflowName int return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowDelete", reflect.TypeOf((*MockInterface)(nil).WorkflowDelete), projectKey, workflowName) } +// WorkflowLabelAdd mocks base method +func (m *MockInterface) WorkflowLabelAdd(projectKey, name, labelName string) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WorkflowLabelAdd", projectKey, name, labelName) + ret0, _ := ret[0].(error) + return ret0 +} + +// WorkflowLabelAdd indicates an expected call of WorkflowLabelAdd +func (mr *MockInterfaceMockRecorder) WorkflowLabelAdd(projectKey, name, labelName interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowLabelAdd", reflect.TypeOf((*MockInterface)(nil).WorkflowLabelAdd), projectKey, name, labelName) +} + +// WorkflowLabelDelete mocks base method +func (m *MockInterface) WorkflowLabelDelete(projectKey, name string, labelID int64) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "WorkflowLabelDelete", projectKey, name, labelID) + ret0, _ := ret[0].(error) + return ret0 +} + +// WorkflowLabelDelete indicates an expected call of WorkflowLabelDelete +func (mr *MockInterfaceMockRecorder) WorkflowLabelDelete(projectKey, name, labelID interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WorkflowLabelDelete", reflect.TypeOf((*MockInterface)(nil).WorkflowLabelDelete), projectKey, name, labelID) +} + // WorkflowGroupAdd mocks base method func (m *MockInterface) WorkflowGroupAdd(projectKey, name, groupName string, permission int) error { m.ctrl.T.Helper() diff --git a/sdk/workflow.go b/sdk/workflow.go index 8c9495afe4..99a523f3e3 100644 --- a/sdk/workflow.go +++ b/sdk/workflow.go @@ -253,7 +253,7 @@ type WorkflowNodeJobRunCount struct { // Label represent a label linked to a workflow type Label struct { ID int64 `json:"id" db:"id"` - Name string `json:"name" db:"name"` + Name string `json:"name" db:"name" cli:"label,key"` Color string `json:"color" db:"color"` ProjectID int64 `json:"project_id" db:"project_id"` WorkflowID int64 `json:"workflow_id,omitempty" db:"-"` diff --git a/tests/04_sc_workflow_simple_serve.yml b/tests/04_sc_workflow_simple_serve.yml index d6541a2f2a..5c7b8eeb31 100644 --- a/tests/04_sc_workflow_simple_serve.yml +++ b/tests/04_sc_workflow_simple_serve.yml @@ -20,8 +20,6 @@ testcases: - name: push workflow steps: - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow push ITSCWRKFLW7 ./fixtures/ITSCWRKFLW7/*.yml --skip-update-files - assertions: - - result.code ShouldEqual 0 - name: export pipeline steps: @@ -31,3 +29,20 @@ testcases: - result.systemoutjson.jobs.jobs0.steps.steps1.servestaticfiles.path ShouldContainSubstring website - result.systemoutjson.jobs.jobs0.steps.steps1.servestaticfiles.entrypoint ShouldContainSubstring index.html - result.systemoutjson.jobs.jobs0.steps.steps1.servestaticfiles.path ShouldContainSubstring website + +- name: manage label + steps: + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow label list ITSCWRKFLW7 ITSCWRKFLW7-WORKFLOW + assertions: + - result.code ShouldEqual 0 + - result.systemout ShouldContainSubstring 'nothing to display...' + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow label add ITSCWRKFLW7 ITSCWRKFLW7-WORKFLOW myLabel + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow label list ITSCWRKFLW7 ITSCWRKFLW7-WORKFLOW --format json + assertions: + - result.code ShouldEqual 0 + - result.systemoutjson.systemoutjson0.label ShouldContainSubstring myLabel + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow label rm ITSCWRKFLW7 ITSCWRKFLW7-WORKFLOW myLabel + - script: {{.cdsctl}} -f {{.cdsctl.config}} workflow label list ITSCWRKFLW7 ITSCWRKFLW7-WORKFLOW + assertions: + - result.code ShouldEqual 0 + - result.systemout ShouldContainSubstring 'nothing to display...'