|
| 1 | +// SPDX-FileCopyrightText: 2025 SAP SE or an SAP affiliate company and IronCore contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +package server_test |
| 5 | + |
| 6 | +import ( |
| 7 | + iri "github.com/ironcore-dev/ironcore/iri/apis/machine/v1alpha1" |
| 8 | + irimeta "github.com/ironcore-dev/ironcore/iri/apis/meta/v1alpha1" |
| 9 | + . "github.com/onsi/ginkgo/v2" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | +) |
| 12 | + |
| 13 | +var _ = Describe("ListMachine", func() { |
| 14 | + It("should list machines", func(ctx SpecContext) { |
| 15 | + By("creating machines") |
| 16 | + createResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{ |
| 17 | + Machine: &iri.Machine{ |
| 18 | + Metadata: &irimeta.ObjectMetadata{ |
| 19 | + Labels: map[string]string{ |
| 20 | + "machinepoolletv1alpha1.MachineUIDLabel": "foo", |
| 21 | + }, |
| 22 | + }, |
| 23 | + Spec: &iri.MachineSpec{ |
| 24 | + Power: iri.Power_POWER_ON, |
| 25 | + Class: machineClassx3xlarge, |
| 26 | + }, |
| 27 | + }, |
| 28 | + }) |
| 29 | + Expect(err).NotTo(HaveOccurred()) |
| 30 | + Expect(createResp).NotTo(BeNil()) |
| 31 | + DeferCleanup(cleanupMachine(createResp.Machine.Metadata.Id)) |
| 32 | + |
| 33 | + createMachineResp, err := machineClient.CreateMachine(ctx, &iri.CreateMachineRequest{ |
| 34 | + Machine: &iri.Machine{ |
| 35 | + Metadata: &irimeta.ObjectMetadata{ |
| 36 | + Labels: map[string]string{ |
| 37 | + "machinepoolletv1alpha1.MachineUIDLabel": "bar", |
| 38 | + }, |
| 39 | + }, |
| 40 | + Spec: &iri.MachineSpec{ |
| 41 | + Power: iri.Power_POWER_ON, |
| 42 | + Class: machineClassx3xlarge, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }) |
| 46 | + Expect(err).NotTo(HaveOccurred()) |
| 47 | + Expect(createMachineResp).NotTo(BeNil()) |
| 48 | + DeferCleanup(cleanupMachine(createMachineResp.Machine.Metadata.Id)) |
| 49 | + |
| 50 | + By("ensuring the machines gets created in the store") |
| 51 | + Eventually(func(g Gomega) { |
| 52 | + msList, err := machineStore.List(ctx) |
| 53 | + g.Expect(err).NotTo(HaveOccurred()) |
| 54 | + g.Expect(msList).NotTo(BeEmpty()) |
| 55 | + g.Expect(msList).To(HaveLen(2)) |
| 56 | + }).Should(Succeed()) |
| 57 | + |
| 58 | + By("listing machines using machine Id") |
| 59 | + listResp, err := machineClient.ListMachines(ctx, &iri.ListMachinesRequest{ |
| 60 | + Filter: &iri.MachineFilter{ |
| 61 | + Id: createResp.Machine.Metadata.Id, |
| 62 | + }, |
| 63 | + }) |
| 64 | + Expect(err).NotTo(HaveOccurred()) |
| 65 | + Expect(listResp.Machines).NotTo(BeEmpty()) |
| 66 | + Expect(listResp.Machines).Should(HaveLen(1)) |
| 67 | + |
| 68 | + By("listing machines using correct Label selector") |
| 69 | + listResp, err = machineClient.ListMachines(ctx, &iri.ListMachinesRequest{ |
| 70 | + Filter: &iri.MachineFilter{ |
| 71 | + LabelSelector: map[string]string{ |
| 72 | + "machinepoolletv1alpha1.MachineUIDLabel": "foo", |
| 73 | + }, |
| 74 | + }, |
| 75 | + }) |
| 76 | + Expect(err).NotTo(HaveOccurred()) |
| 77 | + Expect(listResp.Machines).NotTo(BeEmpty()) |
| 78 | + Expect(listResp.Machines).Should(HaveLen(1)) |
| 79 | + |
| 80 | + By("listing machines using incorrect Label selector") |
| 81 | + listResp, err = machineClient.ListMachines(ctx, &iri.ListMachinesRequest{ |
| 82 | + Filter: &iri.MachineFilter{ |
| 83 | + LabelSelector: map[string]string{ |
| 84 | + "foo": "wrong", |
| 85 | + }, |
| 86 | + }, |
| 87 | + }) |
| 88 | + Expect(err).NotTo(HaveOccurred()) |
| 89 | + Expect(listResp).NotTo(BeNil()) |
| 90 | + Expect(listResp.Machines).To(BeEmpty()) |
| 91 | + }) |
| 92 | +}) |
0 commit comments