Add the first test for workflow init

This commit is contained in:
Ian Howell 2019-05-28 16:47:51 -05:00
parent 8d50c59033
commit 615fe6c15f
7 changed files with 60 additions and 8 deletions

View 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

View File

@ -14,8 +14,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
"github.com/ian-howell/airshipctl/pkg/environment"
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
)
const (
@ -48,7 +48,7 @@ func NewWorkflowInitCommand(out io.Writer, rootSettings *environment.AirshipCTLS
workflowInit := &workflowInitCmd{
out: out,
kubeclient: wfSettings.KubeClient,
crdclient: wfSettings.CRDClient,
crdclient: wfSettings.CRDClient.ApiextensionsV1beta1(),
}
fmt.Fprintf(out, "Creating namespace \"%s\"\n", argoNamespace)

View 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)
}

View File

@ -7,8 +7,8 @@ import (
"github.com/spf13/cobra"
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/util"
wfenv "github.com/ian-howell/airshipctl/pkg/workflow/environment"
)

View File

@ -9,4 +9,3 @@ const (
ShortName string = "wf"
FullName string = Plural + "." + Group
)

View File

@ -2,11 +2,11 @@ package environment
import (
"github.com/spf13/cobra"
apixv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"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
@ -26,7 +26,7 @@ type Settings struct {
ArgoClient argo.Interface
// CRDClient is an instrument for interacting with CRDs
CRDClient apixv1beta1.ApiextensionsV1beta1Interface
CRDClient apixv1beta1.Interface
}
// InitFlags adds the default settings flags to cmd

View File

@ -7,4 +7,3 @@ import (
// _ "github.com/golangci/golangci-lint/cmd/golangci-lint"
_ "k8s.io/code-generator"
)