diff --git a/test/e2e/dryrun.go b/test/e2e/dryrun.go index 2ad7d9f567..27dfbb20dd 100644 --- a/test/e2e/dryrun.go +++ b/test/e2e/dryrun.go @@ -20,47 +20,44 @@ import ( "context" "os" "os/exec" - "path" "strings" "testing" "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" -) -func getCurrentClusterDetails(clusterName string) (string, error) { - cmd := exec.Command("kwokctl", "get", "cluster", clusterName, "-o", "json") - output, err := cmd.Output() - if err != nil { - return "", err - } - out := string(output[:]) - return out, err -} + "sigs.k8s.io/kwok/pkg/utils/path" +) func loadExpectedClusterDetails(filepath string) (string, error) { data, err := os.ReadFile(filepath) if err != nil { return "", err } - out := string(data[:]) - return out, err + out := string(data) + return out, nil } -func CaseDryrun(clusterName string) *features.FeatureBuilder { +func CaseDryrun(clusterName string, kwokctlPath string, rootDir string) *features.FeatureBuilder { f := features.New("Dry run") f = f.Assess("test cluster dryrun", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context { - got, err := getCurrentClusterDetails(clusterName) - if err != nil { - t.Fatal("Could not get cluster details:", err) - } var expected string - pwd := os.Getenv("PWD") - rootDir := path.Join(pwd, "../../../..") - expected, err = loadExpectedClusterDetails(rootDir + "test/kwokctl/testdata/binary/create_cluster_with_extra.txt") + var err error + expected, err = loadExpectedClusterDetails(path.Join(rootDir, "test/kwokctl/testdata/binary/create_cluster.txt")) if err != nil { t.Fatal("Could not get expected cluster details:", err) } + t.Log("EXPECTED CLUSTER:", expected) + cmd := exec.Command(kwokctlPath, "create", "cluster", "--name", clusterName, "--dry-run", "--runtime=binary", "--kube-authorization=false", "--disable-qps-limits", "--quiet-pull", "--timeout=30m", "--wait=30m") + var output []byte + output, err = cmd.Output() + if err != nil { + t.Fatal("Could not get the output of the command:", err) + } + got := string(output) + got = strings.ReplaceAll(got, clusterName, "") + got = strings.ReplaceAll(got, rootDir, "") + t.Log("GOT CLUSTER:", got) if !strings.EqualFold(strings.TrimSpace(got), strings.TrimSpace(expected)) { t.Fatalf("Expected %s but got %s", expected, got) } diff --git a/test/e2e/kwokctl/dryrun/dryrun_test.go b/test/e2e/kwokctl/binary/dryrun_test.go similarity index 88% rename from test/e2e/kwokctl/dryrun/dryrun_test.go rename to test/e2e/kwokctl/binary/dryrun_test.go index 78b9cd6cbc..a15670303b 100644 --- a/test/e2e/kwokctl/dryrun/dryrun_test.go +++ b/test/e2e/kwokctl/binary/dryrun_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package dryrun_test +package binary_test import ( "testing" @@ -23,6 +23,6 @@ import ( ) func TestDryRun(t *testing.T) { - f0 := e2e.CaseDryrun(clusterName).Feature() + f0 := e2e.CaseDryrun(clusterName, kwokctlPath, rootDir).Feature() testEnv.Test(t, f0) } diff --git a/test/e2e/kwokctl/dryrun/main_test.go b/test/e2e/kwokctl/dryrun/main_test.go deleted file mode 100644 index 67b1dcf36d..0000000000 --- a/test/e2e/kwokctl/dryrun/main_test.go +++ /dev/null @@ -1,81 +0,0 @@ -/* -Copyright 2024 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package binary_test is a test environment for kwok. -package dryrun_test - -import ( - "os" - "runtime" - "testing" - - "sigs.k8s.io/e2e-framework/pkg/env" - "sigs.k8s.io/e2e-framework/pkg/envconf" - "sigs.k8s.io/e2e-framework/support/kwok" - - "sigs.k8s.io/kwok/pkg/consts" - "sigs.k8s.io/kwok/pkg/utils/path" - "sigs.k8s.io/kwok/test/e2e/helper" -) - -var ( - runtimeEnv = consts.RuntimeTypeBinary - testEnv env.Environment - pwd = os.Getenv("PWD") - rootDir = path.Join(pwd, "../../../..") - logsDir = path.Join(rootDir, "logs") - clusterName = envconf.RandomName("kwok-e2e-binary", 16) - namespace = envconf.RandomName("ns", 16) - kwokPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwok"+helper.BinSuffix) - kwokctlPath = path.Join(rootDir, "bin", runtime.GOOS, runtime.GOARCH, "kwokctl"+helper.BinSuffix) - baseArgs = []string{ - "--kwok-controller-binary=" + kwokPath, - "--runtime=" + runtimeEnv, - "--enable-metrics-server", - "--wait=15m", - } -) - -func init() { - _ = os.Setenv("KWOK_WORKDIR", path.Join(rootDir, "workdir")) -} - -func TestMain(m *testing.M) { - testEnv = helper.Environment() - - k := kwok.NewProvider(). - WithName(clusterName). - WithPath(kwokctlPath) - testEnv.Setup( - helper.BuildKwokBinary(rootDir), - helper.BuildKwokctlBinary(rootDir), - helper.CreateCluster(k, append(baseArgs, - "--controller-port=10247", - "--config="+path.Join(rootDir, "test/e2e/port_forward.yaml"), - "--config="+path.Join(rootDir, "test/e2e/logs.yaml"), - "--config="+path.Join(rootDir, "test/e2e/attach.yaml"), - "--config="+path.Join(rootDir, "test/e2e/exec.yaml"), - "--config="+path.Join(rootDir, "kustomize/metrics/usage/usage-from-annotation.yaml"), - "--config="+path.Join(rootDir, "kustomize/metrics/resource/metrics-resource.yaml"), - )...), - helper.CreateNamespace(namespace), - ) - testEnv.Finish( - helper.ExportLogs(k, logsDir), - helper.DestroyCluster(k), - ) - os.Exit(testEnv.Run(m)) -} \ No newline at end of file