1
0
mirror of synced 2026-02-13 13:06:56 +00:00

Add tests for flux trace command

Add tests for flux trace command that fake out the kubernetes client,
load objects from a yaml file and create them in the client, and
assert on the output of the trace command to an expected golden file.

This is a follow up from the suggestions in PR https://github.com/fluxcd/flux2/pull/1626 which suggested that additional
testing would be helpful. This test approach is modeled after the helm command tests.

This required some changes to the kubernetes client setup to make it
possible to use a fake. If we agree this pattern makes sense, it can be
applied to other commands.

Signed-off-by: Allen Porter <allen@thebends.org>
This commit is contained in:
Allen Porter
2021-07-31 14:05:35 -07:00
parent eba6706f15
commit 351d287d88
13 changed files with 577 additions and 12 deletions

View File

@@ -25,6 +25,7 @@ import (
"github.com/spf13/cobra"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"github.com/fluxcd/flux2/internal/utils"
"github.com/fluxcd/flux2/pkg/manifestgen/install"
)
@@ -126,6 +127,18 @@ func NewRootFlags() rootFlags {
return rf
}
type rootContext struct {
kubeManager utils.KubeManager
}
var rootCtx = NewRootContext()
func NewRootContext() rootContext {
var rc rootContext
rc.kubeManager = utils.DefaultKubeManager()
return rc
}
func main() {
log.SetFlags(0)
configureKubeconfig()