|
| 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 | + "net/http" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/go-logr/logr" |
| 11 | + bootv1alpha1 "github.com/ironcore-dev/boot-operator/api/v1alpha1" |
| 12 | + "github.com/ironcore-dev/boot-operator/server" |
| 13 | + . "github.com/onsi/ginkgo/v2" |
| 14 | + . "github.com/onsi/gomega" |
| 15 | + corev1 "k8s.io/api/core/v1" |
| 16 | + "k8s.io/apimachinery/pkg/runtime" |
| 17 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 18 | + "sigs.k8s.io/controller-runtime/pkg/client/fake" |
| 19 | +) |
| 20 | + |
| 21 | +var ( |
| 22 | + testServerAddr = ":30003" |
| 23 | + testServerURL = "http://localhost:30003" |
| 24 | + |
| 25 | + defaultUKIURL = "https://example.com/default.efi" |
| 26 | + ipxeServiceURL = "http://localhost:30004" |
| 27 | + |
| 28 | + k8sClient client.Client |
| 29 | +) |
| 30 | + |
| 31 | +func TestBootServer(t *testing.T) { |
| 32 | + RegisterFailHandler(Fail) |
| 33 | + RunSpecs(t, "Boot Server Suite") |
| 34 | +} |
| 35 | + |
| 36 | +var _ = BeforeSuite(func() { |
| 37 | + scheme := runtime.NewScheme() |
| 38 | + Expect(corev1.AddToScheme(scheme)).To(Succeed()) |
| 39 | + Expect(bootv1alpha1.AddToScheme(scheme)).To(Succeed()) |
| 40 | + |
| 41 | + k8sClient = fake.NewClientBuilder(). |
| 42 | + WithScheme(scheme). |
| 43 | + Build() |
| 44 | + |
| 45 | + go func() { |
| 46 | + defer GinkgoRecover() |
| 47 | + server.RunBootServer(testServerAddr, ipxeServiceURL, k8sClient, logr.Discard(), defaultUKIURL) |
| 48 | + }() |
| 49 | + |
| 50 | + Eventually(func() error { |
| 51 | + _, err := http.Get(testServerURL + "/httpboot") |
| 52 | + return err |
| 53 | + }, "5s", "200ms").Should(Succeed()) |
| 54 | +}) |
0 commit comments