This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
git_test.go
63 lines (52 loc) · 1.54 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"os"
"testing"
)
func TestGitHost(t *testing.T) {
if res := gitHost(); res != "heroku.com" {
t.Errorf("expected heroku.com, got %s", res)
}
os.Setenv("HEROKU_GIT_HOST", "notheroku.com")
if res := gitHost(); res != "notheroku.com" {
t.Errorf("expected notheroku.com, got %s", res)
}
os.Setenv("HEROKU_GIT_HOST", "")
os.Setenv("HEROKU_HOST", "stillnotheroku.com")
defer os.Setenv("HEROKU_HOST", "")
if res := gitHost(); res != "stillnotheroku.com" {
t.Errorf("expected stillnotheroku.com, got %s", res)
}
}
var gitRemoteTestOutput = `
heroku git@heroku.com:myappfetch.git (fetch)
heroku git@heroku.com:myapp.git (push)
staging git@heroku.com:myapp-staging.git (fetch)
staging git@heroku.com:myapp-staging.git (push)
origin git@github.com:heroku/hk.git (fetch)
origin git@github.com:heroku/hk.git (push)
exciting https://git.heroku.com/amazing.git (fetch)
exciting https://git.heroku.com/amazing.git (push)
`
func TestParseGitRemoteOutput(t *testing.T) {
results, err := parseGitRemoteOutput([]byte(gitRemoteTestOutput))
if err != nil {
t.Fatal(err)
}
expected := map[string]string{
"heroku": "myapp",
"staging": "myapp-staging",
"exciting": "amazing",
}
if len(results) != len(expected) {
t.Errorf("expected %d results, got %d", len(expected), len(results))
}
for remoteName, app := range expected {
val, ok := results[remoteName]
if !ok {
t.Errorf("expected remote %s not found", val)
} else if val != app {
t.Errorf("expected remote %s to point to app %s, got %s", remoteName, app, val)
}
}
}