MCPcopy Index your code
hub / github.com/google/go-github / TestRepositoriesService_GetBranch

Function TestRepositoriesService_GetBranch

github/repos_test.go:940–990  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

938}
939
940func 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
992func TestRepositoriesService_GetBranch_BadJSONResponse(t *testing.T) {
993 t.Parallel()

Callers

nothing calls this directly

Calls 6

testMethodFunction · 0.85
testBadOptionsFunction · 0.85
EqualMethod · 0.80
setupFunction · 0.70
PtrFunction · 0.70
GetBranchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…