Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/credential-helper_test.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"testing"
9
10
"github.com/google/go-cmp/cmp"
11
)
12
13
func Test_parse_git_command_and_remote(t *testing.T) {
14
tests := []struct {
15
Name string
16
Commands []string
17
Expected gitCommandInfo
18
}{
19
{
20
Name: "Detect push command",
21
Commands: []string{
22
"/usr/lib/git-core/git-remote-https origin https://github.com/jeanp413/test-gp-bug.git",
23
"/usr/lib/git-core/git push",
24
},
25
Expected: gitCommandInfo{RepoUrl: "https://github.com/jeanp413/test-gp-bug.git", GitCommand: "push"},
26
},
27
{
28
Name: "Detect with remote named origin",
29
Commands: []string{
30
"/usr/lib/git-core/git-remote-https origin https://github.com/jeanp413/test-gp-bug.git",
31
"/usr/lib/git-core/git remote-https origin https://github.com/jeanp413/test-gp-bug.git",
32
"git push origin master",
33
},
34
Expected: gitCommandInfo{RepoUrl: "https://github.com/jeanp413/test-gp-bug.git", GitCommand: "push"},
35
},
36
{
37
Name: "Detect with remote named foo",
38
Commands: []string{
39
"/usr/lib/git-core/git-remote-https foo https://github.com/jeanp413/test-private-package.git",
40
"/usr/lib/git-core/git remote-https foo https://github.com/jeanp413/test-private-package.git",
41
"git push foo master",
42
},
43
Expected: gitCommandInfo{RepoUrl: "https://github.com/jeanp413/test-private-package.git", GitCommand: "push"},
44
},
45
{
46
Name: "Detect ls-remote command",
47
Commands: []string{
48
"/usr/lib/git-core/git-remote-https https://github.com/joepurdy/private-npm-package.git https://github.com/joepurdy/private-npm-package.git",
49
"/usr/lib/git-core/git remote-https https://github.com/joepurdy/private-npm-package.git https://github.com/joepurdy/private-npm-package.git",
50
"git --no-replace-objects ls-remote https://github.com/joepurdy/private-npm-package.git",
51
},
52
Expected: gitCommandInfo{RepoUrl: "https://github.com/joepurdy/private-npm-package.git", GitCommand: "ls-remote"},
53
},
54
{
55
Name: "Detect clone command",
56
Commands: []string{
57
"/usr/lib/git-core/git-remote-https origin https://github.com/jeanp413/test-private-package.git",
58
"/usr/lib/git-core/git remote-https origin https://github.com/jeanp413/test-private-package.git",
59
"git --no-replace-objects clone https://github.com/jeanp413/test-private-package.git /home/gitpod/.npm/_cacache/tmp/git-cloneUsL7Mf --recurse-submodules --depth=1",
60
},
61
Expected: gitCommandInfo{RepoUrl: "https://github.com/jeanp413/test-private-package.git", GitCommand: "clone"},
62
},
63
{
64
Name: "JB push command",
65
Commands: []string{
66
"/usr/lib/git-core/git remote-https origin https://github.com/gitpod-samples/spring-petclinic.git",
67
"/bin/git -c core.quotepath=false -c log.showSignature=false push --progress --porcelain origin refs/heads/master:master",
68
},
69
Expected: gitCommandInfo{RepoUrl: "https://github.com/gitpod-samples/spring-petclinic.git", GitCommand: "push"},
70
},
71
}
72
for _, tt := range tests {
73
t.Run(tt.Name, func(t *testing.T) {
74
gitCmdInfo := gitCommandInfo{}
75
for _, command := range tt.Commands {
76
gitCmdInfo.parseGitCommandAndRemote(command)
77
}
78
79
equal := cmp.Equal(gitCmdInfo, tt.Expected)
80
if !equal {
81
t.Fatalf(`Detected git command info was incorrect, got: %v, expected: %v.`, gitCmdInfo, tt.Expected)
82
}
83
})
84
}
85
}
86
87