// TestMain must cleanup these directories created by this function. func buildInstallers(t *testing.T) string { buildInstallersOnce.Do(func() { binDir, err := ioutil.TempDir("", "") if err != nil { t.Fatal(err) } sh := gosh.NewShell(t) defer sh.Cleanup() prefix := "v.io/jiri/profiles/profilescmdline/internal/" gosh.BuildGoPkg(sh, binDir, "v.io/jiri/cmd/jiri", "-o", "jiri") gosh.BuildGoPkg(sh, binDir, prefix+"i1", "-o", "jiri-profile-i1") gosh.BuildGoPkg(sh, binDir, prefix+"i2", "-o", "jiri-profile-i2") buildInstallersBinDir = binDir }) return buildInstallersBinDir }
func buildJiri(t *testing.T) string { buildJiriOnce.Do(func() { binDir, err := ioutil.TempDir("", "") if err != nil { t.Fatal(err) } sh := gosh.NewShell(t) defer sh.Cleanup() gosh.BuildGoPkg(sh, binDir, "v.io/jiri/cmd/jiri", "-o", "jiri") buildJiriBinDir = binDir }) return buildJiriBinDir }
func TestImport(t *testing.T) { tests := []importTestCase{ { Stderr: `wrong number of arguments`, }, { Args: []string{"a"}, Stderr: `wrong number of arguments`, }, { Args: []string{"a", "b", "c"}, Stderr: `wrong number of arguments`, }, // Remote imports, default append behavior { Args: []string{"-name=name", "-remote-branch=remotebranch", "-root=root", "foo", "https://github.com/new.git"}, Want: `<manifest> <imports> <import manifest="foo" name="name" remote="https://github.com/new.git" remotebranch="remotebranch" root="root"/> </imports> </manifest> `, }, { Args: []string{"foo", "https://github.com/new.git"}, Want: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"-out=file", "foo", "https://github.com/new.git"}, Filename: `file`, Want: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"-out=-", "foo", "https://github.com/new.git"}, Stdout: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"foo", "https://github.com/new.git"}, Exist: `<manifest> <imports> <import manifest="bar" name="manifest" remote="https://github.com/orig.git"/> </imports> </manifest> `, Want: `<manifest> <imports> <import manifest="bar" name="manifest" remote="https://github.com/orig.git"/> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, // Remote imports, explicit overwrite behavior { Args: []string{"-overwrite", "foo", "https://github.com/new.git"}, Want: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"-overwrite", "-out=file", "foo", "https://github.com/new.git"}, Filename: `file`, Want: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"-overwrite", "-out=-", "foo", "https://github.com/new.git"}, Stdout: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, { Args: []string{"-overwrite", "foo", "https://github.com/new.git"}, Exist: `<manifest> <imports> <import manifest="bar" name="manifest" remote="https://github.com/orig.git"/> </imports> </manifest> `, Want: `<manifest> <imports> <import manifest="foo" name="manifest" remote="https://github.com/new.git"/> </imports> </manifest> `, }, } sh := gosh.NewShell(t) defer sh.Cleanup() jiriTool := gosh.BuildGoPkg(sh, sh.MakeTempDir(), "v.io/jiri/cmd/jiri") for _, test := range tests { if err := testImport(t, jiriTool, test); err != nil { t.Errorf("%v: %v", test.Args, err) } } }