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