Loading project_feature_flags.go +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ type ProjectFeatureFlag struct { // // GitLab API docs: https://docs.gitlab.com/api/feature_flags/ type ProjectFeatureFlagScope struct { ID int64 `json:"id"` ID int64 `json:"id,omitempty"` EnvironmentScope string `json:"environment_scope"` // Destroy removes the scope identified by ID when set to true. Used Loading project_feature_flags_test.go +62 −0 Original line number Diff line number Diff line Loading @@ -339,6 +339,68 @@ func TestUpdateProjectFeatureFlag_ScopeDestroy(t *testing.T) { assert.Equal(t, expected, actual) } func TestUpdateProjectFeatureFlag_ScopeCreate(t *testing.T) { t.Parallel() mux, client := setup(t) mux.HandleFunc("/api/v4/projects/1/feature_flags/testing", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPut) testBodyJSON(t, r, map[string]any{ "strategies": []any{ map[string]any{ "id": float64(36), "scopes": []any{ map[string]any{ "environment_scope": "staging", }, }, }, }, }) mustWriteHTTPResponse(t, w, "testdata/update_project_feature_flag_scope_create.json") }) opt := &UpdateProjectFeatureFlagOptions{ Strategies: &[]*FeatureFlagStrategyOptions{ { ID: Ptr(int64(36)), Scopes: &[]*ProjectFeatureFlagScope{ { EnvironmentScope: "staging", }, }, }, }, } actual, _, err := client.ProjectFeatureFlags.UpdateProjectFeatureFlag(1, "testing", opt) require.NoError(t, err) expected := &ProjectFeatureFlag{ Name: "awesome_feature", Active: true, Version: "new_version_flag", CreatedAt: Ptr(time.Date(2020, time.May, 13, 20, 10, 32, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 13, 20, 10, 32, 0, time.UTC)), Scopes: []*ProjectFeatureFlagScope{}, Strategies: []*ProjectFeatureFlagStrategy{ { ID: 36, Name: "default", Parameters: &ProjectFeatureFlagStrategyParameter{}, Scopes: []*ProjectFeatureFlagScope{ { ID: 41, EnvironmentScope: "staging", }, }, }, }, } assert.Equal(t, expected, actual) } func TestDeleteProjectFeatureFlag(t *testing.T) { t.Parallel() mux, client := setup(t) Loading testdata/update_project_feature_flag_scope_create.json 0 → 100644 +22 −0 Original line number Diff line number Diff line { "name": "awesome_feature", "description": null, "active": true, "version": "new_version_flag", "created_at": "2020-05-13T20:10:32Z", "updated_at": "2020-05-13T20:10:32Z", "scopes": [], "strategies": [ { "id": 36, "name": "default", "parameters": {}, "scopes": [ { "id": 41, "environment_scope": "staging" } ] } ] } Loading
project_feature_flags.go +1 −1 Original line number Diff line number Diff line Loading @@ -63,7 +63,7 @@ type ProjectFeatureFlag struct { // // GitLab API docs: https://docs.gitlab.com/api/feature_flags/ type ProjectFeatureFlagScope struct { ID int64 `json:"id"` ID int64 `json:"id,omitempty"` EnvironmentScope string `json:"environment_scope"` // Destroy removes the scope identified by ID when set to true. Used Loading
project_feature_flags_test.go +62 −0 Original line number Diff line number Diff line Loading @@ -339,6 +339,68 @@ func TestUpdateProjectFeatureFlag_ScopeDestroy(t *testing.T) { assert.Equal(t, expected, actual) } func TestUpdateProjectFeatureFlag_ScopeCreate(t *testing.T) { t.Parallel() mux, client := setup(t) mux.HandleFunc("/api/v4/projects/1/feature_flags/testing", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, http.MethodPut) testBodyJSON(t, r, map[string]any{ "strategies": []any{ map[string]any{ "id": float64(36), "scopes": []any{ map[string]any{ "environment_scope": "staging", }, }, }, }, }) mustWriteHTTPResponse(t, w, "testdata/update_project_feature_flag_scope_create.json") }) opt := &UpdateProjectFeatureFlagOptions{ Strategies: &[]*FeatureFlagStrategyOptions{ { ID: Ptr(int64(36)), Scopes: &[]*ProjectFeatureFlagScope{ { EnvironmentScope: "staging", }, }, }, }, } actual, _, err := client.ProjectFeatureFlags.UpdateProjectFeatureFlag(1, "testing", opt) require.NoError(t, err) expected := &ProjectFeatureFlag{ Name: "awesome_feature", Active: true, Version: "new_version_flag", CreatedAt: Ptr(time.Date(2020, time.May, 13, 20, 10, 32, 0, time.UTC)), UpdatedAt: Ptr(time.Date(2020, time.May, 13, 20, 10, 32, 0, time.UTC)), Scopes: []*ProjectFeatureFlagScope{}, Strategies: []*ProjectFeatureFlagStrategy{ { ID: 36, Name: "default", Parameters: &ProjectFeatureFlagStrategyParameter{}, Scopes: []*ProjectFeatureFlagScope{ { ID: 41, EnvironmentScope: "staging", }, }, }, }, } assert.Equal(t, expected, actual) } func TestDeleteProjectFeatureFlag(t *testing.T) { t.Parallel() mux, client := setup(t) Loading
testdata/update_project_feature_flag_scope_create.json 0 → 100644 +22 −0 Original line number Diff line number Diff line { "name": "awesome_feature", "description": null, "active": true, "version": "new_version_flag", "created_at": "2020-05-13T20:10:32Z", "updated_at": "2020-05-13T20:10:32Z", "scopes": [], "strategies": [ { "id": 36, "name": "default", "parameters": {}, "scopes": [ { "id": 41, "environment_scope": "staging" } ] } ] }