From 964359ea22cd4c6ee6f2431ec39dc2a2c643b885 Mon Sep 17 00:00:00 2001 From: Harald Nordgren Date: Tue, 18 Sep 2018 15:44:55 +0200 Subject: [PATCH] Create 'TestVendoredBuildConstraints' --- pkg/moq/moq_test.go | 22 +++++++++++++++++++ .../buildconstraints/user/user.go | 9 ++++++++ .../matryer/buildconstraints/go17.go | 12 ++++++++++ .../matryer/buildconstraints/pre_go17.go | 6 +++++ 4 files changed, 49 insertions(+) create mode 100644 pkg/moq/testpackages/buildconstraints/user/user.go create mode 100644 pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/go17.go create mode 100644 pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/pre_go17.go diff --git a/pkg/moq/moq_test.go b/pkg/moq/moq_test.go index 4322869..5c67fbb 100644 --- a/pkg/moq/moq_test.go +++ b/pkg/moq/moq_test.go @@ -197,6 +197,28 @@ func TestVendoredPackages(t *testing.T) { } } +func TestVendoredBuildConstraints(t *testing.T) { + m, err := New("testpackages/buildconstraints/user", "") + if err != nil { + t.Fatalf("moq.New: %s", err) + } + var buf bytes.Buffer + err = m.Mock(&buf, "Service") + if err != nil { + t.Errorf("mock error: %s", err) + } + s := buf.String() + // assertions of things that should be mentioned + var strs = []string{ + `"github.com/matryer/buildconstraints"`, + } + for _, str := range strs { + if !strings.Contains(s, str) { + t.Errorf("expected but missing: \"%s\"", str) + } + } +} + // TestDotImports tests for https://github.com/matryer/moq/issues/21. func TestDotImports(t *testing.T) { preDir, err := os.Getwd() diff --git a/pkg/moq/testpackages/buildconstraints/user/user.go b/pkg/moq/testpackages/buildconstraints/user/user.go new file mode 100644 index 0000000..10d3d9a --- /dev/null +++ b/pkg/moq/testpackages/buildconstraints/user/user.go @@ -0,0 +1,9 @@ +package user + +import "github.com/matryer/buildconstraints" + +// Service does something good with computers. +type Service interface { + DoSomething(buildconstraints.SomeType) error +} + diff --git a/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/go17.go b/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/go17.go new file mode 100644 index 0000000..a03f6f5 --- /dev/null +++ b/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/go17.go @@ -0,0 +1,12 @@ +// +build go1.7 + +package buildconstraints + +var someVariable = "Value 1" + +// SomeType is just some old type. +type SomeType struct { + // Truth indicates whether true is true or not. Computers. + Truth bool +} + diff --git a/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/pre_go17.go b/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/pre_go17.go new file mode 100644 index 0000000..3fc99b6 --- /dev/null +++ b/pkg/moq/testpackages/buildconstraints/vendor/github.com/matryer/buildconstraints/pre_go17.go @@ -0,0 +1,6 @@ +// +build !go1.7 + +package buildconstraints + +var someVariable = "Value 2" +