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

Commit

Permalink
Add omitempty and test
Browse files Browse the repository at this point in the history
  • Loading branch information
RicePatrick committed Mar 8, 2023
1 parent ae46dbc commit 8f5194d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ func (s *ProjectsService) GetProjectEvents(pid interface{}, opt *GetProjectEvent
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#create-project
type CreateProjectOptions struct {
AllowMergeOnSkippedPipeline *bool `url:"allow_merge_on_skipped_pipeline,omitempty" json:"allow_merge_on_skipped_pipeline,omitempty"`
OnlyAllowMergeIfAllStatusChecksPassed *bool `url:"only_allow_merge_if_all_status_checks_passed" json:"only_allow_merge_if_all_status_checks_passed"`
OnlyAllowMergeIfAllStatusChecksPassed *bool `url:"only_allow_merge_if_all_status_checks_passed,omitempty" json:"only_allow_merge_if_all_status_checks_passed,omitempty"`
AnalyticsAccessLevel *AccessControlValue `url:"analytics_access_level,omitempty" json:"analytics_access_level,omitempty"`
ApprovalsBeforeMerge *int `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"`
AutoCancelPendingPipelines *string `url:"auto_cancel_pending_pipelines,omitempty" json:"auto_cancel_pending_pipelines,omitempty"`
Expand Down Expand Up @@ -853,7 +853,7 @@ func (s *ProjectsService) CreateProjectForUser(user int, opt *CreateProjectForUs
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#edit-project
type EditProjectOptions struct {
AllowMergeOnSkippedPipeline *bool `url:"allow_merge_on_skipped_pipeline,omitempty" json:"allow_merge_on_skipped_pipeline,omitempty"`
OnlyAllowMergeIfAllStatusChecksPassed *bool `url:"only_allow_merge_if_all_status_checks_passed" json:"only_allow_merge_if_all_status_checks_passed"`
OnlyAllowMergeIfAllStatusChecksPassed *bool `url:"only_allow_merge_if_all_status_checks_passed,omitempty" json:"only_allow_merge_if_all_status_checks_passed,omitempty"`
AnalyticsAccessLevel *AccessControlValue `url:"analytics_access_level,omitempty" json:"analytics_access_level,omitempty"`
ApprovalsBeforeMerge *int `url:"approvals_before_merge,omitempty" json:"approvals_before_merge,omitempty"`
AutoCancelPendingPipelines *string `url:"auto_cancel_pending_pipelines,omitempty" json:"auto_cancel_pending_pipelines,omitempty"`
Expand Down
25 changes: 25 additions & 0 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package gitlab

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"reflect"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestListProjects(t *testing.T) {
Expand Down Expand Up @@ -1361,3 +1364,25 @@ func TestCreateProjectApprovalRuleEligibleApprovers(t *testing.T) {
t.Errorf("Projects.CreateProjectApprovalRule returned %+v, want %+v", rule, want)
}
}

func TestProjectModelsOptionalMergeAttribute(t *testing.T) {

// Create a `CreateProjectOptions` struct, ensure that merge attribute doesn't serialize
jsonString, err := json.Marshal(&CreateProjectOptions{
Name: String("testProject"),
})
if err != nil {
t.Fatal("Failed to marshal object", err)
}
assert.False(t, strings.Contains(string(jsonString), "only_allow_merge_if_all_status_checks_passed"))

// Test the same thing but for `EditProjectOptions` struct
jsonString, err = json.Marshal(&EditProjectOptions{
Name: String("testProject"),
})
if err != nil {
t.Fatal("Failed to marshal object", err)
}
assert.False(t, strings.Contains(string(jsonString), "only_allow_merge_if_all_status_checks_passed"))

}

0 comments on commit 8f5194d

Please sign in to comment.