@@ -25,6 +25,12 @@ import (
|
||||
|
||||
const DevOpsProjectFinalizerName = "devopsproject.finalizers.kubesphere.io"
|
||||
|
||||
const (
|
||||
ResourceKindDevOpsProject = "DevOpsProject"
|
||||
ResourceSingularDevOpsProject = "devopsproject"
|
||||
ResourcePluralDevOpsProject = "devopsprojects"
|
||||
)
|
||||
|
||||
// DevOpsProjectSpec defines the desired state of DevOpsProject
|
||||
type DevOpsProjectSpec struct {
|
||||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package s2ibinary
|
||||
package devopsproject
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
devopslisters "kubesphere.io/kubesphere/pkg/client/listers/devops/v1alpha3"
|
||||
)
|
||||
|
||||
type DevOpsProjectController struct {
|
||||
type Controller struct {
|
||||
client clientset.Interface
|
||||
kubesphereClient kubesphereclient.Interface
|
||||
|
||||
@@ -41,10 +41,10 @@ type DevOpsProjectController struct {
|
||||
devopsClient devopsClient.Interface
|
||||
}
|
||||
|
||||
func NewController(kubesphereClient kubesphereclient.Interface,
|
||||
client clientset.Interface,
|
||||
func NewController(client clientset.Interface,
|
||||
kubesphereClient kubesphereclient.Interface,
|
||||
devopsClinet devopsClient.Interface,
|
||||
devopsInformer devopsinformers.DevOpsProjectInformer) *DevOpsProjectController {
|
||||
devopsInformer devopsinformers.DevOpsProjectInformer) *Controller {
|
||||
|
||||
broadcaster := record.NewBroadcaster()
|
||||
broadcaster.StartLogging(func(format string, args ...interface{}) {
|
||||
@@ -53,7 +53,7 @@ func NewController(kubesphereClient kubesphereclient.Interface,
|
||||
broadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: client.CoreV1().Events("")})
|
||||
recorder := broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "devopsproject-controller"})
|
||||
|
||||
v := &DevOpsProjectController{
|
||||
v := &Controller{
|
||||
client: client,
|
||||
devopsClient: devopsClinet,
|
||||
kubesphereClient: kubesphereClient,
|
||||
@@ -84,7 +84,7 @@ func NewController(kubesphereClient kubesphereclient.Interface,
|
||||
// enqueueDevOpsProject takes a Foo resource and converts it into a namespace/name
|
||||
// string which is then put onto the work workqueue. This method should *not* be
|
||||
// passed resources of any type other than DevOpsProject.
|
||||
func (c *DevOpsProjectController) enqueueDevOpsProject(obj interface{}) {
|
||||
func (c *Controller) enqueueDevOpsProject(obj interface{}) {
|
||||
var key string
|
||||
var err error
|
||||
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
|
||||
@@ -94,7 +94,7 @@ func (c *DevOpsProjectController) enqueueDevOpsProject(obj interface{}) {
|
||||
c.workqueue.Add(key)
|
||||
}
|
||||
|
||||
func (c *DevOpsProjectController) processNextWorkItem() bool {
|
||||
func (c *Controller) processNextWorkItem() bool {
|
||||
obj, shutdown := c.workqueue.Get()
|
||||
|
||||
if shutdown {
|
||||
@@ -129,17 +129,17 @@ func (c *DevOpsProjectController) processNextWorkItem() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *DevOpsProjectController) worker() {
|
||||
func (c *Controller) worker() {
|
||||
|
||||
for c.processNextWorkItem() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DevOpsProjectController) Start(stopCh <-chan struct{}) error {
|
||||
func (c *Controller) Start(stopCh <-chan struct{}) error {
|
||||
return c.Run(1, stopCh)
|
||||
}
|
||||
|
||||
func (c *DevOpsProjectController) Run(workers int, stopCh <-chan struct{}) error {
|
||||
func (c *Controller) Run(workers int, stopCh <-chan struct{}) error {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer c.workqueue.ShutDown()
|
||||
|
||||
@@ -161,7 +161,7 @@ func (c *DevOpsProjectController) Run(workers int, stopCh <-chan struct{}) error
|
||||
// syncHandler compares the actual state with the desired, and attempts to
|
||||
// converge the two. It then updates the Status block of the devopsproject resource
|
||||
// with the current status of the resource.
|
||||
func (c *DevOpsProjectController) syncHandler(key string) error {
|
||||
func (c *Controller) syncHandler(key string) error {
|
||||
project, err := c.devOpsProjectLister.Get(key)
|
||||
if err != nil {
|
||||
if errors.IsNotFound(err) {
|
||||
@@ -180,23 +180,6 @@ func (c *DevOpsProjectController) syncHandler(key string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if sliceutil.HasString(project.ObjectMeta.Finalizers, devopsv1alpha3.DevOpsProjectFinalizerName) {
|
||||
if err := c.deleteDevOpsProjectInDevOps(project); err != nil {
|
||||
klog.Error(err, fmt.Sprintf("failed to delete resource %s in devops", key))
|
||||
return err
|
||||
}
|
||||
project.ObjectMeta.Finalizers = sliceutil.RemoveString(project.ObjectMeta.Finalizers, func(item string) bool {
|
||||
return item == devopsv1alpha3.DevOpsProjectFinalizerName
|
||||
})
|
||||
_, err := c.kubesphereClient.DevopsV1alpha3().DevOpsProjects().Update(project)
|
||||
if err != nil {
|
||||
klog.Error(err, fmt.Sprintf("failed to update project %s ", key))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, err := c.devopsClient.GetDevOpsProject(key)
|
||||
if err != nil && devopsClient.GetDevOpsStatusCode(err) != http.StatusNotFound {
|
||||
klog.Error(err, fmt.Sprintf("failed to get project %s ", key))
|
||||
@@ -208,12 +191,35 @@ func (c *DevOpsProjectController) syncHandler(key string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if sliceutil.HasString(project.ObjectMeta.Finalizers, devopsv1alpha3.DevOpsProjectFinalizerName) {
|
||||
_, err := c.devopsClient.GetDevOpsProject(key)
|
||||
if err != nil && devopsClient.GetDevOpsStatusCode(err) != http.StatusNotFound {
|
||||
klog.Error(err, fmt.Sprintf("failed to get project %s ", key))
|
||||
return err
|
||||
} else if err != nil && devopsClient.GetDevOpsStatusCode(err) == http.StatusNotFound {
|
||||
} else {
|
||||
if err := c.deleteDevOpsProjectInDevOps(project); err != nil {
|
||||
klog.Error(err, fmt.Sprintf("failed to delete resource %s in devops", key))
|
||||
return err
|
||||
}
|
||||
}
|
||||
project.ObjectMeta.Finalizers = sliceutil.RemoveString(project.ObjectMeta.Finalizers, func(item string) bool {
|
||||
return item == devopsv1alpha3.DevOpsProjectFinalizerName
|
||||
})
|
||||
|
||||
_, err = c.kubesphereClient.DevopsV1alpha3().DevOpsProjects().Update(project)
|
||||
if err != nil {
|
||||
klog.Error(err, fmt.Sprintf("failed to update project %s ", key))
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *DevOpsProjectController) deleteDevOpsProjectInDevOps(project *devopsv1alpha3.DevOpsProject) error {
|
||||
func (c *Controller) deleteDevOpsProjectInDevOps(project *devopsv1alpha3.DevOpsProject) error {
|
||||
|
||||
err := c.devopsClient.DeleteDevOpsProject(project.Name)
|
||||
if err != nil {
|
||||
|
||||
257
pkg/controller/devopsproject/devopsproject_controller_test.go
Normal file
257
pkg/controller/devopsproject/devopsproject_controller_test.go
Normal file
@@ -0,0 +1,257 @@
|
||||
package devopsproject
|
||||
|
||||
import (
|
||||
devopsprojects "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
|
||||
fakeDevOps "kubesphere.io/kubesphere/pkg/simple/client/devops/fake"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
k8sfake "k8s.io/client-go/kubernetes/fake"
|
||||
core "k8s.io/client-go/testing"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/tools/record"
|
||||
devops "kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
|
||||
"kubesphere.io/kubesphere/pkg/client/clientset/versioned/fake"
|
||||
informers "kubesphere.io/kubesphere/pkg/client/informers/externalversions"
|
||||
)
|
||||
|
||||
var (
|
||||
alwaysReady = func() bool { return true }
|
||||
noResyncPeriodFunc = func() time.Duration { return 0 }
|
||||
)
|
||||
|
||||
type fixture struct {
|
||||
t *testing.T
|
||||
|
||||
client *fake.Clientset
|
||||
kubeclient *k8sfake.Clientset
|
||||
// Objects to put in the store.
|
||||
devopsProjectLister []*devops.DevOpsProject
|
||||
actions []core.Action
|
||||
// Objects from here preloaded into NewSimpleFake.
|
||||
objects []runtime.Object
|
||||
// Objects from here preloaded into devops
|
||||
initDevOpsProject []string
|
||||
expectDevOpsProject []string
|
||||
}
|
||||
|
||||
func newFixture(t *testing.T) *fixture {
|
||||
f := &fixture{}
|
||||
f.t = t
|
||||
f.objects = []runtime.Object{}
|
||||
return f
|
||||
}
|
||||
|
||||
func newDevOpsProject(name string) *devopsprojects.DevOpsProject {
|
||||
return &devopsprojects.DevOpsProject{
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: devopsprojects.SchemeGroupVersion.String()},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
}
|
||||
}
|
||||
func newDeletingDevOpsProject(name string) *devopsprojects.DevOpsProject {
|
||||
now := metav1.Now()
|
||||
return &devopsprojects.DevOpsProject{
|
||||
TypeMeta: metav1.TypeMeta{APIVersion: devopsprojects.SchemeGroupVersion.String()},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
DeletionTimestamp: &now,
|
||||
Finalizers: []string{devopsprojects.DevOpsProjectFinalizerName},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *fixture) newController() (*Controller, informers.SharedInformerFactory, *fakeDevOps.Devops) {
|
||||
f.client = fake.NewSimpleClientset(f.objects...)
|
||||
f.kubeclient = k8sfake.NewSimpleClientset()
|
||||
|
||||
i := informers.NewSharedInformerFactory(f.client, noResyncPeriodFunc())
|
||||
dI := fakeDevOps.New(f.initDevOpsProject...)
|
||||
|
||||
c := NewController(f.kubeclient, f.client, dI, i.Devops().V1alpha3().DevOpsProjects())
|
||||
|
||||
c.devOpsProjectSynced = alwaysReady
|
||||
c.eventRecorder = &record.FakeRecorder{}
|
||||
|
||||
for _, f := range f.devopsProjectLister {
|
||||
i.Devops().V1alpha3().DevOpsProjects().Informer().GetIndexer().Add(f)
|
||||
}
|
||||
|
||||
return c, i, dI
|
||||
}
|
||||
|
||||
func (f *fixture) run(fooName string) {
|
||||
f.runController(fooName, true, false)
|
||||
}
|
||||
|
||||
func (f *fixture) runExpectError(fooName string) {
|
||||
f.runController(fooName, true, true)
|
||||
}
|
||||
|
||||
func (f *fixture) runController(projectName string, startInformers bool, expectError bool) {
|
||||
c, i, dI := f.newController()
|
||||
if startInformers {
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
i.Start(stopCh)
|
||||
}
|
||||
|
||||
err := c.syncHandler(projectName)
|
||||
if !expectError && err != nil {
|
||||
f.t.Errorf("error syncing foo: %v", err)
|
||||
} else if expectError && err == nil {
|
||||
f.t.Error("expected error syncing foo, got nil")
|
||||
}
|
||||
|
||||
actions := filterInformerActions(f.client.Actions())
|
||||
for i, action := range actions {
|
||||
if len(f.actions) < i+1 {
|
||||
f.t.Errorf("%d unexpected actions: %+v", len(actions)-len(f.actions), actions[i:])
|
||||
break
|
||||
}
|
||||
|
||||
expectedAction := f.actions[i]
|
||||
checkAction(expectedAction, action, f.t)
|
||||
}
|
||||
|
||||
if len(f.actions) > len(actions) {
|
||||
f.t.Errorf("%d additional expected actions:%+v", len(f.actions)-len(actions), f.actions[len(actions):])
|
||||
}
|
||||
if len(dI.Projects) != len(f.expectDevOpsProject) {
|
||||
f.t.Errorf(" unexpected objects: %v", dI.Projects)
|
||||
}
|
||||
}
|
||||
|
||||
// checkAction verifies that expected and actual actions are equal and both have
|
||||
// same attached resources
|
||||
func checkAction(expected, actual core.Action, t *testing.T) {
|
||||
if !(expected.Matches(actual.GetVerb(), actual.GetResource().Resource) && actual.GetSubresource() == expected.GetSubresource()) {
|
||||
t.Errorf("Expected\n\t%#v\ngot\n\t%#v", expected, actual)
|
||||
return
|
||||
}
|
||||
|
||||
if reflect.TypeOf(actual) != reflect.TypeOf(expected) {
|
||||
t.Errorf("Action has wrong type. Expected: %t. Got: %t", expected, actual)
|
||||
return
|
||||
}
|
||||
|
||||
switch a := actual.(type) {
|
||||
case core.CreateActionImpl:
|
||||
e, _ := expected.(core.CreateActionImpl)
|
||||
expObject := e.GetObject()
|
||||
object := a.GetObject()
|
||||
|
||||
if !reflect.DeepEqual(expObject, object) {
|
||||
t.Errorf("Action %s %s has wrong object\nDiff:\n %s",
|
||||
a.GetVerb(), a.GetResource().Resource, diff.ObjectGoPrintSideBySide(expObject, object))
|
||||
}
|
||||
case core.UpdateActionImpl:
|
||||
e, _ := expected.(core.UpdateActionImpl)
|
||||
expObject := e.GetObject()
|
||||
object := a.GetObject()
|
||||
|
||||
if !reflect.DeepEqual(expObject, object) {
|
||||
t.Errorf("Action %s %s has wrong object\nDiff:\n %s",
|
||||
a.GetVerb(), a.GetResource().Resource, diff.ObjectGoPrintSideBySide(expObject, object))
|
||||
}
|
||||
case core.PatchActionImpl:
|
||||
e, _ := expected.(core.PatchActionImpl)
|
||||
expPatch := e.GetPatch()
|
||||
patch := a.GetPatch()
|
||||
|
||||
if !reflect.DeepEqual(expPatch, patch) {
|
||||
t.Errorf("Action %s %s has wrong patch\nDiff:\n %s",
|
||||
a.GetVerb(), a.GetResource().Resource, diff.ObjectGoPrintSideBySide(expPatch, patch))
|
||||
}
|
||||
default:
|
||||
t.Errorf("Uncaptured Action %s %s, you should explicitly add a case to capture it",
|
||||
actual.GetVerb(), actual.GetResource().Resource)
|
||||
}
|
||||
}
|
||||
|
||||
// filterInformerActions filters list and watch actions for testing resources.
|
||||
// Since list and watch don't change resource state we can filter it to lower
|
||||
// nose level in our tests.
|
||||
func filterInformerActions(actions []core.Action) []core.Action {
|
||||
ret := []core.Action{}
|
||||
for _, action := range actions {
|
||||
if len(action.GetNamespace()) == 0 &&
|
||||
(action.Matches("list", "foos") ||
|
||||
action.Matches("watch", "foos") ||
|
||||
action.Matches("list", "deployments") ||
|
||||
action.Matches("watch", "deployments")) {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, action)
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (f *fixture) expectUpdateDevOpsProjectAction(p *devopsprojects.DevOpsProject) {
|
||||
action := core.NewUpdateAction(schema.GroupVersionResource{Resource: devopsprojects.ResourcePluralDevOpsProject},
|
||||
p.Namespace, p)
|
||||
f.actions = append(f.actions, action)
|
||||
}
|
||||
|
||||
func getKey(p *devopsprojects.DevOpsProject, t *testing.T) string {
|
||||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(p)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error getting key for devopsprojects %v: %v", p.Name, err)
|
||||
return ""
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func TestDoNothing(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
project := newDevOpsProject("test")
|
||||
|
||||
f.devopsProjectLister = append(f.devopsProjectLister, project)
|
||||
f.objects = append(f.objects, project)
|
||||
f.initDevOpsProject = []string{project.Name}
|
||||
f.expectDevOpsProject = []string{project.Name}
|
||||
|
||||
f.expectUpdateDevOpsProjectAction(project)
|
||||
f.run(getKey(project, t))
|
||||
}
|
||||
|
||||
func TestCreateDevOpsProjects(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
project := newDevOpsProject("test")
|
||||
|
||||
f.devopsProjectLister = append(f.devopsProjectLister, project)
|
||||
f.objects = append(f.objects, project)
|
||||
f.expectDevOpsProject = []string{project.Name}
|
||||
|
||||
f.expectUpdateDevOpsProjectAction(project)
|
||||
f.run(getKey(project, t))
|
||||
}
|
||||
|
||||
func TestDeleteDevOpsProjects(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
project := newDeletingDevOpsProject("test")
|
||||
|
||||
f.devopsProjectLister = append(f.devopsProjectLister, project)
|
||||
f.objects = append(f.objects, project)
|
||||
f.initDevOpsProject = []string{project.Name}
|
||||
f.expectDevOpsProject = []string{}
|
||||
f.expectUpdateDevOpsProjectAction(project)
|
||||
f.run(getKey(project, t))
|
||||
}
|
||||
func TestDeleteDevOpsProjectsWithNull(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
project := newDeletingDevOpsProject("test")
|
||||
|
||||
f.devopsProjectLister = append(f.devopsProjectLister, project)
|
||||
f.objects = append(f.objects, project)
|
||||
f.expectDevOpsProject = []string{}
|
||||
f.expectUpdateDevOpsProjectAction(project)
|
||||
f.run(getKey(project, t))
|
||||
}
|
||||
@@ -186,7 +186,7 @@ func (o *devopsProjectOperator) DeleteDevOpsProject(projectId, username string)
|
||||
func (o *devopsProjectOperator) CreateDevOpsProject(username string, workspace string, req *v1alpha2.DevOpsProject) (*v1alpha2.DevOpsProject, error) {
|
||||
|
||||
project := devops.NewDevOpsProject(req.Name, req.Description, username, req.Extra, workspace)
|
||||
_, err := o.dsProject.CreateDevOpsProject(username, project)
|
||||
_, err := o.dsProject.CreateDevOpsProject(project.ProjectId)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
|
||||
@@ -1,206 +1,290 @@
|
||||
package fake
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/devops"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FakeDevops struct {
|
||||
type Devops struct {
|
||||
Data map[string]interface{}
|
||||
|
||||
Projects map[string]interface{}
|
||||
}
|
||||
|
||||
func NewFakeDevops(data map[string]interface{}) *FakeDevops {
|
||||
var fakeData FakeDevops
|
||||
func New(projects ...string) *Devops {
|
||||
d := &Devops{
|
||||
Data: nil,
|
||||
Projects: map[string]interface{}{},
|
||||
}
|
||||
for _, p := range projects {
|
||||
d.Projects[p] = true
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *Devops) CreateDevOpsProject(projectId string) (string, error) {
|
||||
if _, ok := d.Projects[projectId]; ok {
|
||||
return projectId, nil
|
||||
}
|
||||
d.Projects[projectId] = true
|
||||
return projectId, nil
|
||||
}
|
||||
|
||||
func (d *Devops) DeleteDevOpsProject(projectId string) error {
|
||||
if _, ok := d.Projects[projectId]; ok {
|
||||
delete(d.Projects, projectId)
|
||||
return nil
|
||||
} else {
|
||||
return &devops.ErrorResponse{
|
||||
Body: []byte{},
|
||||
Response: &http.Response{
|
||||
Status: "404 Not Found",
|
||||
StatusCode: 404,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
ContentLength: 50,
|
||||
Header: http.Header{
|
||||
"Foo": []string{"Bar"},
|
||||
},
|
||||
Body: ioutil.NopCloser(strings.NewReader("foo")), // shouldn't be used
|
||||
},
|
||||
Message: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Devops) GetDevOpsProject(projectId string) (string, error) {
|
||||
if _, ok := d.Projects[projectId]; ok {
|
||||
return projectId, nil
|
||||
} else {
|
||||
return "", &devops.ErrorResponse{
|
||||
Body: []byte{},
|
||||
Response: &http.Response{
|
||||
Status: "404 Not Found",
|
||||
StatusCode: 404,
|
||||
Proto: "HTTP/1.1",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 1,
|
||||
ContentLength: 50,
|
||||
Header: http.Header{
|
||||
"Foo": []string{"Bar"},
|
||||
},
|
||||
Body: ioutil.NopCloser(strings.NewReader("foo")), // shouldn't be used
|
||||
Request: &http.Request{
|
||||
Method: "",
|
||||
URL: &url.URL{
|
||||
Scheme: "",
|
||||
Opaque: "",
|
||||
User: nil,
|
||||
Host: "",
|
||||
Path: "",
|
||||
RawPath: "",
|
||||
ForceQuery: false,
|
||||
RawQuery: "",
|
||||
Fragment: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
Message: "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NewFakeDevops(data map[string]interface{}) *Devops {
|
||||
var fakeData Devops
|
||||
fakeData.Data = data
|
||||
return &fakeData
|
||||
}
|
||||
|
||||
// Pipelinne operator interface
|
||||
func (d *FakeDevops) GetPipeline(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.Pipeline, error) {
|
||||
func (d *Devops) GetPipeline(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.Pipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *FakeDevops) ListPipelines(httpParameters *devops.HttpParameters) (*devops.PipelineList, error) {
|
||||
func (d *Devops) ListPipelines(httpParameters *devops.HttpParameters) (*devops.PipelineList, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetPipelineRun(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.PipelineRun, error) {
|
||||
func (d *Devops) GetPipelineRun(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.PipelineRun, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ListPipelineRuns(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.PipelineRunList, error) {
|
||||
func (d *Devops) ListPipelineRuns(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.PipelineRunList, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) StopPipeline(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.StopPipeline, error) {
|
||||
func (d *Devops) StopPipeline(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.StopPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ReplayPipeline(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.ReplayPipeline, error) {
|
||||
func (d *Devops) ReplayPipeline(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) (*devops.ReplayPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) RunPipeline(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.RunPipeline, error) {
|
||||
func (d *Devops) RunPipeline(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.RunPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetArtifacts(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]devops.Artifacts, error) {
|
||||
func (d *Devops) GetArtifacts(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]devops.Artifacts, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
||||
func (d *Devops) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetNodeSteps(projectName, pipelineName, runId, nodeId string, httpParameters *devops.HttpParameters) ([]devops.NodeSteps, error) {
|
||||
func (d *Devops) GetNodeSteps(projectName, pipelineName, runId, nodeId string, httpParameters *devops.HttpParameters) ([]devops.NodeSteps, error) {
|
||||
s := []string{projectName, pipelineName, runId, nodeId}
|
||||
key := strings.Join(s, "-")
|
||||
res := d.Data[key].([]devops.NodeSteps)
|
||||
return res, nil
|
||||
}
|
||||
func (d *FakeDevops) GetPipelineRunNodes(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]devops.PipelineRunNodes, error) {
|
||||
func (d *Devops) GetPipelineRunNodes(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]devops.PipelineRunNodes, error) {
|
||||
s := []string{projectName, pipelineName, runId}
|
||||
key := strings.Join(s, "-")
|
||||
res := d.Data[key].([]devops.PipelineRunNodes)
|
||||
return res, nil
|
||||
}
|
||||
func (d *FakeDevops) SubmitInputStep(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) SubmitInputStep(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
//BranchPipelinne operator interface
|
||||
func (d *FakeDevops) GetBranchPipeline(projectName, pipelineName, branchName string, httpParameters *devops.HttpParameters) (*devops.BranchPipeline, error) {
|
||||
func (d *Devops) GetBranchPipeline(projectName, pipelineName, branchName string, httpParameters *devops.HttpParameters) (*devops.BranchPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchPipelineRun(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.PipelineRun, error) {
|
||||
func (d *Devops) GetBranchPipelineRun(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.PipelineRun, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) StopBranchPipeline(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.StopPipeline, error) {
|
||||
func (d *Devops) StopBranchPipeline(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.StopPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ReplayBranchPipeline(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.ReplayPipeline, error) {
|
||||
func (d *Devops) ReplayBranchPipeline(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) (*devops.ReplayPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) RunBranchPipeline(projectName, pipelineName, branchName string, httpParameters *devops.HttpParameters) (*devops.RunPipeline, error) {
|
||||
func (d *Devops) RunBranchPipeline(projectName, pipelineName, branchName string, httpParameters *devops.HttpParameters) (*devops.RunPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchArtifacts(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]devops.Artifacts, error) {
|
||||
func (d *Devops) GetBranchArtifacts(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]devops.Artifacts, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchRunLog(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) GetBranchRunLog(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
||||
func (d *Devops) GetBranchStepLog(projectName, pipelineName, branchName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, httpParameters *devops.HttpParameters) ([]devops.NodeSteps, error) {
|
||||
func (d *Devops) GetBranchNodeSteps(projectName, pipelineName, branchName, runId, nodeId string, httpParameters *devops.HttpParameters) ([]devops.NodeSteps, error) {
|
||||
s := []string{projectName, pipelineName, branchName, runId, nodeId}
|
||||
key := strings.Join(s, "-")
|
||||
res := d.Data[key].([]devops.NodeSteps)
|
||||
return res, nil
|
||||
}
|
||||
func (d *FakeDevops) GetBranchPipelineRunNodes(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]devops.BranchPipelineRunNodes, error) {
|
||||
func (d *Devops) GetBranchPipelineRunNodes(projectName, pipelineName, branchName, runId string, httpParameters *devops.HttpParameters) ([]devops.BranchPipelineRunNodes, error) {
|
||||
s := []string{projectName, pipelineName, branchName, runId}
|
||||
key := strings.Join(s, "-")
|
||||
res := d.Data[key].([]devops.BranchPipelineRunNodes)
|
||||
return res, nil
|
||||
}
|
||||
func (d *FakeDevops) SubmitBranchInputStep(projectName, pipelineName, branchName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) SubmitBranchInputStep(projectName, pipelineName, branchName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetPipelineBranch(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.PipelineBranch, error) {
|
||||
func (d *Devops) GetPipelineBranch(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.PipelineBranch, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ScanBranch(projectName, pipelineName string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) ScanBranch(projectName, pipelineName string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Common pipeline operator interface
|
||||
func (d *FakeDevops) GetConsoleLog(projectName, pipelineName string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) GetConsoleLog(projectName, pipelineName string, httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetCrumb(httpParameters *devops.HttpParameters) (*devops.Crumb, error) {
|
||||
func (d *Devops) GetCrumb(httpParameters *devops.HttpParameters) (*devops.Crumb, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// SCM operator interface
|
||||
func (d *FakeDevops) GetSCMServers(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMServer, error) {
|
||||
func (d *Devops) GetSCMServers(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMServer, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetSCMOrg(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMOrg, error) {
|
||||
func (d *Devops) GetSCMOrg(scmId string, httpParameters *devops.HttpParameters) ([]devops.SCMOrg, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) ([]devops.OrgRepo, error) {
|
||||
func (d *Devops) GetOrgRepo(scmId, organizationId string, httpParameters *devops.HttpParameters) ([]devops.OrgRepo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) CreateSCMServers(scmId string, httpParameters *devops.HttpParameters) (*devops.SCMServer, error) {
|
||||
func (d *Devops) CreateSCMServers(scmId string, httpParameters *devops.HttpParameters) (*devops.SCMServer, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) Validate(scmId string, httpParameters *devops.HttpParameters) (*devops.Validates, error) {
|
||||
func (d *Devops) Validate(scmId string, httpParameters *devops.HttpParameters) (*devops.Validates, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
//Webhook operator interface
|
||||
func (d *FakeDevops) GetNotifyCommit(httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) GetNotifyCommit(httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GithubWebhook(httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
func (d *Devops) GithubWebhook(httpParameters *devops.HttpParameters) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (d *FakeDevops) CheckScriptCompile(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.CheckScript, error) {
|
||||
func (d *Devops) CheckScriptCompile(projectName, pipelineName string, httpParameters *devops.HttpParameters) (*devops.CheckScript, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) CheckCron(projectName string, httpParameters *devops.HttpParameters) (*devops.CheckCronRes, error) {
|
||||
func (d *Devops) CheckCron(projectName string, httpParameters *devops.HttpParameters) (*devops.CheckCronRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ToJenkinsfile(httpParameters *devops.HttpParameters) (*devops.ResJenkinsfile, error) {
|
||||
func (d *Devops) ToJenkinsfile(httpParameters *devops.HttpParameters) (*devops.ResJenkinsfile, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) ToJson(httpParameters *devops.HttpParameters) (*devops.ResJson, error) {
|
||||
func (d *Devops) ToJson(httpParameters *devops.HttpParameters) (*devops.ResJson, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// CredentialOperator
|
||||
func (d *FakeDevops) CreateCredentialInProject(projectId string, credential *devops.Credential) (*string, error) {
|
||||
func (d *Devops) CreateCredentialInProject(projectId string, credential *devops.Credential) (*string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) UpdateCredentialInProject(projectId string, credential *devops.Credential) (*string, error) {
|
||||
func (d *Devops) UpdateCredentialInProject(projectId string, credential *devops.Credential) (*string, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetCredentialInProject(projectId, id string, content bool) (*devops.Credential, error) {
|
||||
func (d *Devops) GetCredentialInProject(projectId, id string, content bool) (*devops.Credential, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetCredentialsInProject(projectId string) ([]*devops.Credential, error) {
|
||||
func (d *Devops) GetCredentialsInProject(projectId string) ([]*devops.Credential, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) DeleteCredentialInProject(projectId, id string) (*string, error) { return nil, nil }
|
||||
func (d *Devops) DeleteCredentialInProject(projectId, id string) (*string, error) { return nil, nil }
|
||||
|
||||
// BuildGetter
|
||||
func (d *FakeDevops) GetProjectPipelineBuildByType(projectId, pipelineId string, status string) (*devops.Build, error) {
|
||||
func (d *Devops) GetProjectPipelineBuildByType(projectId, pipelineId string, status string) (*devops.Build, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) GetMultiBranchPipelineBuildByType(projectId, pipelineId, branch string, status string) (*devops.Build, error) {
|
||||
func (d *Devops) GetMultiBranchPipelineBuildByType(projectId, pipelineId, branch string, status string) (*devops.Build, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ProjectMemberOperator
|
||||
func (d *FakeDevops) AddProjectMember(membership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
func (d *Devops) AddProjectMember(membership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) UpdateProjectMember(oldMembership, newMembership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
func (d *Devops) UpdateProjectMember(oldMembership, newMembership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (d *FakeDevops) DeleteProjectMember(membership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
func (d *Devops) DeleteProjectMember(membership *devops.ProjectMembership) (*devops.ProjectMembership, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// ProjectPipelineOperator
|
||||
func (d *FakeDevops) CreateProjectPipeline(projectId string, pipeline *devops.ProjectPipeline) (string, error) {
|
||||
func (d *Devops) CreateProjectPipeline(projectId string, pipeline *devops.ProjectPipeline) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (d *FakeDevops) DeleteProjectPipeline(projectId string, pipelineId string) (string, error) {
|
||||
func (d *Devops) DeleteProjectPipeline(projectId string, pipelineId string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (d *FakeDevops) UpdateProjectPipeline(projectId string, pipeline *devops.ProjectPipeline) (string, error) {
|
||||
func (d *Devops) UpdateProjectPipeline(projectId string, pipeline *devops.ProjectPipeline) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
func (d *FakeDevops) GetProjectPipelineConfig(projectId, pipelineId string) (*devops.ProjectPipeline, error) {
|
||||
func (d *Devops) GetProjectPipelineConfig(projectId, pipelineId string) (*devops.ProjectPipeline, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user