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

Function TestClientFetch

git/client_test.go:1630–1681  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1628}
1629
1630func TestClientFetch(t *testing.T) {
1631 tests := []struct {
1632 name string
1633 mods []CommandModifier
1634 commands mockedCommands
1635 wantErrorMsg string
1636 }{
1637 {
1638 name: "fetch",
1639 commands: map[args]commandResult{
1640 `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: {
1641 ExitStatus: 0,
1642 },
1643 },
1644 },
1645 {
1646 name: "accepts command modifiers",
1647 mods: []CommandModifier{WithRepoDir("/path/to/repo")},
1648 commands: map[args]commandResult{
1649 `path/to/git -C /path/to/repo -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: {
1650 ExitStatus: 0,
1651 },
1652 },
1653 },
1654 {
1655 name: "git error on fetch",
1656 commands: map[args]commandResult{
1657 `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: {
1658 ExitStatus: 1,
1659 Stderr: "fetch error message",
1660 },
1661 },
1662 wantErrorMsg: "failed to run git: fetch error message",
1663 },
1664 }
1665
1666 for _, tt := range tests {
1667 t.Run(tt.name, func(t *testing.T) {
1668 cmdCtx := createMockedCommandContext(t, tt.commands)
1669 client := Client{
1670 GitPath: "path/to/git",
1671 commandContext: cmdCtx,
1672 }
1673 err := client.Fetch(context.Background(), "origin", "trunk", tt.mods...)
1674 if tt.wantErrorMsg == "" {
1675 require.NoError(t, err)
1676 } else {
1677 require.EqualError(t, err, tt.wantErrorMsg)
1678 }
1679 })
1680 }
1681}
1682
1683func TestClientPull(t *testing.T) {
1684 tests := []struct {

Callers

nothing calls this directly

Calls 4

FetchMethod · 0.95
WithRepoDirFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected