MCPcopy Create free account
hub / github.com/cli/cli / TestAPIHostForHost

Function TestAPIHostForHost

internal/config/auth_config_test.go:1120–1169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1118}
1119
1120func TestAPIHostForHost(t *testing.T) {
1121 tests := []struct {
1122 name string
1123 apiHost string
1124 lookup string
1125 wantAPIHost string
1126 wantFound bool
1127 }{
1128 {
1129 name: "the host has no api_host set",
1130 lookup: "github.com",
1131 wantFound: false,
1132 },
1133 {
1134 name: "the host configures an api_host",
1135 apiHost: "api-gateway.example.com",
1136 lookup: "github.com",
1137 wantAPIHost: "api-gateway.example.com",
1138 wantFound: true,
1139 },
1140 {
1141 name: "an empty host matches nothing",
1142 apiHost: "api-gateway.example.com",
1143 lookup: "",
1144 wantFound: false,
1145 },
1146 {
1147 name: "an unknown host matches nothing",
1148 apiHost: "api-gateway.example.com",
1149 lookup: "ghe.io",
1150 wantFound: false,
1151 },
1152 }
1153
1154 for _, tt := range tests {
1155 t.Run(tt.name, func(t *testing.T) {
1156 authCfg := newTestAuthConfig(t)
1157 _, err := authCfg.Login("github.com", "test-user", "test-token", "https", false)
1158 require.NoError(t, err)
1159 if tt.apiHost != "" {
1160 authCfg.cfg.Set([]string{hostsKey, "github.com", apiHostKey}, tt.apiHost)
1161 }
1162
1163 apiHost, found := authCfg.APIHostForHost(tt.lookup)
1164
1165 require.Equal(t, tt.wantFound, found)
1166 require.Equal(t, tt.wantAPIHost, apiHost)
1167 })
1168 }
1169}

Callers

nothing calls this directly

Calls 6

newTestAuthConfigFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
LoginMethod · 0.65
SetMethod · 0.65
APIHostForHostMethod · 0.65

Tested by

no test coverage detected