Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit b869afc

Browse files
vangentzombiezen
authored andcommitted
wire/tests: Add a test that defines a ProviderSet with a binding but no (#121)
corresponding concrete type. The current error message is poor and should be improved.
1 parent ab2332a commit b869afc

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2019 The Wire Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/google/wire"
21+
)
22+
23+
func main() {
24+
fmt.Println(injectFoo())
25+
}
26+
27+
type fooer interface {
28+
Do() string
29+
}
30+
31+
type foo struct{}
32+
33+
func (f *foo) Do() string {
34+
return "did foo"
35+
}
36+
37+
func newFoo() *foo {
38+
return &foo{}
39+
}
40+
41+
var (
42+
setA = wire.NewSet(newFoo)
43+
// This set is invalid because it has a wire.Bind but no matching provider.
44+
// From the user guide:
45+
// Any set that includes an interface binding must also have a provider in
46+
// the same set that provides the concrete type.
47+
setB = wire.NewSet(wire.Bind(new(fooer), new(foo)))
48+
setC = wire.NewSet(setA, setB)
49+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019 The Wire Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//+build wireinject
16+
17+
package main
18+
19+
import (
20+
"github.com/google/wire"
21+
)
22+
23+
func injectFoo() *foo {
24+
wire.Build(setC)
25+
return nil
26+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example.com/foo
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
example.com/foo/foo.go:x:y: no binding for *example.com/foo.foo

0 commit comments

Comments
 (0)