github.com/koron/hk@v0.0.0-20150303213137-b8aeaa3ab34c/git_test.go (about)

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