aboutsummaryrefslogtreecommitdiff
path: root/internal/fetchdatasource/fetchdatasource_test.go
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2021-08-26 06:36:22 -0400
committerJonathan Amsterdam <jba@google.com>2021-08-26 13:55:16 +0000
commitf6f5076d4026eb90c4e6603f2b56b86402fc0bfb (patch)
treed391fbb14ce7daeab1fdac6b5d009d0ea3b2fd07 /internal/fetchdatasource/fetchdatasource_test.go
parent0eeccf082fa68b8e061bdd376a923e04d6073d0f (diff)
downloadgo-x-pkgsite-f6f5076d4026eb90c4e6603f2b56b86402fc0bfb.tar.xz
internal/fetchdatasource: handle build contexts properly
GetUnit returns a Unit with its Documentation set to a matching BuildContext. This is the same behavior as postgres.DB.GetUnit. For golang/go#47780 Change-Id: I2bc23b7bc5a006e78bec54f6f3229e59ab5a03ef Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/345269 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'internal/fetchdatasource/fetchdatasource_test.go')
-rw-r--r--internal/fetchdatasource/fetchdatasource_test.go41
1 files changed, 40 insertions, 1 deletions
diff --git a/internal/fetchdatasource/fetchdatasource_test.go b/internal/fetchdatasource/fetchdatasource_test.go
index 995dfad9..e807ec7a 100644
--- a/internal/fetchdatasource/fetchdatasource_test.go
+++ b/internal/fetchdatasource/fetchdatasource_test.go
@@ -449,7 +449,7 @@ func TestLocalGetUnitMeta(t *testing.T) {
}
}
-func TestLocalGetUnit(t *testing.T) {
+func TestGetUnit(t *testing.T) {
// This is a simple test to verify that data is fetched correctly. The
// return value of FetchResult is tested in internal/fetch so no need
// to repeat it.
@@ -509,6 +509,45 @@ func TestLocalGetUnit(t *testing.T) {
}
}
+func TestBuildConstraints(t *testing.T) {
+ // The Unit returned by GetUnit should have a single Documentation that
+ // matches the BuildContext argument.
+ ctx, ds, teardown := setup(t, defaultTestModules, true)
+ defer teardown()
+
+ um := &internal.UnitMeta{
+ Path: "example.com/build-constraints/cpu",
+ ModuleInfo: internal.ModuleInfo{
+ ModulePath: "example.com/build-constraints",
+ Version: version.Latest,
+ },
+ }
+ for _, test := range []struct {
+ in, want internal.BuildContext
+ }{
+ {internal.BuildContext{}, internal.BuildContextLinux},
+ {internal.BuildContextLinux, internal.BuildContextLinux},
+ {internal.BuildContextDarwin, internal.BuildContextDarwin},
+ {internal.BuildContext{GOOS: "LiverPaté", GOARCH: "DeTriomphe"}, internal.BuildContext{}},
+ } {
+ t.Run(test.in.String(), func(t *testing.T) {
+ u, err := ds.GetUnit(ctx, um, internal.AllFields, test.in)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if test.want == (internal.BuildContext{}) {
+ if len(u.Documentation) != 0 {
+ t.Error("got docs, want none")
+ }
+ } else if n := len(u.Documentation); n != 1 {
+ t.Errorf("got %d docs, want 1", n)
+ } else if got := u.Documentation[0].BuildContext(); got != test.want {
+ t.Errorf("got %s, want %s", got, test.want)
+ }
+ })
+ }
+}
+
func TestCache(t *testing.T) {
ds := Options{}.New()
m1 := &internal.Module{}