|
| 1 | +package application |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo" |
| 5 | + "k8s.io/apimachinery/pkg/runtime" |
| 6 | + "k8s.io/apimachinery/pkg/runtime/schema" |
| 7 | +) |
| 8 | + |
| 9 | +var _ = Describe("application", func() { |
| 10 | + //var stop chan struct{} |
| 11 | + // |
| 12 | + //BeforeEach(func() { |
| 13 | + // stop = make(chan struct{}) |
| 14 | + // getConfig = func() (*rest.Config, error) { return cfg, nil } |
| 15 | + // newController = controller.New |
| 16 | + // newManager = manager.New |
| 17 | + // getGvk = apiutil.GVKForObject |
| 18 | + //}) |
| 19 | + // |
| 20 | + //AfterEach(func() { |
| 21 | + // close(stop) |
| 22 | + //}) |
| 23 | + // |
| 24 | + //Describe("noop", func() { |
| 25 | + // It("should return run", func() { |
| 26 | + // _, err := noop.Reconcile(reconcile.Request{}) |
| 27 | + // Expect(err).NotTo(HaveOccurred()) |
| 28 | + // }) |
| 29 | + //}) |
| 30 | + // |
| 31 | + //Describe("New", func() { |
| 32 | + // It("should return success if given valid objects", func() { |
| 33 | + // instance, err := New(&appsv1.ReplicaSet{}, &appsv1.ReplicaSet{}) |
| 34 | + // Expect(err).NotTo(HaveOccurred()) |
| 35 | + // Expect(instance).NotTo(BeNil()) |
| 36 | + // }) |
| 37 | + // |
| 38 | + // It("should return an error if the Config is invalid", func() { |
| 39 | + // getConfig = func() (*rest.Config, error) { return cfg, fmt.Errorf("expected error") } |
| 40 | + // instance, err := New(&appsv1.ReplicaSet{}, &appsv1.ReplicaSet{}) |
| 41 | + // Expect(err).To(HaveOccurred()) |
| 42 | + // Expect(instance).To(BeNil()) |
| 43 | + // }) |
| 44 | + // |
| 45 | + // It("should return an error if there is no GVK for an object", func() { |
| 46 | + // instance, err := New(fakeType(""), &appsv1.ReplicaSet{}) |
| 47 | + // Expect(err).To(HaveOccurred()) |
| 48 | + // Expect(instance).To(BeNil()) |
| 49 | + // |
| 50 | + // instance, err = New(&appsv1.ReplicaSet{}, fakeType("")) |
| 51 | + // Expect(err).To(HaveOccurred()) |
| 52 | + // Expect(instance).To(BeNil()) |
| 53 | + // }) |
| 54 | + // |
| 55 | + // It("should return an error if it cannot create the manager", func() { |
| 56 | + // newManager = func(config *rest.Config, options manager.Options) (manager.Manager, error) { |
| 57 | + // return nil, fmt.Errorf("expected error") |
| 58 | + // } |
| 59 | + // instance, err := New(&appsv1.ReplicaSet{}, &appsv1.ReplicaSet{}) |
| 60 | + // Expect(err).To(HaveOccurred()) |
| 61 | + // Expect(instance).To(BeNil()) |
| 62 | + // }) |
| 63 | + // |
| 64 | + // It("should return an error if it cannot create the controller", func() { |
| 65 | + // newController = func(name string, mrg manager.Manager, options controller.Options) ( |
| 66 | + // controller.Controller, error) { |
| 67 | + // |
| 68 | + // return nil, fmt.Errorf("expected error") |
| 69 | + // } |
| 70 | + // instance, err := New(&appsv1.ReplicaSet{}, &appsv1.ReplicaSet{}) |
| 71 | + // Expect(err).To(HaveOccurred()) |
| 72 | + // Expect(instance).To(BeNil()) |
| 73 | + // }) |
| 74 | + // |
| 75 | + // It("should return an error if it cannot call handle", func() { |
| 76 | + // // Prevent getGVK from failing so watch fails |
| 77 | + // getGvk = func(obj runtime.Object, scheme *runtime.Scheme) (schema.GroupVersionKind, error) { |
| 78 | + // return schema.GroupVersionKind{Kind: "foo"}, nil |
| 79 | + // } |
| 80 | + // instance, err := New(fakeType(""), &appsv1.ReplicaSet{}) |
| 81 | + // Expect(err).To(HaveOccurred()) |
| 82 | + // Expect(instance).To(BeNil()) |
| 83 | + // }) |
| 84 | + //}) |
| 85 | + // |
| 86 | + //Describe("Start", func() { |
| 87 | + // It("should Reconcile objects", func(done Done) { |
| 88 | + // By("Creating the application") |
| 89 | + // instance, err := New(&appsv1.Deployment{}, &appsv1.ReplicaSet{}) |
| 90 | + // Expect(err).NotTo(HaveOccurred()) |
| 91 | + // |
| 92 | + // // set the stopFn so we shutdown at the end of the test instead of waiting for a signal |
| 93 | + // instance.stopFn = func() <-chan struct{} { return stop } |
| 94 | + // |
| 95 | + // By("Handling Deployments") |
| 96 | + // ch := make(chan reconcile.Request) |
| 97 | + // fn := reconcile.Func(func(r reconcile.Request) (reconcile.Result, error) { |
| 98 | + // defer GinkgoRecover() |
| 99 | + // fmt.Printf("Reconcile\n\n") |
| 100 | + // ch <- r |
| 101 | + // return reconcile.Result{}, nil |
| 102 | + // }) |
| 103 | + // Expect(err).NotTo(HaveOccurred()) |
| 104 | + // |
| 105 | + // By("Starting the application") |
| 106 | + // go func() { |
| 107 | + // defer GinkgoRecover() |
| 108 | + // Expect(instance.Start(fn)).NotTo(HaveOccurred()) |
| 109 | + // By("Stopping the application") |
| 110 | + // }() |
| 111 | + // |
| 112 | + // By("Creating a Deployment") |
| 113 | + // // Expect a Reconcile when the Deployment is manages. |
| 114 | + // dep := &appsv1.Deployment{ |
| 115 | + // ObjectMeta: metav1.ObjectMeta{ |
| 116 | + // Namespace: "default", |
| 117 | + // Name: "deploy-name", |
| 118 | + // }, |
| 119 | + // Spec: appsv1.DeploymentSpec{ |
| 120 | + // Selector: &metav1.LabelSelector{ |
| 121 | + // MatchLabels: map[string]string{"foo": "bar"}, |
| 122 | + // }, |
| 123 | + // Template: corev1.PodTemplateSpec{ |
| 124 | + // ObjectMeta: metav1.ObjectMeta{Labels: map[string]string{"foo": "bar"}}, |
| 125 | + // Spec: corev1.PodSpec{ |
| 126 | + // Containers: []corev1.Container{ |
| 127 | + // { |
| 128 | + // Name: "nginx", |
| 129 | + // Image: "nginx", |
| 130 | + // }, |
| 131 | + // }, |
| 132 | + // }, |
| 133 | + // }, |
| 134 | + // }, |
| 135 | + // } |
| 136 | + // err = instance.GetClient().Create(context.TODO(), dep) |
| 137 | + // Expect(err).NotTo(HaveOccurred()) |
| 138 | + // |
| 139 | + // By("Waiting for the Deployment Reconcile") |
| 140 | + // Expect(<-ch).To(Equal(reconcile.Request{ |
| 141 | + // NamespacedName: types.NamespacedName{Namespace: "default", Name: "deploy-name"}})) |
| 142 | + // |
| 143 | + // By("Creating a ReplicaSet") |
| 144 | + // // Expect a Reconcile when an Owned object is manages. |
| 145 | + // t := true |
| 146 | + // rs := &appsv1.ReplicaSet{ |
| 147 | + // ObjectMeta: metav1.ObjectMeta{ |
| 148 | + // Namespace: "default", |
| 149 | + // Name: "rs-name", |
| 150 | + // Labels: dep.Spec.Selector.MatchLabels, |
| 151 | + // OwnerReferences: []metav1.OwnerReference{ |
| 152 | + // { |
| 153 | + // Name: "deploy-name", |
| 154 | + // Kind: "Deployment", |
| 155 | + // APIVersion: "apps/v1", |
| 156 | + // Controller: &t, |
| 157 | + // UID: dep.UID, |
| 158 | + // }, |
| 159 | + // }, |
| 160 | + // }, |
| 161 | + // Spec: appsv1.ReplicaSetSpec{ |
| 162 | + // Selector: dep.Spec.Selector, |
| 163 | + // Template: dep.Spec.Template, |
| 164 | + // }, |
| 165 | + // } |
| 166 | + // err = instance.GetClient().Create(context.TODO(), rs) |
| 167 | + // Expect(err).NotTo(HaveOccurred()) |
| 168 | + // |
| 169 | + // By("Waiting for the ReplicaSet Reconcile") |
| 170 | + // Expect(<-ch).To(Equal(reconcile.Request{ |
| 171 | + // NamespacedName: types.NamespacedName{Namespace: "default", Name: "deploy-name"}})) |
| 172 | + // |
| 173 | + // close(done) |
| 174 | + // }, 10) |
| 175 | + //}) |
| 176 | +}) |
| 177 | + |
| 178 | +var _ runtime.Object = fakeType("") |
| 179 | + |
| 180 | +type fakeType string |
| 181 | + |
| 182 | +func (fakeType) GetObjectKind() schema.ObjectKind { return nil } |
| 183 | +func (fakeType) DeepCopyObject() runtime.Object { return nil } |
0 commit comments