Skip to content

Implementation of Custom Gomege Matchers which similar to how it is used in testing kubernetes code

License

Notifications You must be signed in to change notification settings

DiptoChakrabarty/custom-gomega-matcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Custom Gomega Matcher

This Repository has code to implement custom gomega matcher

Check out a detailed blog here

As per documentation as found here we can develop custom gomega matchers which can extend the power of our testing

type GomegaMatcher interface {
    Match(actual interface{}) (success bool, err error)
    FailureMessage(actual interface{}) (message string)
    NegatedFailureMessage(actual interface{}) (message string)
}

Custom Gomega Matchers must fall under this interface , hence there has to be three methods defined for our objects.

Files Present

  • human/human.go
    • This contains the Person struct which is to be tested
    • This struct age attribute is tested
    • The file also contains relevant methods to implement the gomega matcher
type Person struct {
	age []int
}
  • human_test.go
    • The human_test.go file contains the implementation of the Person struct
    • The tests follow the format followed by kubernetes sub projects which I have observed

The tests follow a format of

struct {
		name        string
		targetAge   []int
		humanTarget human.Person
		want        bool
	}
  • Here name defines name of the test
  • targetAge is the values we give
  • humanTarget is the Person struct we provide
  • want identifies if true or false

About

Implementation of Custom Gomege Matchers which similar to how it is used in testing kubernetes code

Topics

Resources

License

Stars

Watchers

Forks

Languages