git-lfs/commands/env_test.go

103 lines
3.2 KiB
Go
Raw Normal View History

2014-06-04 17:40:09 +00:00
package commands
import (
"os"
"os/exec"
2014-06-04 17:40:09 +00:00
"path/filepath"
"testing"
)
2014-06-05 16:52:32 +00:00
func TestEnv(t *testing.T) {
2014-06-04 17:40:09 +00:00
repo := NewRepository(t, "empty")
2014-06-04 18:57:20 +00:00
defer repo.Test()
repo.AddPath(repo.Path, ".git")
repo.AddPath(repo.Path, "subdir")
2014-06-04 17:40:09 +00:00
2014-06-05 16:52:32 +00:00
cmd := repo.Command("env")
2014-06-04 17:40:09 +00:00
SetConfigOutput(cmd, map[string]string{
"Endpoint": "https://example.com/git/media.git/info/media",
"LocalWorkingDir": repo.Path,
"LocalGitDir": filepath.Join(repo.Path, ".git"),
"LocalMediaDir": filepath.Join(repo.Path, ".git", "media"),
2014-06-05 23:32:57 +00:00
"TempDir": filepath.Join(repo.Path, ".git", "media", "tmp"),
2014-06-04 17:40:09 +00:00
})
}
2014-06-05 16:52:32 +00:00
func TestEnvWithMediaUrl(t *testing.T) {
2014-06-04 17:40:09 +00:00
repo := NewRepository(t, "config_media_url")
2014-06-04 18:57:20 +00:00
defer repo.Test()
2014-06-04 17:40:09 +00:00
2014-06-05 16:52:32 +00:00
cmd := repo.Command("env")
2014-06-04 17:40:09 +00:00
SetConfigOutput(cmd, map[string]string{
"Endpoint": "http://foo/bar",
"LocalWorkingDir": repo.Path,
"LocalGitDir": filepath.Join(repo.Path, ".git"),
"LocalMediaDir": filepath.Join(repo.Path, ".git", "media"),
2014-06-05 23:32:57 +00:00
"TempDir": filepath.Join(repo.Path, ".git", "media", "tmp"),
2014-06-04 17:40:09 +00:00
})
}
func TestEnvWithSubmoduleFromRepository(t *testing.T) {
repo := NewRepository(t, "submodule")
defer repo.Test()
cmd := repo.Command("env")
SetConfigOutput(cmd, map[string]string{
"Endpoint": "https://example.com/git/media.git/info/media",
"LocalWorkingDir": repo.Path,
"LocalGitDir": filepath.Join(repo.Path, ".git"),
"LocalMediaDir": filepath.Join(repo.Path, ".git", "media"),
2014-06-05 23:32:57 +00:00
"TempDir": filepath.Join(repo.Path, ".git", "media", "tmp"),
})
cmd.Before(func() {
submodPath := filepath.Join(Root, "commands", "repos", "attributes.git")
exec.Command("git", "config", "--add", "submodule.attributes.url", submodPath).Run()
exec.Command("git", "submodule", "update").Run()
})
}
func TestEnvWithSubmoduleFromSubmodule(t *testing.T) {
repo := NewRepository(t, "submodule")
defer repo.Test()
repo.AddPath(repo.Path, "attributes")
repo.Paths = repo.Paths[1:]
cmd := repo.Command("env")
cmd.Before(func() {
submodPath := filepath.Join(Root, "commands", "repos", "attributes.git")
exec.Command("git", "config", "--add", "submodule.attributes.url", submodPath).Run()
exec.Command("git", "submodule", "update").Run()
os.Chdir(filepath.Join("attributes"))
exec.Command("git", "checkout", "-b", "whatevs").Run()
})
}
func TestEnvWithConfiguredSubmodule(t *testing.T) {
repo := NewRepository(t, "submodule")
defer repo.Test()
repo.AddPath(repo.Path, "config_media_url")
repo.Paths = repo.Paths[1:]
cmd := repo.Command("env")
SetConfigOutput(cmd, map[string]string{
"Endpoint": "http://foo/bar",
"LocalWorkingDir": filepath.Join(repo.Path, "config_media_url"),
"LocalGitDir": filepath.Join(repo.Path, ".git", "modules", "config_media_url"),
"LocalMediaDir": filepath.Join(repo.Path, ".git", "modules", "config_media_url", "media"),
"TempDir": filepath.Join(repo.Path, ".git", "modules", "config_media_url", "media", "tmp"),
})
cmd.Before(func() {
submodPath := filepath.Join(Root, "commands", "repos", "config_media_url.git")
exec.Command("git", "submodule", "add", submodPath).Run()
exec.Command("git", "submodule", "update").Run()
os.Chdir("config_media_url")
exec.Command("git", "checkout", "-b", "whatevs").Run()
})
}