|
| 1 | +package idrange_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + . "github.com/onsi/ginkgo/v2" |
| 8 | + . "github.com/onsi/gomega" |
| 9 | + |
| 10 | + "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/framework" |
| 11 | + "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scheduler/plugins/idrange" |
| 12 | +) |
| 13 | + |
| 14 | +func TestIDRange(t *testing.T) { |
| 15 | + RegisterFailHandler(Fail) |
| 16 | + RunSpecs(t, "idrange plugin") |
| 17 | +} |
| 18 | + |
| 19 | +var _ = Describe("findVMIDRange", Label("unit", "plugins"), func() { |
| 20 | + ctx := context.Background() |
| 21 | + |
| 22 | + Context("no 'vmid.qemu-scheduler/range' key in the context", func() { |
| 23 | + It("should error", func() { |
| 24 | + start, end, err := idrange.FindVMIDRange(ctx) |
| 25 | + Expect(start).To(Equal(0)) |
| 26 | + Expect(end).To(Equal(0)) |
| 27 | + Expect(err.Error()).To(Equal("no vmid range is specified")) |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + Context("specify invalid range (start)", func() { |
| 32 | + It("should error", func() { |
| 33 | + c := context.WithValue(ctx, framework.CtxKey(idrange.VMIDRangeKey), "a-10") |
| 34 | + start, end, err := idrange.FindVMIDRange(c) |
| 35 | + Expect(start).To(Equal(0)) |
| 36 | + Expect(end).To(Equal(0)) |
| 37 | + Expect(err.Error()).To(ContainSubstring("invalid range is specified")) |
| 38 | + }) |
| 39 | + }) |
| 40 | + |
| 41 | + Context("specify invalid range (end)", func() { |
| 42 | + It("should error", func() { |
| 43 | + c := context.WithValue(ctx, framework.CtxKey(idrange.VMIDRangeKey), "10-b") |
| 44 | + start, end, err := idrange.FindVMIDRange(c) |
| 45 | + Expect(start).To(Equal(0)) |
| 46 | + Expect(end).To(Equal(0)) |
| 47 | + Expect(err.Error()).To(ContainSubstring("invalid range is specified")) |
| 48 | + }) |
| 49 | + }) |
| 50 | + |
| 51 | + Context("specify valid range", func() { |
| 52 | + It("should not error", func() { |
| 53 | + c := context.WithValue(ctx, framework.CtxKey(idrange.VMIDRangeKey), "10-20") |
| 54 | + start, end, err := idrange.FindVMIDRange(c) |
| 55 | + Expect(start).To(Equal(10)) |
| 56 | + Expect(end).To(Equal(20)) |
| 57 | + Expect(err).ToNot(HaveOccurred()) |
| 58 | + }) |
| 59 | + }) |
| 60 | +}) |
0 commit comments