File: vendor_test.go

package info (click to toggle)
golang-golang-x-mod 0.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 932 kB
  • sloc: sh: 6; makefile: 6
file content (39 lines) | stat: -rw-r--r-- 1,237 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2020 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.

package zip

import "testing"

func TestIsVendoredPackage(t *testing.T) {
	for _, tc := range []struct {
		path          string
		want          bool
		falsePositive bool // is this case affected by https://golang.org/issue/37397?
	}{
		{path: "vendor/foo/foo.go", want: true},
		{path: "pkg/vendor/foo/foo.go", want: true},
		{path: "longpackagename/vendor/foo/foo.go", want: true},

		{path: "vendor/vendor.go", want: false},

		// We ideally want these cases to be false, but they are affected by
		// https://golang.org/issue/37397, and if we fix them we will invalidate
		// existing module checksums. We must leave them as-is-for now.
		{path: "pkg/vendor/vendor.go", falsePositive: true},
		{path: "longpackagename/vendor/vendor.go", falsePositive: true},
	} {
		got := isVendoredPackage(tc.path)
		want := tc.want
		if tc.falsePositive {
			want = true
		}
		if got != want {
			t.Errorf("isVendoredPackage(%q) = %t; want %t", tc.path, got, tc.want)
			if tc.falsePositive {
				t.Logf("(Expected a false-positive due to https://golang.org/issue/37397.)")
			}
		}
	}
}