diff --git a/pkg/client_test.go b/pkg/client_test.go index cfd18f8..1e83c5e 100644 --- a/pkg/client_test.go +++ b/pkg/client_test.go @@ -3,8 +3,8 @@ package v1 import ( "flag" "fmt" + argoFake "github.com/argoproj/argo/pkg/client/clientset/versioned/fake" "github.com/jmoiron/sqlx" - "github.com/onepanelio/core/pkg/util/mocks" "github.com/pressly/goose" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -83,11 +83,12 @@ func TestMain(m *testing.M) { func NewTestClient(db *sqlx.DB, objects ...runtime.Object) (client *Client) { k8sFake := fake.NewSimpleClientset(objects...) + argoFakeClient := argoFake.NewSimpleClientset() return &Client{ Interface: k8sFake, DB: NewDB(db), - argoprojV1alpha1: mocks.NewArgo(&k8sFake.Fake), + argoprojV1alpha1: argoFakeClient.ArgoprojV1alpha1(), } } diff --git a/pkg/util/mocks/argo.go b/pkg/util/mocks/argo.go deleted file mode 100644 index 5d21eb2..0000000 --- a/pkg/util/mocks/argo.go +++ /dev/null @@ -1,38 +0,0 @@ -package mocks - -import ( - v1alpha1 "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1" - "github.com/argoproj/argo/pkg/client/clientset/versioned/typed/workflow/v1alpha1/fake" - rest "k8s.io/client-go/rest" - "k8s.io/client-go/testing" -) - -type ArgoMock struct { - argo *fake.FakeArgoprojV1alpha1 -} - -func NewArgo(k8fake *testing.Fake) ArgoMock { - return ArgoMock{ - argo: &fake.FakeArgoprojV1alpha1{ - Fake: k8fake, - }, - } -} - -func (c ArgoMock) CronWorkflows(namespace string) v1alpha1.CronWorkflowInterface { - return c.argo.CronWorkflows(namespace) -} - -func (c ArgoMock) Workflows(namespace string) v1alpha1.WorkflowInterface { - return c.argo.Workflows(namespace) -} - -func (c ArgoMock) WorkflowTemplates(namespace string) v1alpha1.WorkflowTemplateInterface { - return c.argo.WorkflowTemplates(namespace) -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c ArgoMock) RESTClient() rest.Interface { - return c.argo.RESTClient() -} diff --git a/pkg/workflow_execution_test.go b/pkg/workflow_execution_test.go index 18b87c6..47760da 100644 --- a/pkg/workflow_execution_test.go +++ b/pkg/workflow_execution_test.go @@ -5,6 +5,7 @@ import ( "testing" ) +// TestClient_CreateWorkflowExecution tests creating a workflow execution func TestClient_CreateWorkflowExecution(t *testing.T) { c := DefaultTestClient() clearDatabase(t) @@ -25,6 +26,44 @@ func TestClient_CreateWorkflowExecution(t *testing.T) { assert.Nil(t, err) } +// TestClient_GetWorkflowExecution tests getting a workflow execution that exists +func TestClient_GetWorkflowExecution(t *testing.T) { + c := DefaultTestClient() + clearDatabase(t) + + namespace := "onepanel" + + wt := &WorkflowTemplate{ + Name: "test", + Manifest: defaultWorkflowTemplate, + } + wt, _ = c.CreateWorkflowTemplate(namespace, wt) + + we := &WorkflowExecution{ + Name: "test", + } + + we, _ = c.CreateWorkflowExecution(namespace, we, wt) + + getWe, err := c.GetWorkflowExecution(namespace, we.UID) + assert.Nil(t, err) + + assert.Equal(t, we.Name, getWe.Name) + assert.Equal(t, we.UID, getWe.UID) +} + +// TestClient_GetWorkflowExecution tests getting a workflow execution that doesn't exist +func TestClient_GetWorkflowExecution_NotExists(t *testing.T) { + c := DefaultTestClient() + clearDatabase(t) + + namespace := "onepanel" + + getWe, err := c.GetWorkflowExecution(namespace, "not-exist") + assert.Nil(t, getWe) + assert.Nil(t, err) +} + // TestClient_ArchiveWorkflowExecution_NotExist makes sure there is no error if the workflow // execution does not exist func TestClient_ArchiveWorkflowExecution_NotExist(t *testing.T) {