Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2064 from yogeshlonkar/main
Browse files Browse the repository at this point in the history
Add support for hidden field to group variables
  • Loading branch information
RicePatrick authored Dec 9, 2024
2 parents 5626c64 + 5146c24 commit 7f944b7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
2 changes: 2 additions & 0 deletions group_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type GroupVariable struct {
VariableType VariableTypeValue `json:"variable_type"`
Protected bool `json:"protected"`
Masked bool `json:"masked"`
Hidden bool `json:"hidden"`
Raw bool `json:"raw"`
EnvironmentScope string `json:"environment_scope"`
Description string `json:"description"`
Expand Down Expand Up @@ -127,6 +128,7 @@ type CreateGroupVariableOptions struct {
Description *string `url:"description,omitempty" json:"description,omitempty"`
EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
MaskedAndHidden *bool `url:"masked_and_hidden,omitempty" json:"hidden,omitempty"`
Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
Expand Down
72 changes: 61 additions & 11 deletions group_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestListGroupVariabless(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/variables",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `[{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true}]`)
fmt.Fprint(w, `[{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true,"hidden": true}]`)
})

variables, _, err := client.GroupVariables.ListVariables(1, &ListGroupVariablesOptions{})
Expand All @@ -43,6 +43,7 @@ func TestListGroupVariabless(t *testing.T) {
Value: "test1",
Protected: false,
Masked: true,
Hidden: true,
},
}

Expand All @@ -58,15 +59,15 @@ func TestGetGroupVariable(t *testing.T) {
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testParams(t, r, "filter%5Benvironment_scope%5D=prod")
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true}`)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true,"hidden": false}`)
})

variable, _, err := client.GroupVariables.GetVariable(1, "TEST_VARIABLE_1", &GetGroupVariableOptions{Filter: &VariableFilter{EnvironmentScope: "prod"}})
if err != nil {
t.Errorf("GroupVariables.GetVariable returned error: %v", err)
}

want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true}
want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true, Hidden: false}
if !reflect.DeepEqual(want, variable) {
t.Errorf("GroupVariables.GetVariable returned %+v, want %+v", variable, want)
}
Expand All @@ -78,22 +79,51 @@ func TestCreateGroupVariable(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/variables",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true}`)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value":"test1","protected": false,"masked": true,"hidden": false}`)
})

opt := &CreateGroupVariableOptions{
Key: Ptr("TEST_VARIABLE_1"),
Value: Ptr("test1"),
Protected: Ptr(false),
Masked: Ptr(true),
Key: Ptr("TEST_VARIABLE_1"),
Value: Ptr("test1"),
Protected: Ptr(false),
Masked: Ptr(true),
MaskedAndHidden: Ptr(false),
}

variable, _, err := client.GroupVariables.CreateVariable(1, opt, nil)
if err != nil {
t.Errorf("GroupVariables.CreateVariable returned error: %v", err)
}

want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true}
want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true, Hidden: false}
if !reflect.DeepEqual(want, variable) {
t.Errorf("GroupVariables.CreateVariable returned %+v, want %+v", variable, want)
}
}

func TestCreateGroupVariable_MaskedAndHidden(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/variables",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","protected": false,"masked": true,"hidden": true}`)
})

opt := &CreateGroupVariableOptions{
Key: Ptr("TEST_VARIABLE_1"),
Value: Ptr("test1"),
Protected: Ptr(false),
Masked: Ptr(true),
MaskedAndHidden: Ptr(true),
}

variable, _, err := client.GroupVariables.CreateVariable(1, opt, nil)
if err != nil {
t.Errorf("GroupVariables.CreateVariable returned error: %v", err)
}

want := &GroupVariable{Key: "TEST_VARIABLE_1", Protected: false, Masked: true, Hidden: true}
if !reflect.DeepEqual(want, variable) {
t.Errorf("GroupVariables.CreateVariable returned %+v, want %+v", variable, want)
}
Expand Down Expand Up @@ -126,15 +156,35 @@ func TestUpdateGroupVariable(t *testing.T) {
mux.HandleFunc("/api/v4/groups/1/variables/TEST_VARIABLE_1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true}`)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","value": "test1","protected": false,"masked": true,"hidden": false}`)
})

variable, _, err := client.GroupVariables.UpdateVariable(1, "TEST_VARIABLE_1", &UpdateGroupVariableOptions{})
if err != nil {
t.Errorf("GroupVariables.UpdateVariable returned error: %v", err)
}

want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true, Hidden: false}
if !reflect.DeepEqual(want, variable) {
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", variable, want)
}
}

func TestUpdateGroupVariable_MaskedAndHidden(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/groups/1/variables/TEST_VARIABLE_1",
func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{"key": "TEST_VARIABLE_1","protected": false,"masked": true,"hidden": true}`)
})

variable, _, err := client.GroupVariables.UpdateVariable(1, "TEST_VARIABLE_1", &UpdateGroupVariableOptions{})
if err != nil {
t.Errorf("GroupVariables.UpdateVariable returned error: %v", err)
}

want := &GroupVariable{Key: "TEST_VARIABLE_1", Value: "test1", Protected: false, Masked: true}
want := &GroupVariable{Key: "TEST_VARIABLE_1", Protected: false, Masked: true, Hidden: true}
if !reflect.DeepEqual(want, variable) {
t.Errorf("Groups.UpdatedGroup returned %+v, want %+v", variable, want)
}
Expand Down

0 comments on commit 7f944b7

Please sign in to comment.