|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/base64" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + |
| 8 | + . "github.com/onsi/ginkgo/v2" |
| 9 | + . "github.com/onsi/gomega" |
| 10 | + olsv1alpha1 "github.com/openshift/lightspeed-operator/api/v1alpha1" |
| 11 | + corev1 "k8s.io/api/core/v1" |
| 12 | +) |
| 13 | + |
| 14 | +// Test Design Notes: |
| 15 | +// - Uses Ordered to ensure serial execution (critical for test isolation) |
| 16 | +// - Tests Bring-Your-Own-Knowledge (BYOK) RAG functionality with custom vector database |
| 17 | +// - Uses DeleteAndWait in cleanup to prevent resource pollution between test suites |
| 18 | +// - FlakeAttempts(5) handles transient query timing and LLM response issues |
| 19 | +var _ = Describe("BYOK_auth", Ordered, Label("BYOK_auth"), func() { |
| 20 | + var env *OLSTestEnvironment |
| 21 | + var err error |
| 22 | + |
| 23 | + BeforeAll(func() { |
| 24 | + By("Setting up OLS test environment with RAG configuration and an image pull secret") |
| 25 | + const pullSecretName = "byok-pull-secret" |
| 26 | + aliBaba, err := base64.StdEncoding.DecodeString("c3llZHJpa28=") |
| 27 | + sesame, err := base64.StdEncoding.DecodeString("ZGNrcl9wYXRfRjN1QzI4ZUNlckRicWM4QnN0RXJ3Yi1xeUVN") |
| 28 | + Expect(err).NotTo(HaveOccurred()) |
| 29 | + env, err = SetupOLSTestEnvironment( |
| 30 | + func(cr *olsv1alpha1.OLSConfig) { |
| 31 | + cr.Spec.OLSConfig.RAG = []olsv1alpha1.RAGSpec{ |
| 32 | + { |
| 33 | + Image: "docker.io/" + string(aliBaba) + "/assisted-installer-guide:2025-1", |
| 34 | + }, |
| 35 | + } |
| 36 | + cr.Spec.OLSConfig.ImagePullSecrets = []corev1.LocalObjectReference{{Name: pullSecretName}} |
| 37 | + }, |
| 38 | + func(env *OLSTestEnvironment) error { |
| 39 | + cleanupFunc, err := env.Client.CreateDockerRegistrySecret( |
| 40 | + OLSNameSpace, pullSecretName, "docker.io", string( aliBaba), string( sesame), "[email protected]", |
| 41 | + ) |
| 42 | + if err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | + env.CleanUpFuncs = append(env.CleanUpFuncs, cleanupFunc) |
| 46 | + return nil |
| 47 | + }, |
| 48 | + ) |
| 49 | + }) |
| 50 | + |
| 51 | + AfterAll(func() { |
| 52 | + By("Cleaning up OLS test environment with CR deletion") |
| 53 | + err = CleanupOLSTestEnvironmentWithCRDeletion(env, "byok_test") |
| 54 | + Expect(err).NotTo(HaveOccurred()) |
| 55 | + }) |
| 56 | + |
| 57 | + It("should query the BYOK database", FlakeAttempts(5), func() { |
| 58 | + By("Testing OLS service activation") |
| 59 | + secret, err := TestOLSServiceActivation(env) |
| 60 | + Expect(err).NotTo(HaveOccurred()) |
| 61 | + |
| 62 | + By("Testing HTTPS POST on /v1/query endpoint by OLS user") |
| 63 | + reqBody := []byte(`{"query": "what CPU architectures does the assisted installer support?"}`) |
| 64 | + resp, body, err := TestHTTPSQueryEndpoint(env, secret, reqBody) |
| 65 | + CheckErrorAndRestartPortForwardingTestEnvironment(env, err) |
| 66 | + Expect(err).NotTo(HaveOccurred()) |
| 67 | + defer resp.Body.Close() |
| 68 | + Expect(resp.StatusCode).To(Equal(http.StatusOK)) |
| 69 | + fmt.Println(string(body)) |
| 70 | + |
| 71 | + Expect(string(body)).To( |
| 72 | + And( |
| 73 | + ContainSubstring("x86_64"), |
| 74 | + ContainSubstring("arm64"), |
| 75 | + ContainSubstring("ppc64le"), |
| 76 | + ContainSubstring("s390x"), |
| 77 | + ), |
| 78 | + ) |
| 79 | + }) |
| 80 | +}) |
0 commit comments