1
0
mirror of https://github.com/golang/go synced 2024-10-01 09:38:36 -06:00
go/internal/imports/mod_cache_test.go
Suzy Mueller ee1fc86af2 internal/imports: use cache of mod cache pkgs in find packages
To check if a package is in a module that is in scope, the module
resolver checks if there are Go files that would be included in a
package in the directory matching the import path in scope.

If this directory is in the module cache and we have saved it as a
package, we know this directory contains Go files, and do not have to
read the directory.

Change-Id: I7c9365ce42c760ab95bc68b036212120895c89fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186922
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-29 20:29:44 +00:00

53 lines
1019 B
Go

package imports
import (
"fmt"
"testing"
)
func TestDirectoryPackageInfoReachedStatus(t *testing.T) {
tests := []struct {
info directoryPackageInfo
target directoryPackageStatus
wantStatus bool
wantError bool
}{
{
info: directoryPackageInfo{
status: directoryScanned,
err: nil,
},
target: directoryScanned,
wantStatus: true,
},
{
info: directoryPackageInfo{
status: directoryScanned,
err: fmt.Errorf("error getting to directory scanned"),
},
target: directoryScanned,
wantStatus: true,
wantError: true,
},
{
info: directoryPackageInfo{},
target: directoryScanned,
wantStatus: false,
},
}
for _, tt := range tests {
gotStatus, gotErr := tt.info.reachedStatus(tt.target)
if gotErr != nil {
if !tt.wantError {
t.Errorf("unexpected error: %s", gotErr)
}
continue
}
if tt.wantStatus != gotStatus {
t.Errorf("reached status expected: %v, got: %v", tt.wantStatus, gotStatus)
}
}
}