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

Function NewMockConfigFromString

internal/config/test.go:31–109  ·  view source on GitHub ↗

NewMockConfigFromString returns a mock config populated from cfgString, for tests that need to stub config behaviour by assigning to the mock's function fields. The mock answers host, token, and default host lookups from cfgString alone, so it ignores both the config files on disk and the environme

(cfgString string)

Source from the content-addressed store, hash-verified

29// implementation, writes config, or reads the auth environment variables directly,
30// since none of those go through the mock.
31func NewMockConfigFromString(cfgString string) *ghmock.ConfigMock {
32 c := ghConfig.ReadFromString(cfgString)
33 cfg := cfg{c}
34 mock := &ghmock.ConfigMock{}
35 mock.GetOrDefaultFunc = func(host, key string) o.Option[gh.ConfigEntry] {
36 return cfg.GetOrDefault(host, key)
37 }
38 mock.SetFunc = func(host, key, value string) {
39 cfg.Set(host, key, value)
40 }
41 mock.WriteFunc = func() error {
42 return cfg.Write()
43 }
44 mock.MigrateFunc = func(m gh.Migration) error {
45 return cfg.Migrate(m)
46 }
47 mock.AliasesFunc = func() gh.AliasConfig {
48 return &AliasConfig{cfg: c}
49 }
50 mock.AuthenticationFunc = func() gh.AuthConfig {
51 return &AuthConfig{
52 cfg: c,
53 defaultHostOverride: func() (string, string) {
54 return "github.com", "default"
55 },
56 hostsOverride: func() []string {
57 keys, _ := c.Keys([]string{hostsKey})
58 return keys
59 },
60 tokenOverride: func(hostname string) (string, string) {
61 token, _ := c.Get([]string{hostsKey, hostname, oauthTokenKey})
62 return token, oauthTokenKey
63 },
64 }
65 }
66 mock.AccessibleColorsFunc = func(hostname string) gh.ConfigEntry {
67 return cfg.AccessibleColors(hostname)
68 }
69 mock.AccessiblePrompterFunc = func(hostname string) gh.ConfigEntry {
70 return cfg.AccessiblePrompter(hostname)
71 }
72 mock.BrowserFunc = func(hostname string) gh.ConfigEntry {
73 return cfg.Browser(hostname)
74 }
75 mock.TelemetryFunc = func() gh.ConfigEntry {
76 return cfg.Telemetry()
77 }
78 mock.ColorLabelsFunc = func(hostname string) gh.ConfigEntry {
79 return cfg.ColorLabels(hostname)
80 }
81 mock.EditorFunc = func(hostname string) gh.ConfigEntry {
82 return cfg.Editor(hostname)
83 }
84 mock.GitProtocolFunc = func(hostname string) gh.ConfigEntry {
85 return cfg.GitProtocol(hostname)
86 }
87 mock.HTTPUnixSocketFunc = func(hostname string) gh.ConfigEntry {
88 return cfg.HTTPUnixSocket(hostname)

Callers 15

defaultConfigFunction · 0.92
testConfigFunction · 0.92
TestNewCmdCreateFunction · 0.92
Test_createRunFunction · 0.92
Test_editRunFunction · 0.92
TestImportRunFunction · 0.92
TestDeleteRunFunction · 0.92
TestAliasListFunction · 0.92
testConfigFunction · 0.92
TestNewCmdCreateFunction · 0.92

Calls 15

GetOrDefaultMethod · 0.95
SetMethod · 0.95
WriteMethod · 0.95
MigrateMethod · 0.95
AccessibleColorsMethod · 0.95
AccessiblePrompterMethod · 0.95
BrowserMethod · 0.95
TelemetryMethod · 0.95
ColorLabelsMethod · 0.95
EditorMethod · 0.95
GitProtocolMethod · 0.95
HTTPUnixSocketMethod · 0.95

Tested by 15

defaultConfigFunction · 0.74
testConfigFunction · 0.74
TestNewCmdCreateFunction · 0.74
Test_createRunFunction · 0.74
Test_editRunFunction · 0.74
TestImportRunFunction · 0.74
TestDeleteRunFunction · 0.74
TestAliasListFunction · 0.74
testConfigFunction · 0.74
TestNewCmdCreateFunction · 0.74