How to use Errorf method of gomock_test Package

Best Mock code snippet using gomock_test.Errorf

Run Mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

matchers_test.go

Source: matchers_test.go Github

copy
1// Copyright 2010 Google Inc.
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//     http://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
15package gomock_test
16
17import (
18	"errors"
19	"testing"
20
21	"github.com/golang/mock/gomock"
22	mock_matcher "github.com/golang/mock/gomock/mock_matcher"
23)
24
25func TestMatchers(t *testing.T) {
26	type e interface{}
27	type testCase struct {
28		matcher gomock.Matcher
29		yes, no []e
30	}
31	tests := []testCase{
32		testCase{gomock.Any(), []e{3, nil, "foo"}, nil},
33		testCase{gomock.Eq(4), []e{4}, []e{3, "blah", nil, int64(4)}},
34		testCase{gomock.Nil(),
35			[]e{nil, (error)(nil), (chan bool)(nil), (*int)(nil)},
36			[]e{"", 0, make(chan bool), errors.New("err"), new(int)}},
37		testCase{gomock.Not(gomock.Eq(4)), []e{3, "blah", nil, int64(4)}, []e{4}},
38	}
39	for i, test := range tests {
40		for _, x := range test.yes {
41			if !test.matcher.Matches(x) {
42				t.Errorf(`test %d: "%v %s" should be true.`, i, x, test.matcher)
43			}
44		}
45		for _, x := range test.no {
46			if test.matcher.Matches(x) {
47				t.Errorf(`test %d: "%v %s" should be false.`, i, x, test.matcher)
48			}
49		}
50	}
51}
52
53// A more thorough test of notMatcher
54func TestNotMatcher(t *testing.T) {
55	ctrl := gomock.NewController(t)
56	defer ctrl.Finish()
57
58	mockMatcher := mock_matcher.NewMockMatcher(ctrl)
59	notMatcher := gomock.Not(mockMatcher)
60
61	mockMatcher.EXPECT().Matches(4).Return(true)
62	if match := notMatcher.Matches(4); match {
63		t.Errorf("notMatcher should not match 4")
64	}
65
66	mockMatcher.EXPECT().Matches(5).Return(false)
67	if match := notMatcher.Matches(5); !match {
68		t.Errorf("notMatcher should match 5")
69	}
70}
71
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger Errorf code on LambdaTest Cloud Grid

Execute automation tests with Errorf on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)