Skip to content
プロジェクト

概要

Kubernetes クラスターで動作するコンポーネントのエンドツーエンドテスト向け Go フレームワークです。

システム・インフラ

この数値の測り方

計測したスター増加

24時間
0
7日間
+2
15日間
+4
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

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.CreateCluster(kind.NewProvider(), kindClusterName),
		envfuncs.CreateNamespace(namespace),
	)

	// Use pre-defined environment funcs to teardown kind cluster after tests
	testenv.Finish(
		envfuncs.DeleteNamespace(namespace),
		envfuncs.DestroyCluster(kindClusterName),
	)

	// 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.

関連プロジェクトを探す

読み込み中…