|
| 1 | +package cmd |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func Test_fromRemoteToOrgRepo(t *testing.T) { |
| 6 | + type args struct { |
| 7 | + remoteUsed string |
| 8 | + } |
| 9 | + tests := []struct { |
| 10 | + name string |
| 11 | + args args |
| 12 | + wantDefaultGitOrg string |
| 13 | + wantDefaultGitRepo string |
| 14 | + }{ |
| 15 | + {"git", args{"git@github.com:codeperfio/pprof-exporter.git"}, "codeperfio", "pprof-exporter"}, |
| 16 | + {"git-neg", args{"git@github.com:codeperfio/pprof-exporter"}, "codeperfio", "pprof-exporter"}, |
| 17 | + {"git-neg2", args{"github.com:codeperfio/pprof-exporter"}, "codeperfio", "pprof-exporter"}, |
| 18 | + {"codeperfio/example-go", args{"git@github.com:codeperfio/example-go.git"}, "codeperfio", "example-go"}, |
| 19 | + {"codeperfio/example-go-https", args{"https://github.com/codeperfio/example-go.git"}, "codeperfio", "example-go"}, |
| 20 | + {"codeperfio/example-go-https-neg", args{"https://github.com/codeperfio/example-go"}, "codeperfio", "example-go"}, |
| 21 | + } |
| 22 | + for _, tt := range tests { |
| 23 | + t.Run(tt.name, func(t *testing.T) { |
| 24 | + gotDefaultGitOrg, gotDefaultGitRepo := fromRemoteToOrgRepo(tt.args.remoteUsed) |
| 25 | + if gotDefaultGitOrg != tt.wantDefaultGitOrg { |
| 26 | + t.Errorf("fromRemoteToOrgRepo() gotDefaultGitOrg = %v, want %v", gotDefaultGitOrg, tt.wantDefaultGitOrg) |
| 27 | + } |
| 28 | + if gotDefaultGitRepo != tt.wantDefaultGitRepo { |
| 29 | + t.Errorf("fromRemoteToOrgRepo() gotDefaultGitRepo = %v, want %v", gotDefaultGitRepo, tt.wantDefaultGitRepo) |
| 30 | + } |
| 31 | + }) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func Test_getShortHash(t *testing.T) { |
| 36 | + type args struct { |
| 37 | + hash string |
| 38 | + ndigits int |
| 39 | + } |
| 40 | + tests := []struct { |
| 41 | + name string |
| 42 | + args args |
| 43 | + wantShort string |
| 44 | + }{ |
| 45 | + {"small", args{"a", 10}, "a"}, |
| 46 | + {"7dig", args{"1e872b59013425b7c404a91d16119e8452b983f2", 7}, "1e872b5"}, |
| 47 | + {"4dig", args{"1e872b59013425b7c404a91d16119e8452b983f2", 4}, "1e87"}, |
| 48 | + } |
| 49 | + for _, tt := range tests { |
| 50 | + t.Run(tt.name, func(t *testing.T) { |
| 51 | + if gotShort := getShortHash(tt.args.hash, tt.args.ndigits); gotShort != tt.wantShort { |
| 52 | + t.Errorf("getShortHash() = %v, want %v", gotShort, tt.wantShort) |
| 53 | + } |
| 54 | + }) |
| 55 | + } |
| 56 | +} |
0 commit comments