Skip to content

Commit

Permalink
Add missing params to ProjectLint
Browse files Browse the repository at this point in the history
  • Loading branch information
Robby Dyer committed Mar 22, 2024
1 parent 8f2dbc2 commit 42b5002
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 @@ -124,6 +124,8 @@ type ProjectLintOptions struct {
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"`
ContentRef *string `url:"content_ref" json:"content_ref,omitempty"`
DryRunRef *string `url:"dry_run_ref" json:"dry_run_ref,omitempty"`
}

// ProjectLint validates .gitlab-ci.yml content by project.
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 42b5002

Please sign in to comment.