AmitKumarDas/Decisions

k8s: control loop: integration test & e2e test - design

AmitKumarDas opened this issue · 1 comments

Use Case: I want to implement simple test logic to perform integration test of my k8s controller. I do not want to depend on full fledged k8s environment. It will be ideal to just depend on k8s & etcd binaries.

Thoughts:

  • Install k8s & etcd binaries
  • Start my binary from _test.go file
  • Write test cases in TestXYZ(t *testing.T) functions

High Level Design:

package test

type Action string

const (
   ActionCreate Action = "create"
   ActionApply Action = "apply"
   ActionDelete  Action = "delete"
   ActionUpdate Action = "update"
)

type Expect struct {
  Match *ResourceSelector
  EqualsToCount *int
  NotEqualsToCount *int
  EqualsTo *unstructed.Unstructured
  EqualsToAll []*unstructed.Unstructured
  Contains *unstructed.Unstructured
  ContainsAll []*unstructed.Unstructured
  RetryTimes *int
  RetryInterval *time.Duration
}

type Context struct {
  StepIndex int
}

type Response struct {
  Desc *string
  Object *unstructured.Unstructured
  Client dynamic.client // check if this is really required?
  Action *Action
  Times *int
  Random *bool
  Expect *Expect
}

type Testable struct {
  Desc *string

  // array of functions that get executed in the given order
  Steps []func(ctx Context, resp *Response) error
}