func TestTagList(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), gt.File("a_test.go", "testing", "bytes"), gt.FileBuild("b.go", "appengine", "encoding/hex"), ) g.Setup("co2/pk1", gt.File("a_not_test_foo.go", "encoding/csv"), gt.File("a_test.go", "testing", "encoding/json"), gt.FileBuild("b.go", "appengine", "encoding/binary"), ) g.In("co1") c := ctx(g) c.IgnoreBuild("test appengine") list(g, c, "co1 list", `e co2/pk1 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s encoding/csv < ["co2/pk1"] s encoding/hex < ["co1/pk1"] s testing < ["co1/pk1"] `) }
func TestUnused(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), ) g.Setup("co1/vendor/a", gt.File("a.go", "encoding/csv"), ) g.Setup("co2/pk1", gt.File("a.go", "bytes"), ) g.Setup("co3/pk1", gt.File("a.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co3/pk1", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] u co1/vendor/a [a] < [] u co1/vendor/co3/pk1 [co3/pk1] < [] l co1/pk1 < [] s bytes < ["co1/vendor/co2/pk1"] s encoding/csv < ["co1/vendor/a"] s strings < ["co1/vendor/co3/pk1"] `) }
func TestDuplicatePackage(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co3/pk1"), ) g.Setup("co2/pk1", gt.File("a.go", "co3/pk1"), ) g.Setup("co3/pk1", gt.File("a.go", "strings"), ) g.In("co2") Vendor(g, "co2 init", "init", "") Vendor(g, "co2 add", "add +ext", "") g.In("co1") Vendor(g, "co1 init", "init", "") Vendor(g, "co1 pre list", "list", `e co2/pk1 e co3/pk1 e co3/pk1 l co1/pk1 `) Vendor(g, "co1 add", "add -long +ext", "") Vendor(g, "co1 list", "list", `v co2/pk1 v co3/pk1 l co1/pk1 `) }
func TestTagAdd15(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), gt.File("a_test.go", "bytes", "testing"), gt.FileBuild("b.go", "appengine", "encoding/csv"), ) g.In("co1") c := ctx15(g) c.IgnoreBuild("test appengine") g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", `v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] l co1/pk1 < [] s strings < ["co1/vendor/co2/pk1"] `) checkPathBase := filepath.Join(g.Current(), "vendor", "co2", "pk1") if _, err := os.Stat(filepath.Join(checkPathBase, "a_test.go")); err == nil { t.Error("a_test.go should not be copied into vendor folder") } if _, err := os.Stat(filepath.Join(checkPathBase, "b.go")); err == nil { t.Error("b.go should not be copied into vendor folder") } }
func TestVendorProgram(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/main", gt.File("b.go", "bytes"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/main", AddUpdate)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 list", ` p co1/vendor/co2/main [co2/main] < [] l co1/pk1 < [] s bytes < ["co1/vendor/co2/main"] s strings < ["co1/pk1"] `) }
func TestEllipsis(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk1/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk1/pk2", gt.File("a.go", "strings"), ) g.In("co1") Vendor(g, "co1 init", "init", "") Vendor(g, "", "list", `e co2/pk1 e co2/pk1/pk2 l co1/pk1 `) Vendor(g, "co1 add ext", "add co2/pk1/...", "") Vendor(g, "co1 list", "list", `v co2/pk1 v co2/pk1/pk2 l co1/pk1 `) }
func TestImportSimple15(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx15(g) g.Check(c.ModifyImport("co2/pk1", AddUpdate)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) expected := `v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] e co2/pk2 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/vendor/co2/pk1" "co2/pk2"] ` list(g, c, "same", expected) c = ctx15(g) list(g, c, "new", expected) vendorFile15(g, `{ "comment": "", "ignore": "", "package": [ { "canonical": "co2/pk1", "comment": "", "local": "vendor/co2/pk1", "revision": "", "revisionTime": "" } ] }`) // Now remove an import. g.Check(c.ModifyImport("co2/pk1", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 remove", `e co2/pk1 < ["co1/pk1"] e co2/pk2 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co2/pk1" "co2/pk2"] `) }
func TestVendor(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), gt.File("b.go", "bytes"), ) g.Setup("co2/vendor/a", gt.File("a.go", "strings"), ) g.Setup("co2/pk1", gt.File("a.go", "a"), ) g.In("co1") c := ctx(g) list(g, c, "co1 list", `e co2/pk1 < ["co1/pk1"] e co2/vendor/a [a] < ["co2/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co2/vendor/a"] `) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co2/vendor/a", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", `v co1/vendor/a [a] < ["co1/vendor/co2/pk1"] v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/vendor/a"] `) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "origin": "co2/vendor/a", "path": "a", "revision": "" }, { "path": "co2/pk1", "revision": "" } ] } `) }
func TestAddMissing(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), ) g.In("co1") c := ctx(g) err := c.ModifyImport("co2/pk1", Add) if _, is := err.(ErrNotInGOPATH); !is { t.Fatalf("Expected not in GOPATH error. Got %v", err) } }
func TestTree(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk1/c_code", gt.File("stub.c"), ) g.Setup("co2/pk1/go_code", gt.File("stub.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1/^", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add list", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] u co1/vendor/co2/pk1/go_code [co2/pk1/go_code] < [] l co1/pk1 < [] s strings < ["co1/vendor/co2/pk1" "co1/vendor/co2/pk1/go_code"] `) tree(g, c, "co1 after add tree", ` /pk1/a.go /vendor/co2/pk1/a.go /vendor/co2/pk1/c_code/stub.c /vendor/co2/pk1/go_code/stub.go /vendor/vendor.json `) g.Check(c.ModifyImport("co2/pk1", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) tree(g, c, "co1 after remove tree", ` /pk1/a.go /vendor/vendor.json `) }
func TestMissing(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co3/pk1"), ) g.Setup("co2/pk1", gt.File("a.go", "bytes"), ) g.Setup("co3/pk1", gt.File("a.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co3/pk1", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] v co1/vendor/co3/pk1 [co3/pk1] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/vendor/co2/pk1"] s strings < ["co1/vendor/co3/pk1"] `) g.In("co1") c = ctx(g) g.Remove("co1/vendor/co2/pk1") g.Remove("co1/vendor/co3/pk1") g.Remove("co3/pk1") list(g, c, "co1 after remove", ` e co2/pk1 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co2/pk1"] m co3/pk1 < ["co1/pk1"] `) }
func TestImportSimple(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx14(g) g.Check(c.ModifyImport("co2/pk1", AddUpdate)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) vendorFile14(g, `{ "comment": "", "ignore": "", "package": [ { "path": "co2/pk1", "revision": "" } ] }`) expected := `v co1/internal/co2/pk1 [co2/pk1] < ["co1/pk1"] e co2/pk2 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/internal/co2/pk1" "co2/pk2"] ` list(g, c, "same", expected) c = ctx14(g) list(g, c, "new", expected) }
func TestRemove(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) g.In("co2/pk1") // Change directory to let windows delete directory. current := g.Current() g.In("co1") err := os.RemoveAll(current) if err != nil { g.Fatal(err) } g.Check(c.ModifyImport("co2/pk1", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) vi, err := os.Stat(filepath.Join(c.RootDir, c.VendorFolder)) if err != nil { t.Fatal("vendor folder should still be present", err) } if vi.IsDir() == false { t.Fatal("vendor folder is not a dir") } }
func TestSimple(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx14(g) list(g, c, "initial", `e co2/pk1 < ["co1/pk1"] e co2/pk2 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co2/pk1" "co2/pk2"] `) }
func TestTagList15(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1/pk2"), gt.File("a_test.go", "testing", "co2/pk1", "bytes"), gt.FileBuild("b.go", "appengine", "encoding/binary"), ) g.Setup("co2/pk1", gt.File("a.go", "encoding/csv"), ) g.Setup("co2/pk1/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx15(g) c.IgnoreBuild("test appengine") list(g, c, "co1 list", `e co2/pk1/pk2 < ["co1/pk1"] l co1/pk1 < [] s strings < ["co2/pk1/pk2"] `) }
func TestDuplicatePackage(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk2", "co3/pk3"), ) g.Setup("co2/pk2", gt.File("b.go", "co3/pk3"), ) g.Setup("co3/pk3", gt.File("c.go", "strings"), ) g.In("co2") c := ctx(g) statusList, err := c.Status() g.Check(err) for _, item := range statusList { if item.Status != StatusExternal { continue } g.Check(c.ModifyImport(item.Local, AddUpdate)) } g.Check(c.Alter()) g.Check(c.WriteVendorFile()) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "path": "co3/pk3", "revision": "" } ] } `) list(g, c, "co2 list", ` v co2/vendor/co3/pk3 [co3/pk3] < ["co2/pk2"] l co2/pk2 < [] s strings < ["co2/vendor/co3/pk3"] `) g.In("co1") c = ctx(g) list(g, c, "co1 pre list", ` e co2/pk2 < ["co1/pk1"] e co2/vendor/co3/pk3 [co3/pk3] < ["co2/pk2"] e co3/pk3 < ["co1/pk1"] l co1/pk1 < [] s strings < ["co2/vendor/co3/pk3" "co3/pk3"] `) statusList, err = c.Status() g.Check(err) for _, item := range statusList { if item.Status != StatusExternal { continue } g.Check(c.ModifyImport(item.Local, AddUpdate)) } c.ResloveApply(ResolveAutoLongestPath(c.Check())) // Automaically resolve conflicts. g.Check(c.Alter()) g.Check(c.WriteVendorFile()) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "path": "co2/pk2", "revision": "" }, { "origin": "co1/vendor/co3/pk3", "path": "co3/pk3", "revision": "" } ] } `) expected := ` v co1/vendor/co2/pk2 [co2/pk2] < ["co1/pk1"] v co1/vendor/co3/pk3 [co3/pk3] < ["co1/pk1" "co1/vendor/co2/pk2"] l co1/pk1 < [] s strings < ["co1/vendor/co3/pk3"] ` list(g, c, "co1 list 1", expected) c = ctx(g) list(g, c, "co1 list 2", expected) // Now remove one import. g.Check(c.ModifyImport("co3/pk3", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 remove", `v co1/vendor/co2/pk2 [co2/pk2] < ["co1/pk1"] e co3/pk3 < ["co1/pk1" "co1/vendor/co2/pk2"] l co1/pk1 < [] s strings < ["co3/pk3"] `) }
func TestUpdate(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk1/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk1/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co2/pk1/pk2", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/vendor/co2/pk1" "co1/vendor/co2/pk1/pk2"] `) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "path": "co2/pk1", "revision": "" }, { "path": "co2/pk1/pk2", "revision": "" } ] } `) g.Setup("co2/pk1/pk2", gt.File("a.go", "strings", "encoding/csv"), ) // Update an import. g.Check(c.ModifyImport("co2/pk1/pk2", Update)) ct := 0 for _, op := range c.Operation { if op.State == OpDone { continue } ct++ } if ct != 1 { t.Fatal("Must only have a single operation. Has", ct) } g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after update", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s encoding/csv < ["co1/vendor/co2/pk1/pk2"] s strings < ["co1/vendor/co2/pk1" "co1/vendor/co2/pk1/pk2"] `) // Now remove an import. g.Check(c.ModifyImport("co2/pk1", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 remove", `v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] e co2/pk1 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s encoding/csv < ["co1/vendor/co2/pk1/pk2"] s strings < ["co1/vendor/co2/pk1/pk2" "co2/pk1"] `) }
func TestVendorFile(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1"), gt.File("b.go", "bytes"), ) g.Setup("a", gt.File("a.go", "strings"), ) g.Setup("co2/pk1", gt.File("a.go", "a"), ) g.In("co2") c := ctx(g) g.Check(c.ModifyImport("a", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) // Ensure we import from vendor folder. // TODO: add test with "a" in GOPATH to ensure vendor folder pref. g.Remove("a") g.In("co1") c = ctx(g) list(g, c, "co1 list", `e co2/pk1 < ["co1/pk1"] e co2/vendor/a [a] < ["co2/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co2/vendor/a"] `) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co2/vendor/a", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", `v co1/vendor/a [a] < ["co1/vendor/co2/pk1"] v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/vendor/a"] `) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "origin": "co2/vendor/a", "path": "a", "revision": "" }, { "path": "co2/pk1", "revision": "" } ] } `) }
func TestUpdate(t *testing.T) { g := gt.New(t) defer g.Clean() g.Setup("co1/pk1", gt.File("a.go", "co2/pk1", "co2/pk1/pk2"), gt.File("b.go", "co2/pk1", "bytes"), ) g.Setup("co2/pk1", gt.File("a.go", "strings"), ) g.Setup("co2/pk1/pk2", gt.File("a.go", "strings"), ) g.In("co1") c := ctx(g) g.Check(c.ModifyImport("co2/pk1", Add)) g.Check(c.ModifyImport("co2/pk1/pk2", Add)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after add", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s strings < ["co1/vendor/co2/pk1" "co1/vendor/co2/pk1/pk2"] `) vendorFile(g, `{ "comment": "", "ignore": "", "package": [ { "path": "co2/pk1", "revision": "" }, { "path": "co2/pk1/pk2", "revision": "" } ] } `) g.Setup("co1/vendor/co2/pk1/pk2", gt.File("a.go", "strings", "encoding/csv"), ) // Update an import. g.Check(c.ModifyImport("co2/pk1/pk2", Update)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 after update", ` v co1/vendor/co2/pk1 [co2/pk1] < ["co1/pk1"] v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s encoding/csv < ["co1/vendor/co2/pk1/pk2"] s strings < ["co1/vendor/co2/pk1" "co1/vendor/co2/pk1/pk2"] `) // Now remove an import. g.Check(c.ModifyImport("co2/pk1", Remove)) g.Check(c.Alter()) g.Check(c.WriteVendorFile()) list(g, c, "co1 remove", `v co1/vendor/co2/pk1/pk2 [co2/pk1/pk2] < ["co1/pk1"] e co2/pk1 < ["co1/pk1"] l co1/pk1 < [] s bytes < ["co1/pk1"] s encoding/csv < ["co1/vendor/co2/pk1/pk2"] s strings < ["co1/vendor/co2/pk1/pk2" "co2/pk1"] `) }