| 1 |
// Copyright 2020 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package zip |
| 6 |
|
| 7 |
import "testing" |
| 8 |
|
| 9 |
var pre124 []string = []string{ |
| 10 |
"", |
| 11 |
"go1.14", |
| 12 |
"go1.21.0", |
| 13 |
"go1.22.4", |
| 14 |
"go1.23", |
| 15 |
"go1.23.1", |
| 16 |
"go1.2", |
| 17 |
"go1.7", |
| 18 |
"go1.9", |
| 19 |
} |
| 20 |
|
| 21 |
var after124 []string = []string{"go1.24.0", "go1.24", "go1.99.0"} |
| 22 |
|
| 23 |
var allVers []string = append(pre124, after124...) |
| 24 |
|
| 25 |
func TestIsVendoredPackage(t *testing.T) { |
| 26 |
for _, tc := range []struct { |
| 27 |
path string |
| 28 |
want bool |
| 29 |
versions []string |
| 30 |
}{ |
| 31 |
{path: "vendor/foo/foo.go", want: true, versions: allVers}, |
| 32 |
{path: "pkg/vendor/foo/foo.go", want: true, versions: allVers}, |
| 33 |
{path: "longpackagename/vendor/foo/foo.go", want: true, versions: allVers}, |
| 34 |
{path: "vendor/vendor.go", want: false, versions: allVers}, |
| 35 |
{path: "vendor/foo/modules.txt", want: true, versions: allVers}, |
| 36 |
{path: "modules.txt", want: false, versions: allVers}, |
| 37 |
{path: "vendor/amodules.txt", want: false, versions: allVers}, |
| 38 |
|
| 39 |
// These test cases were affected by https://golang.org/issue/63395 |
| 40 |
{path: "vendor/modules.txt", want: false, versions: pre124}, |
| 41 |
{path: "vendor/modules.txt", want: true, versions: after124}, |
| 42 |
|
| 43 |
// These test cases were affected by https://golang.org/issue/37397 |
| 44 |
{path: "pkg/vendor/vendor.go", want: true, versions: pre124}, |
| 45 |
{path: "pkg/vendor/vendor.go", want: false, versions: after124}, |
| 46 |
{path: "longpackagename/vendor/vendor.go", want: true, versions: pre124}, |
| 47 |
{path: "longpackagename/vendor/vendor.go", want: false, versions: after124}, |
| 48 |
} { |
| 49 |
for _, v := range tc.versions { |
| 50 |
got := isVendoredPackage(tc.path, v) |
| 51 |
want := tc.want |
| 52 |
if got != want { |
| 53 |
t.Errorf("isVendoredPackage(%q, %s) = %t; want %t", tc.path, v, got, tc.want) |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |