MCPcopy
hub / github.com/cli/cli / Test

Method Test

pkg/cmd/auth/shared/contract/helper_config.go:20–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18}
19
20func (contract HelperConfig) Test(t *testing.T) {
21 t.Run("when there are no credential helpers, configures gh for repo and gist host", func(t *testing.T) {
22 hc := contract.NewHelperConfig(t)
23 require.NoError(t, hc.ConfigureOurs("github.com"))
24
25 repoHelper, err := hc.ConfiguredHelper("github.com")
26 require.NoError(t, err)
27 require.True(t, repoHelper.IsConfigured(), "expected our helper to be configured")
28 require.True(t, repoHelper.IsOurs(), "expected the helper to be ours but was %q", repoHelper.Cmd)
29
30 gistHelper, err := hc.ConfiguredHelper("gist.github.com")
31 require.NoError(t, err)
32 require.True(t, gistHelper.IsConfigured(), "expected our helper to be configured")
33 require.True(t, gistHelper.IsOurs(), "expected the helper to be ours but was %q", gistHelper.Cmd)
34 })
35
36 t.Run("when there is a global credential helper, it should be configured but not ours", func(t *testing.T) {
37 hc := contract.NewHelperConfig(t)
38 contract.ConfigureHelper(t, "credential.helper")
39
40 helper, err := hc.ConfiguredHelper("github.com")
41 require.NoError(t, err)
42 require.True(t, helper.IsConfigured(), "expected helper to be configured")
43 require.False(t, helper.IsOurs(), "expected the helper not to be ours but was %q", helper.Cmd)
44 })
45
46 t.Run("when there is a host credential helper, it should be configured but not ours", func(t *testing.T) {
47 hc := contract.NewHelperConfig(t)
48 contract.ConfigureHelper(t, "credential.https://github.com.helper")
49
50 helper, err := hc.ConfiguredHelper("github.com")
51 require.NoError(t, err)
52 require.True(t, helper.IsConfigured(), "expected helper to be configured")
53 require.False(t, helper.IsOurs(), "expected the helper not to be ours but was %q", helper.Cmd)
54 })
55
56 t.Run("returns non configured helper when no helpers are configured", func(t *testing.T) {
57 hc := contract.NewHelperConfig(t)
58
59 helper, err := hc.ConfiguredHelper("github.com")
60 require.NoError(t, err)
61 require.False(t, helper.IsConfigured(), "expected no helper to be configured")
62 require.False(t, helper.IsOurs(), "expected the helper not to be ours but was %q", helper.Cmd)
63 })
64}

Callers 3

TestHelperConfigContractFunction · 0.80
newMockGitClientFunction · 0.80

Implementers 2

HelperConfigpkg/cmd/auth/shared/gitcredentials/hel
FakeHelperConfigpkg/cmd/auth/shared/gitcredentials/fak

Calls 5

ConfigureOursMethod · 0.95
ConfiguredHelperMethod · 0.95
IsConfiguredMethod · 0.80
IsOursMethod · 0.80
RunMethod · 0.65

Tested by 3

TestHelperConfigContractFunction · 0.64
newMockGitClientFunction · 0.64