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 #1903 from robbydyer/lint_updates
Browse files Browse the repository at this point in the history
Add missing params to ProjectLint
  • Loading branch information
svanharmelen authored Mar 23, 2024
2 parents 15491a8 + 7be424f commit f7ec87b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ func (s *ValidateService) ProjectNamespaceLint(pid interface{}, opt *ProjectName
// GitLab API docs:
// https://docs.gitlab.com/ee/api/lint.html#validate-a-projects-ci-configuration
type ProjectLintOptions struct {
ContentRef *string `url:"content_ref,omitempty" json:"content_ref,omitempty"`
DryRunRef *string `url:"dry_run_ref,omitempty" json:"dry_run_ref,omitempty"`
DryRun *bool `url:"dry_run,omitempty" json:"dry_run,omitempty"`
IncludeJobs *bool `url:"include_jobs,omitempty" json:"include_jobs,omitempty"`
Ref *string `url:"ref,omitempty" json:"ref,omitempty"`
Expand Down
51 changes: 51 additions & 0 deletions validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,54 @@ func TestValidateProjectNamespace(t *testing.T) {
})
}
}

func TestValidateProjectLint(t *testing.T) {
testCases := []struct {
description string
request *ProjectLintOptions
response string
want *ProjectLintResult
}{
{
description: "valid",
request: &ProjectLintOptions{
DryRun: Ptr(false),
IncludeJobs: Ptr(true),
ContentRef: Ptr("foo"),
},
response: `{
"valid": true,
"errors": [],
"warnings": [],
"merged_yaml": "---\n:build:\n :script:\n - echo build"
}`,
want: &ProjectLintResult{
Valid: true,
Warnings: []string{},
Errors: []string{},
MergedYaml: "---\n:build:\n :script:\n - echo build",
},
},
}

for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/ci/lint", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, tc.response)
})

got, _, err := client.Validate.ProjectLint(1, tc.request)
if err != nil {
t.Errorf("Validate returned error: %v", err)
}

want := tc.want
if !reflect.DeepEqual(got, want) {
t.Errorf("Validate returned \ngot:\n%v\nwant:\n%v", Stringify(got), Stringify(want))
}
})
}
}

0 comments on commit f7ec87b

Please sign in to comment.