From 67170e739d9f9c6c74ec02a6087c3e08010f20ee Mon Sep 17 00:00:00 2001 From: Robert van Gent Date: Thu, 15 Nov 2018 10:11:59 -0800 Subject: [PATCH] wire/tests: add a test for wire.Bind on an injector arg (google/go-cloud#708) --- .../wire/testdata/BindInjectorArg/foo/foo.go | 43 +++++++++++++++++++ .../wire/testdata/BindInjectorArg/foo/wire.go | 30 +++++++++++++ internal/wire/testdata/BindInjectorArg/pkg | 1 + .../BindInjectorArg/want/wire_errs.txt | 1 + 4 files changed, 75 insertions(+) create mode 100644 internal/wire/testdata/BindInjectorArg/foo/foo.go create mode 100644 internal/wire/testdata/BindInjectorArg/foo/wire.go create mode 100644 internal/wire/testdata/BindInjectorArg/pkg create mode 100644 internal/wire/testdata/BindInjectorArg/want/wire_errs.txt diff --git a/internal/wire/testdata/BindInjectorArg/foo/foo.go b/internal/wire/testdata/BindInjectorArg/foo/foo.go new file mode 100644 index 0000000..de70ada --- /dev/null +++ b/internal/wire/testdata/BindInjectorArg/foo/foo.go @@ -0,0 +1,43 @@ +// Copyright 2018 The Go Cloud Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" +) + +func main() { + fmt.Println(inject(&Foo{"hello"}).Name) +} + +type Fooer interface { + Foo() string +} + +type Foo struct { + f string +} + +func (f *Foo) Foo() string { + return f.f +} + +type Bar struct { + Name string +} + +func NewBar(fooer Fooer) *Bar { + return &Bar{Name: fooer.Foo()} +} diff --git a/internal/wire/testdata/BindInjectorArg/foo/wire.go b/internal/wire/testdata/BindInjectorArg/foo/wire.go new file mode 100644 index 0000000..1bc6a4f --- /dev/null +++ b/internal/wire/testdata/BindInjectorArg/foo/wire.go @@ -0,0 +1,30 @@ +// Copyright 2018 The Go Cloud Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//+build wireinject + +package main + +import ( + "github.com/google/go-cloud/wire" +) + +func inject(foo *Foo) *Bar { + // Currently fails because wire.Bind can't see injector args (#547). + wire.Build( + NewBar, + wire.Bind(new(Fooer), &Foo{}), + ) + return nil +} diff --git a/internal/wire/testdata/BindInjectorArg/pkg b/internal/wire/testdata/BindInjectorArg/pkg new file mode 100644 index 0000000..f7a5c8c --- /dev/null +++ b/internal/wire/testdata/BindInjectorArg/pkg @@ -0,0 +1 @@ +example.com/foo diff --git a/internal/wire/testdata/BindInjectorArg/want/wire_errs.txt b/internal/wire/testdata/BindInjectorArg/want/wire_errs.txt new file mode 100644 index 0000000..31c37a8 --- /dev/null +++ b/internal/wire/testdata/BindInjectorArg/want/wire_errs.txt @@ -0,0 +1 @@ +example.com/foo/wire.go:x:y: no binding for *example.com/foo.Foo \ No newline at end of file