MCPcopy Index your code
hub / github.com/cli/cli / Test_remoteResolver

Function Test_remoteResolver

pkg/cmd/factory/remote_resolver_test.go:23–293  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21}
22
23func Test_remoteResolver(t *testing.T) {
24 tests := []struct {
25 name string
26 remotes func() (git.RemoteSet, error)
27 config gh.Config
28 output []string
29 wantsErr bool
30 }{
31 {
32 name: "no authenticated hosts",
33 remotes: func() (git.RemoteSet, error) {
34 return git.RemoteSet{
35 git.NewRemote("origin", "https://github.com/owner/repo.git"),
36 }, nil
37 },
38 config: func() gh.Config {
39 cfg := &ghmock.ConfigMock{}
40 cfg.AuthenticationFunc = func() gh.AuthConfig {
41 authCfg := &config.AuthConfig{}
42 authCfg.SetHosts([]string{})
43 authCfg.SetDefaultHost("github.com", "default")
44 return authCfg
45 }
46 return cfg
47 }(),
48 wantsErr: true,
49 },
50 {
51 name: "no git remotes",
52 remotes: func() (git.RemoteSet, error) {
53 return git.RemoteSet{}, nil
54 },
55 config: func() gh.Config {
56 cfg := &ghmock.ConfigMock{}
57 cfg.AuthenticationFunc = func() gh.AuthConfig {
58 authCfg := &config.AuthConfig{}
59 authCfg.SetHosts([]string{"example.com"})
60 authCfg.SetDefaultHost("example.com", "hosts")
61 return authCfg
62 }
63 return cfg
64 }(),
65 wantsErr: true,
66 },
67 {
68 name: "one authenticated host with no matching git remote and no fallback remotes",
69 remotes: func() (git.RemoteSet, error) {
70 return git.RemoteSet{
71 git.NewRemote("origin", "https://test.com/owner/repo.git"),
72 }, nil
73 },
74 config: func() gh.Config {
75 cfg := &ghmock.ConfigMock{}
76 cfg.AuthenticationFunc = func() gh.AuthConfig {
77 authCfg := &config.AuthConfig{}
78 authCfg.SetHosts([]string{"example.com"})
79 authCfg.SetActiveToken("", "")
80 authCfg.SetDefaultHost("example.com", "hosts")

Callers

nothing calls this directly

Calls 8

SetHostsMethod · 0.95
SetDefaultHostMethod · 0.95
SetActiveTokenMethod · 0.95
ResolverMethod · 0.95
NewRemoteFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected