hub/commands/init_test.go

94 строки
2.3 KiB
Go
Исходник Обычный вид История

2013-07-05 03:18:54 +04:00
package commands
import (
"fmt"
2013-12-10 10:47:15 +04:00
"os"
"path/filepath"
2013-07-05 03:18:54 +04:00
"testing"
"github.com/bmizerany/assert"
"github.com/github/hub/github"
2013-07-05 03:18:54 +04:00
)
func setupInitContext() {
2014-04-08 08:19:57 +04:00
os.Setenv("HUB_PROTOCOL", "git")
os.Setenv("HUB_CONFIG", "")
2013-12-17 19:07:26 +04:00
github.CreateTestConfigs("jingweno", "123")
}
func TestEmptyParams(t *testing.T) {
setupInitContext()
2013-07-05 03:18:54 +04:00
args := NewArgs([]string{"init"})
err := transformInitArgs(args)
assert.Equal(t, nil, err)
assert.Equal(t, true, args.IsParamsEmpty())
}
2013-07-05 03:18:54 +04:00
func TestFlagToAddRemote(t *testing.T) {
setupInitContext()
2013-07-05 03:18:54 +04:00
args := NewArgs([]string{"init", "-g", "--quiet"})
err := transformInitArgs(args)
2013-07-05 03:18:54 +04:00
assert.Equal(t, nil, err)
commands := args.Commands()
assert.Equal(t, 2, len(commands))
assert.Equal(t, "git init --quiet", commands[0].String())
currentDir, err := os.Getwd()
assert.Equal(t, nil, err)
expected := fmt.Sprintf(
"git --git-dir %s remote add origin git@github.com:jingweno/%s.git",
filepath.Join(currentDir, ".git"),
filepath.Base(currentDir),
)
assert.Equal(t, expected, commands[1].String())
}
func TestInitInAnotherDir(t *testing.T) {
setupInitContext()
args := NewArgs([]string{"init", "-g", "--template", "mytpl", "--shared=umask", "my project"})
err := transformInitArgs(args)
assert.Equal(t, nil, err)
commands := args.Commands()
assert.Equal(t, 2, len(commands))
assert.Equal(t, "git init --template mytpl --shared=umask my project", commands[0].String())
currentDir, err := os.Getwd()
assert.Equal(t, nil, err)
expected := fmt.Sprintf(
"git --git-dir %s remote add origin git@github.com:jingweno/%s.git",
filepath.Join(currentDir, "my project", ".git"),
"my-project",
)
assert.Equal(t, expected, commands[1].String())
}
func TestSeparateGitDir(t *testing.T) {
setupInitContext()
args := NewArgs([]string{"init", "-g", "--separate-git-dir", "/tmp/where-i-play.git", "my/playground"})
err := transformInitArgs(args)
assert.Equal(t, nil, err)
commands := args.Commands()
assert.Equal(t, 2, len(commands))
assert.Equal(t, "git init --separate-git-dir /tmp/where-i-play.git my/playground", commands[0].String())
currentDir, err := os.Getwd()
assert.Equal(t, nil, err)
expected := fmt.Sprintf(
"git --git-dir %s remote add origin git@github.com:jingweno/%s.git",
filepath.Join(currentDir, "my", "playground", ".git"),
"playground",
)
assert.Equal(t, expected, commands[1].String())
2013-07-05 03:18:54 +04:00
}