Add the first test for workflow init
This commit is contained in:
parent
8d50c59033
commit
615fe6c15f
10
cmd/workflow/testdata/TestWorkflowInitGoldenOutput/workflow-init.golden
vendored
Normal file
10
cmd/workflow/testdata/TestWorkflowInitGoldenOutput/workflow-init.golden
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Creating namespace "argo"
|
||||||
|
Registering Workflow CRD
|
||||||
|
Creating argo ServiceAccount
|
||||||
|
Creating argo admin ClusterRole
|
||||||
|
Creating argo edit ClusterRole
|
||||||
|
Creating argo view ClusterRole
|
||||||
|
Creating argo ClusterRole
|
||||||
|
Creating argo ClusterRoleBinding
|
||||||
|
Creating argo ConfigMap
|
||||||
|
Creating argo Deployment
|
@ -14,8 +14,8 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
|
|
||||||
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
|
||||||
"github.com/ian-howell/airshipctl/pkg/environment"
|
"github.com/ian-howell/airshipctl/pkg/environment"
|
||||||
|
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -48,7 +48,7 @@ func NewWorkflowInitCommand(out io.Writer, rootSettings *environment.AirshipCTLS
|
|||||||
workflowInit := &workflowInitCmd{
|
workflowInit := &workflowInitCmd{
|
||||||
out: out,
|
out: out,
|
||||||
kubeclient: wfSettings.KubeClient,
|
kubeclient: wfSettings.KubeClient,
|
||||||
crdclient: wfSettings.CRDClient,
|
crdclient: wfSettings.CRDClient.ApiextensionsV1beta1(),
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(out, "Creating namespace \"%s\"\n", argoNamespace)
|
fmt.Fprintf(out, "Creating namespace \"%s\"\n", argoNamespace)
|
||||||
|
44
cmd/workflow/workflow_init_test.go
Normal file
44
cmd/workflow/workflow_init_test.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package workflow_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
apixv1beta1fake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
|
||||||
|
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||||
|
|
||||||
|
"github.com/ian-howell/airshipctl/cmd"
|
||||||
|
"github.com/ian-howell/airshipctl/cmd/workflow"
|
||||||
|
argofake "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned/fake"
|
||||||
|
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
||||||
|
"github.com/ian-howell/airshipctl/test"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWorkflowInit(t *testing.T) {
|
||||||
|
actual := &bytes.Buffer{}
|
||||||
|
rootCmd, settings, err := cmd.NewRootCmd(actual)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not create root command: %s", err.Error())
|
||||||
|
}
|
||||||
|
workflowRoot := workflow.NewWorkflowCommand(actual, settings)
|
||||||
|
workflowRoot.AddCommand(workflow.NewWorkflowInitCommand(actual, settings))
|
||||||
|
argoClient := argofake.NewSimpleClientset()
|
||||||
|
crdClient := apixv1beta1fake.NewSimpleClientset()
|
||||||
|
kubeClient := kubefake.NewSimpleClientset()
|
||||||
|
settings.PluginSettings[workflow.PluginSettingsID] = &wfenv.Settings{
|
||||||
|
ArgoClient: argoClient,
|
||||||
|
CRDClient: crdClient,
|
||||||
|
KubeClient: kubeClient,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(workflowRoot)
|
||||||
|
rootCmd.PersistentFlags().Parse(os.Args[1:])
|
||||||
|
|
||||||
|
var tt test.CmdTest
|
||||||
|
tt = test.CmdTest{
|
||||||
|
Name: "workflow-init",
|
||||||
|
CmdLine: "workflow init",
|
||||||
|
}
|
||||||
|
|
||||||
|
test.RunTest(t, tt, rootCmd, actual)
|
||||||
|
}
|
@ -7,8 +7,8 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
"github.com/ian-howell/airshipctl/pkg/util"
|
|
||||||
"github.com/ian-howell/airshipctl/pkg/environment"
|
"github.com/ian-howell/airshipctl/pkg/environment"
|
||||||
|
"github.com/ian-howell/airshipctl/pkg/util"
|
||||||
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,4 +9,3 @@ const (
|
|||||||
ShortName string = "wf"
|
ShortName string = "wf"
|
||||||
FullName string = Plural + "." + Group
|
FullName string = Plural + "." + Group
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2,11 +2,11 @@ package environment
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
argo "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned"
|
|
||||||
|
|
||||||
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1"
|
argo "github.com/ian-howell/airshipctl/pkg/client/clientset/versioned"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Settings is a container for all of the settings needed by workflows
|
// Settings is a container for all of the settings needed by workflows
|
||||||
@ -26,7 +26,7 @@ type Settings struct {
|
|||||||
ArgoClient argo.Interface
|
ArgoClient argo.Interface
|
||||||
|
|
||||||
// CRDClient is an instrument for interacting with CRDs
|
// CRDClient is an instrument for interacting with CRDs
|
||||||
CRDClient apixv1beta1.ApiextensionsV1beta1Interface
|
CRDClient apixv1beta1.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitFlags adds the default settings flags to cmd
|
// InitFlags adds the default settings flags to cmd
|
||||||
|
@ -7,4 +7,3 @@ import (
|
|||||||
// _ "github.com/golangci/golangci-lint/cmd/golangci-lint"
|
// _ "github.com/golangci/golangci-lint/cmd/golangci-lint"
|
||||||
_ "k8s.io/code-generator"
|
_ "k8s.io/code-generator"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user