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

Function TestAPIHostForHost

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

Source from the content-addressed store, hash-verified

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

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