Skip to content

Release v0.0.5

Compare
Choose a tag to compare
@vladimirvivien vladimirvivien released this 10 Dec 21:48
· 412 commits to main since this release
fee1391

This release is packed with new and super useful functionalities to continue to make it easy to create end-to-end tests, including:

The new wait and conditions package

The wait and conditions packages allow test writers to express cluster conditions to wait for before proceeding, during a test execution. The API takes the same simple and familiar approach by providing an expressive way to construct conditional predicates as shown below:

// Test to wait for a deployment condition
func TestDeployment(t *testing.T) {
    res := envconf.New().Client().Resources() // get default resource manger
    deployment := createDeployment("d2") // create a deployment object

    // wait for the deployment to become at least 50% available within 1 minute
    err = wait.For(conditions.New(res).ResourceMatch(&dep, func(object k8s.Object) bool {
        d := object.(*appsv1.Deployment)
	return float64(d.Status.ReadyReplicas)/float64(*d.Spec.Replicas) >= 0.50
    }), wait.WithTimeout(time.Minute*1))
    ...
}

Pre-defined conditions

To make test-writing more convenient, the package comes with a long list of pre-defined conditions that can be used in your tests as shown below:

// Test to wait for a deployment condition
func TestDeploymentConditionMatch(t *testing.T) {
    res := envconf.New().Client().Resources() // get default resource manger
    deployment := createDeployment("d2") // create a deployment object

    // wait for deployment condition (deployment is available)
    err := wait.For(conditions.New(res).DeploymentConditionMatch(deployment, appsv1.DeploymentAvailable, v1.ConditionTrue))
    ...
}

Other pre-defined conditions

  • ResourceScaled - resource scaled to a specified replica number
  • ResourceMatch - matches a provided condition
  • ResourceListN - number of available resource list matches a provided number
  • ResourcesFound specified resource(s) are found in the cluster
  • ResourcesDeleted specified resource(s) has/have been deleted
  • JobConditionMatch - job status matches a specified condition
  • JobFailed / JobCompleted - waits for specified job to fail / job to complete
  • DeploymentMatch - deployment matches a provided condition/status
  • PodConditionMatch - pod matches a status or condition
  • PodPhaseMatch - pod matches a specified phase
  • PodReady / PodRunning - specified pod is ready / pod is running
  • ContainersReady - wait for containers in specified pod to be ready

Table-driven test representation

This release introduces table-driven tests as a convenient way to define tests

var test = env.New()
...
func TestTableDriven(t *testing.T) {
	// feature 1
	table0 := features.Table{
		{
			Name: "less than equal 64",
			Assessment: func(ctx context.Context, t *testing.T, config *envconf.Config) context.Context {
				rnd := ctx.Value("randsrc").(*rand.Rand) 
				lim := ctx.Value("limit").(int32) 
				if rnd.Int31n(lim) > 64 {
					t.Log("limit should be less than 64")
				}
				return ctx
			},
		},
		{
			Name: "more than than equal 128",
			Assessment: func(ctx context.Context, t *testing.T, config *envconf.Config) context.Context {
				rnd := ctx.Value("randsrc").(*rand.Rand)  // in real test, check asserted type
				lim := ctx.Value("limit").(int32) // check type assertion
				if rnd.Int31n(lim) > 128 {
					t.Log("limit should be less than 128")
				}
				return ctx
			},
		},
	}.Build("Random numbers").Feature()
        test.Test(t, table0.Build().Feature())

Other enhancements

  • Integration of klog package for leveled logging
  • Ability to specify custom configuration for KinD during tests
  • Ability to specify docker image and local image when launching KinD clusters during tests

Changelog

c4a197e Support for table-driven tests
67ca656 add condition helper for checking deployment status and methods for waiting on object lists
041d212 support loading images into kind cluster
0001077 GIT-77: enable klog based generic logging infra with verbose handlers
bdb0467 use stdout from kind command when writing kubeconfig
11cb5d1 GIT-81: fix syntax highlighting for klient Design Doc
6d24c50 Fix typos in the doc
40fee41 fetch kubeconfig if cluster is already created
b79a789 GIT-60: enable helper function for conditional waits