Skip to content

Commit

Permalink
test: add test with lagoon and docker-compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Oct 21, 2024
1 parent 6868c3a commit b02abbb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
62 changes: 59 additions & 3 deletions cmd/identify_imagebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"testing"

"github.com/andreyvit/diff"
"github.com/uselagoon/build-deploy-tool/internal/dbaasclient"
"github.com/uselagoon/build-deploy-tool/internal/generator"
"github.com/uselagoon/build-deploy-tool/internal/helpers"
Expand Down Expand Up @@ -752,6 +753,61 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
},
},
},
{
name: "test12 Force Pull Base Images with variable replacement",
args: testdata.GetSeedData(
testdata.TestData{
Namespace: "example-project-main",
ProjectName: "example-project",
EnvironmentName: "main",
Branch: "main",
LagoonYAML: "internal/testdata/basic/lagoon.forcebaseimagepull-2.yml",
ProjectVariables: []lagoon.EnvironmentVariable{
{
Name: "BASE_IMAGE_TAG",
Value: "my-tag",
Scope: "build",
},
{
Name: "BASE_IMAGE_REPO",
Value: "my-repo",
Scope: "build",
},
},
}, true),
want: imageBuild{
BuildKit: helpers.BoolPtr(true),
BuildArguments: map[string]string{
"BASE_IMAGE_TAG": "my-tag",
"BASE_IMAGE_REPO": "my-repo",
"LAGOON_BUILD_NAME": "lagoon-build-abcdefg",
"LAGOON_PROJECT": "example-project",
"LAGOON_ENVIRONMENT": "main",
"LAGOON_ENVIRONMENT_TYPE": "production",
"LAGOON_BUILD_TYPE": "branch",
"LAGOON_GIT_SOURCE_REPOSITORY": "ssh://git@example.com/lagoon-demo.git",
"LAGOON_KUBERNETES": "remote-cluster1",
"LAGOON_GIT_SHA": "abcdefg123456",
"LAGOON_GIT_BRANCH": "main",
"NODE_IMAGE": "example-project-main-node",
"LAGOON_SSH_PRIVATE_KEY": "-----BEGIN OPENSSH PRIVATE KEY-----\nthisisafakekey\n-----END OPENSSH PRIVATE KEY-----",
},
ForcePullImages: []string{
"registry.com/my-repo/imagename:my-tag",
},
Images: []imageBuilds{
{
Name: "node",
ImageBuild: generator.ImageBuild{
BuildImage: "harbor.example/example-project/main/node:latest",
Context: "internal/testdata/basic/docker",
DockerFile: "basic.dockerfile",
TemporaryImage: "example-project-main-node",
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -788,10 +844,10 @@ func TestImageBuildConfigurationIdentification(t *testing.T) {
t.Errorf("%v", err)
}

oJ, _ := json.Marshal(out)
wJ, _ := json.Marshal(tt.want)
oJ, _ := json.MarshalIndent(out, "", " ")
wJ, _ := json.MarshalIndent(tt.want, "", " ")
if string(oJ) != string(wJ) {
t.Errorf("returned output %v doesn't match want %v", string(oJ), string(wJ))
t.Errorf("ImageBuildConfigurationIdentification() = \n%v", diff.LineDiff(string(oJ), string(wJ)))
}
t.Cleanup(func() {
helpers.UnsetEnvVars(tt.vars)
Expand Down
23 changes: 23 additions & 0 deletions internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '2'
services:
node:
networks:
- amazeeio-network
- default
build:
context: internal/testdata/basic/docker
dockerfile: basic.dockerfile
labels:
lagoon.type: basic
lagoon.service.usecomposeports: true
lagoon.base.image: registry.com/${BASE_IMAGE_REPO:-namespace}/imagename:${BASE_IMAGE_TAG:-latest}
volumes:
- .:/app:delegated
ports:
- '1234'
- '8191'
- '9001/udp'

networks:
amazeeio-network:
external: true
10 changes: 10 additions & 0 deletions internal/testdata/basic/lagoon.forcebaseimagepull-2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
docker-compose-yaml: internal/testdata/basic/docker-compose.forcebaseimagepull-2.yml

environment_variables:
git_sha: "true"

environments:
main:
routes:
- node:
- example.com

0 comments on commit b02abbb

Please sign in to comment.