@@ -223,3 +223,54 @@ func TestValidateProjectNamespace(t *testing.T) {
223223 })
224224 }
225225}
226+
227+ func TestValidateProjectLint (t * testing.T ) {
228+ testCases := []struct {
229+ description string
230+ request * ProjectLintOptions
231+ response string
232+ want * ProjectLintResult
233+ }{
234+ {
235+ description : "valid" ,
236+ request : & ProjectLintOptions {
237+ DryRun : Ptr (false ),
238+ IncludeJobs : Ptr (true ),
239+ ContentRef : Ptr ("foo" ),
240+ },
241+ response : `{
242+ "valid": true,
243+ "errors": [],
244+ "warnings": [],
245+ "merged_yaml": "---\n:build:\n :script:\n - echo build"
246+ }` ,
247+ want : & ProjectLintResult {
248+ Valid : true ,
249+ Warnings : []string {},
250+ Errors : []string {},
251+ MergedYaml : "---\n :build:\n :script:\n - echo build" ,
252+ },
253+ },
254+ }
255+
256+ for _ , tc := range testCases {
257+ t .Run (tc .description , func (t * testing.T ) {
258+ mux , client := setup (t )
259+
260+ mux .HandleFunc ("/api/v4/projects/1/ci/lint" , func (w http.ResponseWriter , r * http.Request ) {
261+ testMethod (t , r , http .MethodGet )
262+ fmt .Fprint (w , tc .response )
263+ })
264+
265+ got , _ , err := client .Validate .ProjectLint (1 , tc .request )
266+ if err != nil {
267+ t .Errorf ("Validate returned error: %v" , err )
268+ }
269+
270+ want := tc .want
271+ if ! reflect .DeepEqual (got , want ) {
272+ t .Errorf ("Validate returned \n got:\n %v\n want:\n %v" , Stringify (got ), Stringify (want ))
273+ }
274+ })
275+ }
276+ }
0 commit comments