Skip to content

Provide testable log/events facilities to assert to during the test #2

@ppxl

Description

@ppxl

Using the go test mechanism in conjuncion with testcluster-go is the go-to (pun intended) of this project. Asserting information of logs and events should be the main point to get a better testing experience.

My idea is something along the lines of this pseudo-code:

func Test_myOperator(t *testing.T, c *testCluster) {
  // given
  err := c.Apply(operatorYaml)
  require.NoError(t, err)

  // when
  err := c.Apply(aristotelesCustomResource)
  require.NoError(t, err)

  // then
  within(10 * time.Seconds, func() error
     lo := c.Lookout("k8s.example.com/v1/YourResource", "v1/Pod")
     events := lo.Resource(YourResource).ByName("aristoteles").Events(t) // handle should fail with errors to reduce the mental load
     events.Contains("Quality is not an act, it is a habit.") // types and issuer should play into this as well
     
     arisPod := lo.Resource(Pod).BySelector("app:aristoteles")
     status := arisPod.Status(t)
     status.Contains("Running") // could be more specific to certain status fields?

     logs := arisPod.Logs(t)
     logs.Contains("Pod started successfully on port 1234")
  )
}

Edit: I figure this is rather an architecture design issue, but here goes. These are the key points:

  • Resource selection must be achived (here: the look-out who sits in the crow's nest of your ship)
  • The selected resource is imaged as an object that receives *testing.T in order to
    • control the test failure/success,
    • avoid helper files in the stacktrace,
    • and finally allow to include a comfy assertion framework
  • added value of this is inspection and assertion of resource attributes during the test run-time
  • ideas of functors
    • Events() - events provided to the requested resource
    • Logs() - pod logs - how to separate by container? what about init - or crashlooped containers?
    • Status() - has every resource a general status? most probably not
      • probably do some type cast or generic magic to return the desired type previously mentioned as GVK. Maybe the expected golang type from the CRD type is better for casting)
    • Timeout() - eventual consistency makes timeout of tests necessary
    • each functor allows
      • at least generic assertions like those from stretchr/testify
      • a DSL way of allowing to enhance assertions to aid more use-case/business-specific needs

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions