...

Source file src/github.com/google/go-github/v47/github/repos_codeowners_test.go

Documentation: github.com/google/go-github/v47/github

     1  // Copyright 2022 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"fmt"
    11  	"net/http"
    12  	"testing"
    13  
    14  	"github.com/google/go-cmp/cmp"
    15  )
    16  
    17  func TestRepositoriesService_GetCodeownersErrors(t *testing.T) {
    18  	client, mux, _, teardown := setup()
    19  	defer teardown()
    20  
    21  	mux.HandleFunc("/repos/o/r/codeowners/errors", func(w http.ResponseWriter, r *http.Request) {
    22  		testMethod(t, r, "GET")
    23  		testHeader(t, r, "Accept", mediaTypeV3)
    24  		fmt.Fprint(w, `{
    25  		  "errors": [
    26  			{
    27  			  "line": 1,
    28  			  "column": 1,
    29  			  "kind": "Invalid pattern",
    30  			  "source": "***/*.rb @monalisa",
    31  			  "suggestion": "Did you mean **/*.rb?",
    32  			  "message": "Invalid pattern on line 3: Did you mean **/*.rb?\n\n  ***/*.rb @monalisa\n  ^",
    33  			  "path": ".github/CODEOWNERS"
    34  			}
    35  		  ]
    36  		}
    37  	`)
    38  	})
    39  
    40  	ctx := context.Background()
    41  	codeownersErrors, _, err := client.Repositories.GetCodeownersErrors(ctx, "o", "r")
    42  	if err != nil {
    43  		t.Errorf("Repositories.GetCodeownersErrors returned error: %v", err)
    44  	}
    45  
    46  	want := &CodeownersErrors{
    47  		Errors: []*CodeownersError{
    48  			{
    49  				Line:       1,
    50  				Column:     1,
    51  				Kind:       "Invalid pattern",
    52  				Source:     "***/*.rb @monalisa",
    53  				Suggestion: String("Did you mean **/*.rb?"),
    54  				Message:    "Invalid pattern on line 3: Did you mean **/*.rb?\n\n  ***/*.rb @monalisa\n  ^",
    55  				Path:       ".github/CODEOWNERS",
    56  			},
    57  		},
    58  	}
    59  	if !cmp.Equal(codeownersErrors, want) {
    60  		t.Errorf("Repositories.GetCodeownersErrors returned %+v, want %+v", codeownersErrors, want)
    61  	}
    62  
    63  	const methodName = "GetCodeownersErrors"
    64  	testBadOptions(t, methodName, func() (err error) {
    65  		_, _, err = client.Repositories.GetCodeownersErrors(ctx, "\n", "\n")
    66  		return err
    67  	})
    68  
    69  	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
    70  		got, resp, err := client.Repositories.GetCodeownersErrors(ctx, "o", "r")
    71  		if got != nil {
    72  			t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
    73  		}
    74  		return resp, err
    75  	})
    76  }
    77  
    78  func TestCodeownersErrors_Marshal(t *testing.T) {
    79  	testJSONMarshal(t, &CodeownersErrors{}, "{}")
    80  
    81  	u := &CodeownersErrors{
    82  		Errors: []*CodeownersError{
    83  			{
    84  				Line:       1,
    85  				Column:     1,
    86  				Kind:       "Invalid pattern",
    87  				Source:     "***/*.rb @monalisa",
    88  				Suggestion: String("Did you mean **/*.rb?"),
    89  				Message:    "Invalid pattern on line 3: Did you mean **/*.rb?\n\n  ***/*.rb @monalisa\n  ^",
    90  				Path:       ".github/CODEOWNERS",
    91  			},
    92  		},
    93  	}
    94  
    95  	want := `{
    96  	  "errors": [
    97  		{
    98  		  "line": 1,
    99  		  "column": 1,
   100  		  "kind": "Invalid pattern",
   101  		  "source": "***/*.rb @monalisa",
   102  		  "suggestion": "Did you mean **/*.rb?",
   103  		  "message": "Invalid pattern on line 3: Did you mean **/*.rb?\n\n  ***/*.rb @monalisa\n  ^",
   104  		  "path": ".github/CODEOWNERS"
   105  		}
   106  	  ]
   107  	}
   108  `
   109  	testJSONMarshal(t, u, want)
   110  }
   111  

View as plain text