Skip to content

refactor controller_tests #136

Closed
Closed
@kuritka

Description

Refactor controller tests

  • to AAA form
  • split tests into functions

Follow standard template as shown below:

func TestReflectGeoTagInTheStatus(t *testing.T) {
 defer cleanup()
 init()
  //arrange
  //act
  //assert
}
func TestSomethingElse(t *testing.T) {
 defer cleanup()
 init()
  //arrange
  //act
  //assert
}
//this will be executed for each test that requires
func cleanup(){
   //cleaning env vars, resources etc
}
//this will be executed for each test that requires
func init(){
  // init reconcilers, clients etc.. whatever
}
//TestMain is reserved GO func. It says that: this will be executed only once for all tests. Don't use that if we don't need
func TestMain(m testing.M){
   //cleaning reasources for all tests i.e. remove cluster, or cloud resources etc... 
   defer TearDown()
   //prepare shared resources for all tests. i.e. create test cluster,  queue etc..
   InitForAllTests()
   t.Main()
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions