10 func TestDirectoryPackageInfoReachedStatus(t *testing.T) {
12 info directoryPackageInfo
13 target directoryPackageStatus
18 info: directoryPackageInfo{
19 status: directoryScanned,
22 target: directoryScanned,
26 info: directoryPackageInfo{
27 status: directoryScanned,
28 err: fmt.Errorf("error getting to directory scanned"),
30 target: directoryScanned,
35 info: directoryPackageInfo{},
36 target: directoryScanned,
41 for _, tt := range tests {
42 gotStatus, gotErr := tt.info.reachedStatus(tt.target)
45 t.Errorf("unexpected error: %s", gotErr)
50 if tt.wantStatus != gotStatus {
51 t.Errorf("reached status expected: %v, got: %v", tt.wantStatus, gotStatus)
56 func TestModCacheInfo(t *testing.T) {
58 dirs: make(map[string]*directoryPackageInfo),
63 info directoryPackageInfo
67 info: directoryPackageInfo{
68 status: directoryScanned,
70 nonCanonicalImportPath: "example.com/mypackage",
75 info: directoryPackageInfo{
76 status: directoryScanned,
77 err: fmt.Errorf("bad package"),
81 dir: "mypackage/other",
82 info: directoryPackageInfo{
83 dir: "mypackage/other",
84 nonCanonicalImportPath: "example.com/mypackage/other",
89 for _, d := range dirInfo {
90 m.Store(d.dir, d.info)
93 for _, d := range dirInfo {
94 val, ok := m.Load(d.dir)
96 t.Errorf("directory not loaded: %s", d.dir)
99 if !reflect.DeepEqual(d.info, val) {
100 t.Errorf("expected: %v, got: %v", d.info, val)
104 var wantKeys []string
105 for _, d := range dirInfo {
106 wantKeys = append(wantKeys, d.dir)
108 sort.Strings(wantKeys)
111 sort.Strings(gotKeys)
113 if len(gotKeys) != len(wantKeys) {
114 t.Errorf("different length of keys. expected: %d, got: %d", len(wantKeys), len(gotKeys))
117 for i, want := range wantKeys {
118 if want != gotKeys[i] {
119 t.Errorf("%d: expected %s, got %s", i, want, gotKeys[i])