2017-05-02 19:26:49 +03:00
|
|
|
// Copyright 2017 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-04-02 19:57:46 +03:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package gps
|
|
|
|
|
2017-04-11 21:34:10 +03:00
|
|
|
import "testing"
|
2017-04-10 22:13:24 +03:00
|
|
|
|
|
|
|
func TestStripVendorSymlinks(t *testing.T) {
|
|
|
|
// On windows, we skip symlinks, even if they're named 'vendor', because
|
|
|
|
// they're too hard to distinguish from junctions.
|
|
|
|
t.Run("vendor symlink", stripVendorTestCase(fsTestCase{
|
|
|
|
before: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
|
|
|
{"package", "_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "vendor"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
|
|
|
{"package", "_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "vendor"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
t.Run("nonvendor symlink", stripVendorTestCase(fsTestCase{
|
|
|
|
before: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
|
|
|
{"package", "_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
|
|
|
{"package", "_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
t.Run("vendor symlink to file", stripVendorTestCase(fsTestCase{
|
|
|
|
before: filesystemState{
|
|
|
|
files: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"file"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"vendor"},
|
|
|
|
to: "file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
files: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"file"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"vendor"},
|
|
|
|
to: "file",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2017-09-21 03:41:44 +03:00
|
|
|
t.Run("broken vendor symlink", stripVendorTestCase(fsTestCase{
|
|
|
|
before: filesystemState{
|
|
|
|
dirs: []fsPath{
|
|
|
|
{"package"},
|
|
|
|
},
|
|
|
|
links: []fsLink{
|
|
|
|
{
|
|
|
|
path: fsPath{"package", "vendor"},
|
|
|
|
to: "nonexistence",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
dirs: []fsPath{
|
|
|
|
{"package"},
|
|
|
|
},
|
|
|
|
links: []fsLink{
|
|
|
|
{
|
|
|
|
path: fsPath{"package", "vendor"},
|
|
|
|
to: "nonexistence",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
2017-04-10 22:13:24 +03:00
|
|
|
t.Run("chained symlinks", stripVendorTestCase(fsTestCase{
|
2017-04-10 22:31:00 +03:00
|
|
|
// Curiously, if a symlink on windows points to *another* symlink which
|
|
|
|
// eventually points at a directory, we'll correctly remove that first
|
|
|
|
// symlink, because the first symlink doesn't appear to Go to be a
|
|
|
|
// directory.
|
2017-04-10 22:13:24 +03:00
|
|
|
before: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"vendor"},
|
|
|
|
to: "vendor2",
|
|
|
|
},
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"vendor2"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"_vendor"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"vendor2"},
|
|
|
|
to: "_vendor",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
|
|
|
|
t.Run("circular symlinks", stripVendorTestCase(fsTestCase{
|
|
|
|
before: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link1"},
|
|
|
|
to: "link2",
|
|
|
|
},
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link2"},
|
|
|
|
to: "link1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
after: filesystemState{
|
|
|
|
dirs: []fsPath{
|
2017-05-11 18:18:30 +03:00
|
|
|
{"package"},
|
2017-04-10 22:13:24 +03:00
|
|
|
},
|
|
|
|
links: []fsLink{
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link1"},
|
|
|
|
to: "link2",
|
|
|
|
},
|
2017-05-11 18:18:30 +03:00
|
|
|
{
|
2017-04-10 22:13:24 +03:00
|
|
|
path: fsPath{"package", "link2"},
|
|
|
|
to: "link1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}))
|
|
|
|
}
|