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

Function TestRepositoriesService_ListRulesForBranch

github/repos_rules_test.go:17–65  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestRepositoriesService_ListRulesForBranch(t *testing.T) {
18 t.Parallel()
19 client, mux, _ := setup(t)
20
21 mux.HandleFunc("/repos/o/repo/rules/branches/branch", func(w http.ResponseWriter, r *http.Request) {
22 testMethod(t, r, "GET")
23 fmt.Fprint(w, `[
24 {
25 "ruleset_id": 42069,
26 "ruleset_source_type": "Repository",
27 "ruleset_source": "google/a",
28 "type": "creation"
29 },
30 {
31 "ruleset_id": 42069,
32 "ruleset_source_type": "Organization",
33 "ruleset_source": "google",
34 "type": "update",
35 "parameters": {
36 "update_allows_fetch_and_merge": true
37 }
38 }
39 ]`)
40 })
41
42 ctx := t.Context()
43 rules, _, err := client.Repositories.ListRulesForBranch(ctx, "o", "repo", "branch", nil)
44 if err != nil {
45 t.Errorf("Repositories.ListRulesForBranch returned error: %v", err)
46 }
47
48 want := &BranchRules{
49 Creation: []*BranchRuleMetadata{{RulesetSourceType: RulesetSourceTypeRepository, RulesetSource: "google/a", RulesetID: 42069}},
50 Update: []*UpdateBranchRule{{BranchRuleMetadata: BranchRuleMetadata{RulesetSourceType: RulesetSourceTypeOrganization, RulesetSource: "google", RulesetID: 42069}, Parameters: UpdateRuleParameters{UpdateAllowsFetchAndMerge: true}}},
51 }
52
53 if !cmp.Equal(rules, want) {
54 t.Errorf("Repositories.ListRulesForBranch returned %+v, want %+v", rules, want)
55 }
56
57 const methodName = "ListRulesForBranch"
58 testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
59 got, resp, err := client.Repositories.ListRulesForBranch(ctx, "o", "repo", "branch", nil)
60 if got != nil {
61 t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
62 }
63 return resp, err
64 })
65}
66
67func TestRepositoriesService_ListRulesForBranchIter(t *testing.T) {
68 t.Parallel()

Callers

nothing calls this directly

Calls 5

testMethodFunction · 0.85
ListRulesForBranchMethod · 0.80
EqualMethod · 0.80
setupFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…