|
| 1 | +package controller |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + . "github.com/onsi/ginkgo/v2" |
| 7 | + . "github.com/onsi/gomega" |
| 8 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 9 | + "k8s.io/apimachinery/pkg/types" |
| 10 | + "sigs.k8s.io/controller-runtime/pkg/reconcile" |
| 11 | + |
| 12 | + impv1alpha1 "github.com/syscode-labs/imp/api/v1alpha1" |
| 13 | +) |
| 14 | + |
| 15 | +func newSnapshotReconciler() *ImpVMSnapshotReconciler { |
| 16 | + return &ImpVMSnapshotReconciler{ |
| 17 | + Client: k8sClient, |
| 18 | + Scheme: k8sClient.Scheme(), |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +var _ = Describe("ImpVMSnapshot controller", func() { |
| 23 | + ctx := context.Background() |
| 24 | + |
| 25 | + It("sets phase to Pending on creation", func() { |
| 26 | + snap := &impv1alpha1.ImpVMSnapshot{ |
| 27 | + ObjectMeta: metav1.ObjectMeta{ |
| 28 | + Name: "snap-ctrl-test", |
| 29 | + Namespace: "default", |
| 30 | + }, |
| 31 | + Spec: impv1alpha1.ImpVMSnapshotSpec{ |
| 32 | + SourceVMName: "vm-does-not-exist", |
| 33 | + SourceVMNamespace: "default", |
| 34 | + Storage: impv1alpha1.SnapshotStorageSpec{Type: "node-local"}, |
| 35 | + }, |
| 36 | + } |
| 37 | + Expect(k8sClient.Create(ctx, snap)).To(Succeed()) |
| 38 | + DeferCleanup(func() { k8sClient.Delete(ctx, snap) }) //nolint:errcheck |
| 39 | + |
| 40 | + r := newSnapshotReconciler() |
| 41 | + _, err := r.Reconcile(ctx, reconcile.Request{ |
| 42 | + NamespacedName: types.NamespacedName{Name: "snap-ctrl-test", Namespace: "default"}, |
| 43 | + }) |
| 44 | + Expect(err).NotTo(HaveOccurred()) |
| 45 | + |
| 46 | + updated := &impv1alpha1.ImpVMSnapshot{} |
| 47 | + Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "snap-ctrl-test", Namespace: "default"}, updated)).To(Succeed()) |
| 48 | + Expect(updated.Status.Phase).NotTo(BeEmpty()) |
| 49 | + Expect(updated.Status.Phase).To(Equal("Pending")) |
| 50 | + }) |
| 51 | +}) |
0 commit comments