mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-09-26 17:51:13 +08:00
fix: how we get argo mock.
This commit is contained in:
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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()
|
||||
}
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user