|
| 1 | +// Copyright 2026 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 | + "fmt" |
| 10 | + "net/http" |
| 11 | + "testing" |
| 12 | + |
| 13 | + "github.com/google/go-cmp/cmp" |
| 14 | +) |
| 15 | + |
| 16 | +func TestCopilotService_GetCopilotCloudAgentConfiguration(t *testing.T) { |
| 17 | + t.Parallel() |
| 18 | + client, mux, _ := setup(t) |
| 19 | + |
| 20 | + mux.HandleFunc("/repos/o/r/copilot/cloud-agent/configuration", func(w http.ResponseWriter, r *http.Request) { |
| 21 | + testMethod(t, r, "GET") |
| 22 | + fmt.Fprint(w, `{ |
| 23 | + "mcp_configuration": null, |
| 24 | + "enabled_tools": { |
| 25 | + "codeql": true, |
| 26 | + "copilot_code_review": true, |
| 27 | + "secret_scanning": true, |
| 28 | + "dependency_vulnerability_checks": true |
| 29 | + }, |
| 30 | + "require_actions_workflow_approval": true, |
| 31 | + "is_firewall_enabled": true, |
| 32 | + "is_firewall_recommended_allowlist_enabled": true, |
| 33 | + "custom_allowlist": [] |
| 34 | + }`) |
| 35 | + }) |
| 36 | + |
| 37 | + ctx := t.Context() |
| 38 | + config, _, err := client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "o", "r") |
| 39 | + if err != nil { |
| 40 | + t.Errorf("GetCopilotCloudAgentConfiguration returned error: %v", err) |
| 41 | + } |
| 42 | + |
| 43 | + want := &CopilotCloudAgentConfiguration{ |
| 44 | + McpConfiguration: nil, |
| 45 | + EnabledTools: &EnabledTools{ |
| 46 | + Codeql: Ptr(true), |
| 47 | + CopilotCodeReview: Ptr(true), |
| 48 | + SecretScanning: Ptr(true), |
| 49 | + DependencyVulnerabilityChecks: Ptr(true), |
| 50 | + }, |
| 51 | + RequireActionsWorkflowApproval: Ptr(true), |
| 52 | + IsFirewallEnabled: Ptr(true), |
| 53 | + IsFirewallRecommendedAllowlistEnabled: Ptr(true), |
| 54 | + CustomAllowlist: []string{}, |
| 55 | + } |
| 56 | + |
| 57 | + if !cmp.Equal(config, want) { |
| 58 | + t.Errorf("GetCopilotCloudAgentConfiguration returned %+v, want %+v", config, want) |
| 59 | + } |
| 60 | + |
| 61 | + const methodName = "GetCopilotCloudAgentConfiguration" |
| 62 | + testBadOptions(t, methodName, func() (err error) { |
| 63 | + _, _, err = client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "\n", "\n") |
| 64 | + return err |
| 65 | + }) |
| 66 | + |
| 67 | + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { |
| 68 | + got, resp, err := client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "o", "r") |
| 69 | + if got != nil { |
| 70 | + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) |
| 71 | + } |
| 72 | + return resp, err |
| 73 | + }) |
| 74 | +} |
| 75 | + |
| 76 | +func TestCopilotService_GetCopilotCloudAgentConfiguration_InvalidOwner(t *testing.T) { |
| 77 | + t.Parallel() |
| 78 | + client, _, _ := setup(t) |
| 79 | + |
| 80 | + ctx := t.Context() |
| 81 | + _, _, err := client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "%", "r") |
| 82 | + testURLParseError(t, err) |
| 83 | +} |
| 84 | + |
| 85 | +func TestCopilotService_GetCopilotCloudAgentConfiguration_InvalidRepo(t *testing.T) { |
| 86 | + t.Parallel() |
| 87 | + client, _, _ := setup(t) |
| 88 | + |
| 89 | + ctx := t.Context() |
| 90 | + _, _, err := client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "o", "%") |
| 91 | + testURLParseError(t, err) |
| 92 | +} |
| 93 | + |
| 94 | +func TestCopilotService_GetCopilotCloudAgentConfiguration_NotFound(t *testing.T) { |
| 95 | + t.Parallel() |
| 96 | + client, mux, _ := setup(t) |
| 97 | + |
| 98 | + mux.HandleFunc("/repos/o/r/copilot/cloud-agent/configuration", func(w http.ResponseWriter, r *http.Request) { |
| 99 | + testMethod(t, r, "GET") |
| 100 | + w.WriteHeader(http.StatusNotFound) |
| 101 | + }) |
| 102 | + |
| 103 | + ctx := t.Context() |
| 104 | + config, resp, err := client.Copilot.GetCopilotCloudAgentConfiguration(ctx, "o", "r") |
| 105 | + if err == nil { |
| 106 | + t.Error("Expected HTTP 404 response") |
| 107 | + } |
| 108 | + if got, want := resp.Response.StatusCode, http.StatusNotFound; got != want { |
| 109 | + t.Errorf("GetCopilotCloudAgentConfiguration return status %v, want %v", got, want) |
| 110 | + } |
| 111 | + if config != nil { |
| 112 | + t.Errorf("GetCopilotCloudAgentConfiguration return %+v, want nil", config) |
| 113 | + } |
| 114 | +} |
| 115 | + |
| 116 | +func TestCopilotCloudAgentConfiguration_Marshal(t *testing.T) { |
| 117 | + t.Parallel() |
| 118 | + testJSONMarshal(t, &CopilotCloudAgentConfiguration{}, "{}") |
| 119 | + |
| 120 | + u := &CopilotCloudAgentConfiguration{ |
| 121 | + McpConfiguration: nil, |
| 122 | + EnabledTools: &EnabledTools{ |
| 123 | + Codeql: Ptr(true), |
| 124 | + CopilotCodeReview: Ptr(false), |
| 125 | + SecretScanning: Ptr(true), |
| 126 | + DependencyVulnerabilityChecks: Ptr(false), |
| 127 | + }, |
| 128 | + RequireActionsWorkflowApproval: Ptr(true), |
| 129 | + IsFirewallEnabled: Ptr(false), |
| 130 | + IsFirewallRecommendedAllowlistEnabled: Ptr(true), |
| 131 | + CustomAllowlist: []string{"192.168.0.0/16"}, |
| 132 | + } |
| 133 | + |
| 134 | + want := `{ |
| 135 | + "enabled_tools": { |
| 136 | + "codeql": true, |
| 137 | + "copilot_code_review": false, |
| 138 | + "secret_scanning": true, |
| 139 | + "dependency_vulnerability_checks": false |
| 140 | + }, |
| 141 | + "require_actions_workflow_approval": true, |
| 142 | + "is_firewall_enabled": false, |
| 143 | + "is_firewall_recommended_allowlist_enabled": true, |
| 144 | + "custom_allowlist": ["192.168.0.0/16"] |
| 145 | + }` |
| 146 | + |
| 147 | + testJSONMarshal(t, u, want) |
| 148 | +} |
0 commit comments