1 // Copyright 2019 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.
14 func TestDirectoryPackageInfoReachedStatus(t *testing.T) {
16 info directoryPackageInfo
17 target directoryPackageStatus
22 info: directoryPackageInfo{
23 status: directoryScanned,
26 target: directoryScanned,
30 info: directoryPackageInfo{
31 status: directoryScanned,
32 err: fmt.Errorf("error getting to directory scanned"),
34 target: directoryScanned,
39 info: directoryPackageInfo{},
40 target: directoryScanned,
45 for _, tt := range tests {
46 gotStatus, gotErr := tt.info.reachedStatus(tt.target)
49 t.Errorf("unexpected error: %s", gotErr)
54 if tt.wantStatus != gotStatus {
55 t.Errorf("reached status expected: %v, got: %v", tt.wantStatus, gotStatus)
60 func TestModCacheInfo(t *testing.T) {
62 dirs: make(map[string]*directoryPackageInfo),
67 info directoryPackageInfo
71 info: directoryPackageInfo{
72 status: directoryScanned,
74 nonCanonicalImportPath: "example.com/mypackage",
79 info: directoryPackageInfo{
80 status: directoryScanned,
81 err: fmt.Errorf("bad package"),
85 dir: "mypackage/other",
86 info: directoryPackageInfo{
87 dir: "mypackage/other",
88 nonCanonicalImportPath: "example.com/mypackage/other",
93 for _, d := range dirInfo {
94 m.Store(d.dir, d.info)
97 for _, d := range dirInfo {
98 val, ok := m.Load(d.dir)
100 t.Errorf("directory not loaded: %s", d.dir)
103 if !reflect.DeepEqual(d.info, val) {
104 t.Errorf("expected: %v, got: %v", d.info, val)
108 var wantKeys []string
109 for _, d := range dirInfo {
110 wantKeys = append(wantKeys, d.dir)
112 sort.Strings(wantKeys)
115 sort.Strings(gotKeys)
117 if len(gotKeys) != len(wantKeys) {
118 t.Errorf("different length of keys. expected: %d, got: %d", len(wantKeys), len(gotKeys))
121 for i, want := range wantKeys {
122 if want != gotKeys[i] {
123 t.Errorf("%d: expected %s, got %s", i, want, gotKeys[i])