Giter Site home page Giter Site logo

oxyno-zeta / gomock-extra-matcher Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 1.0 109 KB

Gomock Extra Matchers (Struct, Map, IntRange, StringRegexp)

Home Page: https://oxyno-zeta.github.io/gomock-extra-matcher/

License: Apache License 2.0

Go 83.26% Makefile 5.37% JavaScript 11.03% Shell 0.34%
gomock gomock-matchers tests matcher mock

gomock-extra-matcher's Introduction

gomock-extra-matcher

Go Doc CircleCI Go Report Card

Coverage Status GitHub license GitHub release (latest by date)


Menu

Why ?

I've created this library because I cannot find such a library like this one and I don't want to create specific matcher for each structure, each map, ... in all tests that I have and can write.

Moreover, creating specific matcher need maintenance code and this is time consumption.

I'm sure that I'm not the only one that what to avoid all of this :) .

How to use ?

Import the library in your tests files:

import "github.com/oxyno-zeta/gomock-extra-matcher"

Use it in your gomock instance:

mock.EXPECT().DoSomething(extra.StringRegexpMatcher(`^[a-z]+\[[0-9]+\]$`))

Matchers

IntRangeMatcher

Explanation

This matcher will allow to test that an int is inside a range. Here it is considered that input can be equal to the lower bound and the same for the upper bound.

Example

Here is an example of usage:

mock.EXPECT().DoSomething(extra.IntRangeMatcher(lowerBound, upperBound))

StringRegexpMatcher

Explanation

This matcher will allow to test that a string is validating a Regexp.

Example

Here is an example of usage:

mock.EXPECT().DoSomething(extra.StringRegexpMatcher(`^[a-z]+\[[0-9]+\]$`))

MapMatcher

Explanation

This matcher will allow to test map key and map value.

To this one, it is possible to give a gomock matcher to a key and also to the value.

The Key function is chainable. It is also possible to more than one test per key.

Example

Here are some example of usage:

// Here we consider a map[string]string as input
mock.EXPECT().DoSomething(extra.MapMatcher().Key("key1", "value1").Key(gomock.Any(), "value1").Key("key1", gomock.Not("value2")))

StructMatcher

Explanation

This matcher will allow to test public fields of a structure (Only public ones. Reflect can't manage private fields...).

To this matcher, it is possible to give either a gomock matcher or either a real value for validation.

The Field function is chainable. It is also possible to more than one test per field.

Example

// Here we consider a struct as this one
/*
type Fake struct {
    Name string
    Data map[string]string
}
*/
mock.EXPECT().DoSomething(extra.StructMatcher().Field("Name", "value1").Field("Data", gomock.Eq(map[string]string{"fake":"value"})))

OrMatcher

Explanation

This matcher will allow to test multiple matchers with a logical "OR" between them. This will stop at first match.

Example

mock.EXPECT().DoSomething(extra.OrMatcher(gomock.Eq(1), gomock.Eq(10), gomock.Eq(15)))

Thanks

  • My wife BH to support me doing this

Author

  • Oxyno-zeta (Havrileck Alexandre)

License

Apache 2.0 (See in LICENSE)

gomock-extra-matcher's People

Contributors

oxyno-zeta avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

alexdouze

gomock-extra-matcher's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v4@3df4ab11eba7bda6032a0b82a6bb43b11571feac
  • golangci/golangci-lint-action v3
  • actions/checkout v4@3df4ab11eba7bda6032a0b82a6bb43b11571feac
  • actions/setup-go v4
.github/workflows/labeler.yml
  • actions/labeler v4
  • ubuntu 22.04
.github/workflows/size.yml
  • pascalgn/size-label-action b1f4946f381d38d3b5960f76b514afdfef39b609
  • ubuntu 22.04
.github/workflows/stale.yml
  • actions/stale v8
  • ubuntu 22.04
gomod
go.mod
  • go 1.15
  • go.uber.org/mock v0.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

We want you to stop depending on https://github.com/golang/mock

Is your feature request related to a problem? Please describe.
Your package depends on https://github.com/golang/mock, but https://github.com/golang/mock became read-only on June 28, 2023.

My project has also switched to https://github.com/uber-go/mock, but I am concerned about continuing to use your package because your package still depends on package A.

Describe the solution you'd like
I want them to stop relying on https://github.com/golang/mock and switch to https://github.com/uber-go/mock.

Describe alternatives you've considered

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.