Skip to content

Commit d6ffd93

Browse files
authored
Merge pull request #231 from hustjieke/feature_support_e2e_stage1
test: e2e prototype framework stage 1 #199
2 parents 0a4b2ab + dd47c6a commit d6ffd93

File tree

5 files changed

+186
-1
lines changed

5 files changed

+186
-1
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Image URL to use all building/pushing image targets
32
IMG ?= controller:latest
43
SIDECAR_IMG ?= sidecar:latest
@@ -113,3 +112,8 @@ GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
113112
rm -rf $$TMP_DIR ;\
114113
}
115114
endef
115+
116+
# E2E tests
117+
###########
118+
e2e-local:
119+
go test -v ./test/e2e $(G_ARGS) -timeout 20m

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
k8s.io/api v0.21.2
1818
k8s.io/apimachinery v0.21.2
1919
k8s.io/client-go v0.21.2
20+
k8s.io/component-base v0.21.2
2021
k8s.io/klog/v2 v2.8.0
2122
sigs.k8s.io/controller-runtime v0.9.2
2223
)

test/e2e/e2e.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"testing"
21+
)
22+
23+
func RunE2ETests(t *testing.T) {
24+
// empty now
25+
}

test/e2e/e2e_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Copyright 2015 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"flag"
21+
"fmt"
22+
"math/rand"
23+
"os"
24+
"testing"
25+
"time"
26+
27+
"k8s.io/component-base/version"
28+
29+
"github.com/radondb/radondb-mysql-kubernetes/test/e2e/framework"
30+
)
31+
32+
// handleFlags sets up all flags and parses the command line.
33+
func handleFlags() {
34+
framework.RegisterCommonFlags(flag.CommandLine)
35+
flag.Parse()
36+
}
37+
38+
func TestMain(m *testing.M) {
39+
var versionFlag bool
40+
flag.CommandLine.BoolVar(&versionFlag, "version", false, "Displays version information.")
41+
42+
// Register test flags, then parse flags.
43+
handleFlags()
44+
45+
if versionFlag {
46+
fmt.Printf("%s\n", version.Get())
47+
os.Exit(0)
48+
}
49+
50+
rand.Seed(time.Now().UnixNano())
51+
os.Exit(m.Run())
52+
}
53+
54+
func TestE2E(t *testing.T) {
55+
RunE2ETests(t)
56+
}

test/e2e/framework/test_context.go

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Copyright 2016 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package framework
18+
19+
import (
20+
"flag"
21+
"fmt"
22+
"os"
23+
24+
"k8s.io/client-go/tools/clientcmd"
25+
)
26+
27+
const (
28+
// TODO(gry): make sure the default port, do we need it?
29+
defaultHost = "https://127.0.0.1:6443"
30+
31+
// DefaultNumNodes is the number of nodes. If not specified, then number of nodes is auto-detected
32+
DefaultNumNodes = -1
33+
)
34+
35+
// TestContextType contains test settings and global state. Due to
36+
// historic reasons, it is a mixture of items managed by the test
37+
// framework itself, cloud providers and individual tests.
38+
// The goal is to move anything not required by the framework
39+
// into the code which uses the settings.
40+
//
41+
// The recommendation for those settings is:
42+
// - They are stored in their own context structure or local
43+
// variables.
44+
// - The standard `flag` package is used to register them.
45+
// The flag name should follow the pattern <part1>.<part2>....<partn>
46+
// where the prefix is unlikely to conflict with other tests or
47+
// standard packages and each part is in lower camel case. For
48+
// example, test/e2e/storage/csi/context.go could define
49+
// storage.csi.numIterations.
50+
// - framework/config can be used to simplify the registration of
51+
// multiple options with a single function call:
52+
// var storageCSI {
53+
// NumIterations `default:"1" usage:"number of iterations"`
54+
// }
55+
// _ config.AddOptions(&storageCSI, "storage.csi")
56+
// - The direct use Viper in tests is possible, but discouraged because
57+
// it only works in test suites which use Viper (which is not
58+
// required) and the supported options cannot be
59+
// discovered by a test suite user.
60+
//
61+
// Test suite authors can use framework/viper to make all command line
62+
// parameters also configurable via a configuration file.
63+
type TestContextType struct {
64+
KubeConfig string
65+
KubeContext string
66+
Host string
67+
68+
OutputDir string
69+
70+
// If set to true test will dump data about the namespace in which test was running.
71+
DumpLogsOnFailure bool
72+
// Disables dumping cluster log from master and nodes after all tests.
73+
DisableLogDump bool
74+
TimeoutSeconds int
75+
}
76+
77+
// TestContext should be used by all tests to access common context data.
78+
var TestContext TestContextType
79+
80+
// RegisterCommonFlags registers flags common to all e2e test suites.
81+
// The flag set can be flag.CommandLine (if desired) or a custom
82+
// flag set that then gets passed to viperconfig.ViperizeFlags.
83+
//
84+
// The other Register*Flags methods below can be used to add more
85+
// test-specific flags. However, those settings then get added
86+
// regardless whether the test is actually in the test suite.
87+
//
88+
// For tests that have been converted to registering their
89+
// options themselves, copy flags from test/e2e/framework/config
90+
// as shown in HandleFlags.
91+
func RegisterCommonFlags(flags *flag.FlagSet) {
92+
flags.StringVar(&TestContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.")
93+
flags.StringVar(&TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
94+
flags.StringVar(&TestContext.Host, "host", "", fmt.Sprintf("The host, or apiserver, to connect to. Will default to %s if this argument and --kubeconfig are not set.", defaultHost))
95+
flags.StringVar(&TestContext.OutputDir, "e2e-output-dir", "/tmp", "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.")
96+
flags.BoolVar(&TestContext.DumpLogsOnFailure, "dump-logs-on-failure", true, "If set to true test will dump data about the namespace in which test was running.")
97+
flags.BoolVar(&TestContext.DisableLogDump, "disable-log-dump", false, "If set to true, logs from master and nodes won't be gathered after test run.")
98+
flag.IntVar(&TestContext.TimeoutSeconds, "pod-wait-timeout", 100, "Timeout to wait for a pod to be ready.")
99+
}

0 commit comments

Comments
 (0)