(t *testing.T)
| 938 | } |
| 939 | |
| 940 | func TestRepositoriesService_GetBranch(t *testing.T) { |
| 941 | t.Parallel() |
| 942 | client, mux, _ := setup(t) |
| 943 | |
| 944 | tests := []struct { |
| 945 | branch string |
| 946 | urlPath string |
| 947 | }{ |
| 948 | {branch: "b", urlPath: "/repos/o/r/branches/b"}, |
| 949 | {branch: "feat/branch-50%", urlPath: "/repos/o/r/branches/feat%2fbranch-50%25"}, |
| 950 | } |
| 951 | |
| 952 | for _, test := range tests { |
| 953 | mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) { |
| 954 | testMethod(t, r, "GET") |
| 955 | fmt.Fprint(w, `{"name":"n", "commit":{"sha":"s","commit":{"message":"m"}}, "protected":true, "protection":{"required_status_checks":{"contexts":["c"]}}}`) |
| 956 | }) |
| 957 | |
| 958 | ctx := t.Context() |
| 959 | branch, _, err := client.Repositories.GetBranch(ctx, "o", "r", test.branch, 0) |
| 960 | if err != nil { |
| 961 | t.Errorf("Repositories.GetBranch returned error: %v", err) |
| 962 | } |
| 963 | |
| 964 | want := &Branch{ |
| 965 | Name: Ptr("n"), |
| 966 | Commit: &RepositoryCommit{ |
| 967 | SHA: Ptr("s"), |
| 968 | Commit: &Commit{ |
| 969 | Message: Ptr("m"), |
| 970 | }, |
| 971 | }, |
| 972 | Protected: Ptr(true), |
| 973 | Protection: &Protection{ |
| 974 | RequiredStatusChecks: &RequiredStatusChecks{ |
| 975 | Contexts: &[]string{"c"}, |
| 976 | }, |
| 977 | }, |
| 978 | } |
| 979 | |
| 980 | if !cmp.Equal(branch, want) { |
| 981 | t.Errorf("Repositories.GetBranch returned %+v, want %+v", branch, want) |
| 982 | } |
| 983 | |
| 984 | const methodName = "GetBranch" |
| 985 | testBadOptions(t, methodName, func() (err error) { |
| 986 | _, _, err = client.Repositories.GetBranch(ctx, "\n", "\n", "\n", 0) |
| 987 | return err |
| 988 | }) |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | func TestRepositoriesService_GetBranch_BadJSONResponse(t *testing.T) { |
| 993 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…