mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-29 07:19:07 +08:00
Replace the 4 arguments to cmdTestCase with a function that can let tests run arbitrary logic if it is more complex than what is provided by the test harness. Move the existing logic into functions that the test can use for common assertions on golden files and golden values. These changes were pulled out of PR #1696 to make a smaller review. Signed-off-by: Allen Porter <allen@thebends.org>
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
// +build e2e
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/fluxcd/flux2/internal/utils"
|
|
"k8s.io/apimachinery/pkg/version"
|
|
)
|
|
|
|
func TestCheckPre(t *testing.T) {
|
|
jsonOutput, err := utils.ExecKubectlCommand(context.TODO(), utils.ModeCapture, rootArgs.kubeconfig, rootArgs.kubecontext, "version", "--output", "json")
|
|
if err != nil {
|
|
t.Fatalf("Error running utils.ExecKubectlCommand: %v", err.Error())
|
|
}
|
|
|
|
var versions map[string]version.Info
|
|
if err := json.Unmarshal([]byte(jsonOutput), &versions); err != nil {
|
|
t.Fatalf("Error unmarshalling: %v", err.Error())
|
|
}
|
|
|
|
clientVersion := strings.TrimPrefix(versions["clientVersion"].GitVersion, "v")
|
|
serverVersion := strings.TrimPrefix(versions["serverVersion"].GitVersion, "v")
|
|
|
|
cmd := cmdTestCase{
|
|
args: "check --pre",
|
|
testClusterMode: ExistingClusterMode,
|
|
assert: assertGoldenTemplateFile("testdata/check/check_pre.golden", map[string]string{
|
|
"clientVersion": clientVersion,
|
|
"serverVersion": serverVersion,
|
|
}),
|
|
}
|
|
cmd.runTestCmd(t)
|
|
}
|