Skip to content

Commit b02abbb

Browse files
committed
test: add test with lagoon and docker-compose files
1 parent 6868c3a commit b02abbb

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

cmd/identify_imagebuild_test.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"testing"
77

8+
"github.com/andreyvit/diff"
89
"github.com/uselagoon/build-deploy-tool/internal/dbaasclient"
910
"github.com/uselagoon/build-deploy-tool/internal/generator"
1011
"github.com/uselagoon/build-deploy-tool/internal/helpers"
@@ -752,6 +753,61 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
752753
},
753754
},
754755
},
756+
{
757+
name: "test12 Force Pull Base Images with variable replacement",
758+
args: testdata.GetSeedData(
759+
testdata.TestData{
760+
Namespace: "example-project-main",
761+
ProjectName: "example-project",
762+
EnvironmentName: "main",
763+
Branch: "main",
764+
LagoonYAML: "internal/testdata/basic/lagoon.forcebaseimagepull-2.yml",
765+
ProjectVariables: []lagoon.EnvironmentVariable{
766+
{
767+
Name: "BASE_IMAGE_TAG",
768+
Value: "my-tag",
769+
Scope: "build",
770+
},
771+
{
772+
Name: "BASE_IMAGE_REPO",
773+
Value: "my-repo",
774+
Scope: "build",
775+
},
776+
},
777+
}, true),
778+
want: imageBuild{
779+
BuildKit: helpers.BoolPtr(true),
780+
BuildArguments: map[string]string{
781+
"BASE_IMAGE_TAG": "my-tag",
782+
"BASE_IMAGE_REPO": "my-repo",
783+
"LAGOON_BUILD_NAME": "lagoon-build-abcdefg",
784+
"LAGOON_PROJECT": "example-project",
785+
"LAGOON_ENVIRONMENT": "main",
786+
"LAGOON_ENVIRONMENT_TYPE": "production",
787+
"LAGOON_BUILD_TYPE": "branch",
788+
"LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git",
789+
"LAGOON_KUBERNETES": "remote-cluster1",
790+
"LAGOON_GIT_SHA": "abcdefg123456",
791+
"LAGOON_GIT_BRANCH": "main",
792+
"NODE_IMAGE": "example-project-main-node",
793+
"LAGOON_SSH_PRIVATE_KEY": "-----BEGIN OPENSSH PRIVATE KEY-----\nthisisafakekey\n-----END OPENSSH PRIVATE KEY-----",
794+
},
795+
ForcePullImages: []string{
796+
"registry.com/my-repo/imagename:my-tag",
797+
},
798+
Images: []imageBuilds{
799+
{
800+
Name: "node",
801+
ImageBuild: generator.ImageBuild{
802+
BuildImage: "harbor.example/example-project/main/node:latest",
803+
Context: "internal/testdata/basic/docker",
804+
DockerFile: "basic.dockerfile",
805+
TemporaryImage: "example-project-main-node",
806+
},
807+
},
808+
},
809+
},
810+
},
755811
}
756812
for _, tt := range tests {
757813
t.Run(tt.name, func(t *testing.T) {
@@ -788,10 +844,10 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
788844
t.Errorf("%v", err)
789845
}
790846

791-
oJ, _ := json.Marshal(out)
792-
wJ, _ := json.Marshal(tt.want)
847+
oJ, _ := json.MarshalIndent(out, "", " ")
848+
wJ, _ := json.MarshalIndent(tt.want, "", " ")
793849
if string(oJ) != string(wJ) {
794-
t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ))
850+
t.Errorf("ImageBuildConfigurationIdentification() = \n%v", diff.LineDiff(string(oJ), string(wJ)))
795851
}
796852
t.Cleanup(func() {
797853
helpers.UnsetEnvVars(tt.vars)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: '2'
2+
services:
3+
node:
4+
networks:
5+
- amazeeio-network
6+
- default
7+
build:
8+
context: internal/testdata/basic/docker
9+
dockerfile: basic.dockerfile
10+
labels:
11+
lagoon.type: basic
12+
lagoon.service.usecomposeports: true
13+
lagoon.base.image: registry.com/${BASE_IMAGE_REPO:-namespace}/imagename:${BASE_IMAGE_TAG:-latest}
14+
volumes:
15+
- .:/app:delegated
16+
ports:
17+
- '1234'
18+
- '8191'
19+
- '9001/udp'
20+
21+
networks:
22+
amazeeio-network:
23+
external: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
docker-compose-yaml: internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml
2+
3+
environment_variables:
4+
git_sha: "true"
5+
6+
environments:
7+
main:
8+
routes:
9+
- node:
10+
- example.com

0 commit comments

Comments
 (0)