diff --git a/validate.go b/validate.go index 1a0f56a14..cb79ac838 100644 --- a/validate.go +++ b/validate.go @@ -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"` diff --git a/validate_test.go b/validate_test.go index ab4bfc350..20171e24f 100644 --- a/validate_test.go +++ b/validate_test.go @@ -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)) + } + }) + } +}