AmitKumarDas / Decisions

Apache License 2.0
10 stars 3 forks source link

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

Open AmitKumarDas opened 4 years ago

AmitKumarDas commented 4 years ago

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.

AmitKumarDas commented 4 years ago

Thoughts:

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
}