|
| 1 | +// Copyright 2023 Red Hat, Inc. and/or its affiliates |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package platform |
| 16 | + |
| 17 | +import ( |
| 18 | + "os" |
| 19 | + "regexp" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/stretchr/testify/assert" |
| 23 | + |
| 24 | + "github.com/kiegroup/kogito-serverless-operator/test" |
| 25 | +) |
| 26 | + |
| 27 | +func TestSonataFlowBuildController(t *testing.T) { |
| 28 | + platform := test.GetBasePlatform() |
| 29 | + dockerfileBytes, err := os.ReadFile("../../test/builder/Dockerfile") |
| 30 | + if err != nil { |
| 31 | + assert.Fail(t, "Unable to read base Dockerfile") |
| 32 | + } |
| 33 | + dockerfile := string(dockerfileBytes) |
| 34 | + // 1 - Let's verify that the default image is used (for this unit test is quay.io/kiegroup/kogito-swf-builder-nightly:latest) |
| 35 | + resDefault := GetCustomizedDockerfile(dockerfile, *platform) |
| 36 | + foundDefault, err := regexp.MatchString("FROM quay.io/kiegroup/kogito-swf-builder-nightly:latest AS builder", resDefault) |
| 37 | + assert.NoError(t, err) |
| 38 | + assert.True(t, foundDefault) |
| 39 | + |
| 40 | + // 2 - Let's try to override using the productized image |
| 41 | + platform.Spec.BuildPlatform.BaseImage = "registry.access.redhat.com/openshift-serverless-1-tech-preview/logic-swf-builder-rhel8" |
| 42 | + resProductized := GetCustomizedDockerfile(dockerfile, *platform) |
| 43 | + foundProductized, err := regexp.MatchString("FROM registry.access.redhat.com/openshift-serverless-1-tech-preview/logic-swf-builder-rhel8 AS builder", resProductized) |
| 44 | + assert.NoError(t, err) |
| 45 | + assert.True(t, foundProductized) |
| 46 | +} |
0 commit comments