Coder Social home page Coder Social logo

mitchmckenzie / e2e-framework Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kubernetes-sigs/e2e-framework

0.0 0.0 0.0 592 KB

A Go framework for end-to-end testing of components running in Kubernetes clusters.

License: Apache License 2.0

Shell 3.13% Go 95.44% Makefile 1.43%

e2e-framework's Introduction

E2E Framework

godoc

A Go framework for end-to-end testing of components running in Kubernetes clusters.

The primary goal of this project is to provide a go test(able) framework that uses the native Go testing API to define end-to-end tests suites that can be used to test Kubernetes components. Some additional goals include:

  • Provide a sensible programmatic API to compose tests
  • Leverage Go's testing API to compose test suites
  • Expose packages that are easy to programmatically consume
  • Collection of helper functions that abstracts Client-Go functionalities
  • Rely on built-in Go test features to easily select/filter tests to run during execution
  • And more

For more detail, see the design document.

Getting started

The Go package is designed to be integrated directly in your test. Simply update your project to pull the desired Go modules:

go get sigs.k8s.io/e2e-framework/pkg/env
go get sigs.k8s.io/e2e-framework/klient

Using the framework

The framework uses the built-in Go testing framework directly to define and run tests.

Setup TestMain

Use function TestMain to define package-wide testing steps and configure behavior. The following examples uses pre-defined steps to create a KinD cluster before running any test in the package:

var (
	testenv env.Environment
)

func TestMain(m *testing.M) {
    testenv = env.New()
    kindClusterName := envconf.RandomName("my-cluster", 16)
    namespace := envconf.RandomName("myns", 16)

    // Use pre-defined environment funcs to create a kind cluster prior to test run
    testenv.Setup(
        envfuncs.CreateKindCluster(kindClusterName),
    )

    // Use pre-defined environment funcs to teardown kind cluster after tests
    testenv.Finish(
        envfuncs.DeleteNamespace(namespace),
    )
    
    // launch package tests
    os.Exit(testenv.Run(m))
}

Define a test function

Use a Go test function to define features to be tested as shown below:

func TestKubernetes(t *testing.T) {
    f1 := features.New("count pod").
        WithLabel("type", "pod-count").
        Assess("pods from kube-system", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
            var pods corev1.PodList
            err := cfg.Client().Resources("kube-system").List(context.TODO(), &pods)
            if err != nil {
                t.Fatal(err)
            }
            if len(pods.Items) == 0 {
                t.Fatal("no pods in namespace kube-system")
            }
            return ctx
        }).Feature()

    f2 := features.New("count namespaces").
        WithLabel("type", "ns-count").
        Assess("namespace exist", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
            var nspaces corev1.NamespaceList
            err := cfg.Client().Resources().List(context.TODO(), &nspaces)
            if err != nil {
                t.Fatal(err)
            }
            if len(nspaces.Items) == 1 {
                t.Fatal("no other namespace")
            }
            return ctx
        }).Feature()
        
    // test feature
    testenv.Test(t, f1, f2)
}

Running the test

Use the Go testing tooling to run the tests in the package as shown below. The following would run all tests except those with label type=ns-count:

go test ./package -args --skip-labels="type=ns-count"

Examples

See the ./examples directory for additional examples showing how to use the framework.

Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the community page.

You can reach the maintainers of this project at:

Code of conduct

Participation in the Kubernetes community is governed by the Kubernetes Code of Conduct.

e2e-framework's People

Contributors

k8s-ci-robot avatar vladimirvivien avatar harshanarayana avatar shwethakumbla avatar cpanato avatar johnschnake avatar crandles avatar matrus2 avatar mhofstetter avatar tech-geek29 avatar andrewsykim avatar v0lkc avatar fracasula avatar nikhita avatar ronensc avatar 0xff-dev avatar spiffxp avatar ernado avatar bentheelder avatar fredrb avatar helayoty avatar komalsukhani avatar tklauser avatar twpayne avatar jayunit100 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.