Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -eu
set -o pipefail

configure_db "${DB}"
# shellcheck disable=SC2068
# Double-quoting array expansion here causes ginkgo to fail
go run github.com/onsi/ginkgo/v2/ginkgo ${@}
12 changes: 6 additions & 6 deletions cmd/locket/testrunner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"code.cloudfoundry.org/locket/cmd/locket/certauthority"
"code.cloudfoundry.org/locket/cmd/locket/config"
"code.cloudfoundry.org/tlsconfig"
. "github.com/onsi/gomega"
"github.com/onsi/gomega"
ginkgomon "github.com/tedsuo/ifrit/ginkgomon_v2"
)

Expand Down Expand Up @@ -56,14 +56,14 @@ func NewLocketRunner(locketBinPath string, fs ...func(cfg *config.LocketConfig))
}

locketConfig, err := os.CreateTemp("", "locket-config")
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())

locketConfigFilePath := locketConfig.Name()

encoder := json.NewEncoder(locketConfig)
err = encoder.Encode(cfg)
Expect(err).NotTo(HaveOccurred())
Expect(locketConfig.Close()).To(Succeed())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(locketConfig.Close()).To(gomega.Succeed())

return ginkgomon.New(ginkgomon.Config{
Name: "locket",
Expand All @@ -72,7 +72,7 @@ func NewLocketRunner(locketBinPath string, fs ...func(cfg *config.LocketConfig))
Command: exec.Command(locketBinPath, "-config="+locketConfigFilePath),
Cleanup: func() {
err := os.RemoveAll(locketConfigFilePath)
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
},
})
}
Expand All @@ -82,7 +82,7 @@ func LocketClientTLSConfig() *tls.Config {
tlsconfig.WithInternalServiceDefaults(),
tlsconfig.WithIdentityFromFile(certFile, keyFile),
).Client(tlsconfig.WithAuthorityFromFile(caCertFile))
Expect(err).NotTo(HaveOccurred())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
return tlsConfig
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module code.cloudfoundry.org/locket
go 1.26.0

require (
code.cloudfoundry.org/bbs v0.0.0-00010101000000-000000000000
code.cloudfoundry.org/clock v1.75.0
code.cloudfoundry.org/debugserver v0.102.0
code.cloudfoundry.org/diego-db-helpers v0.3.0
Expand Down
60 changes: 60 additions & 0 deletions scripts/create-docker-container.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -eu
set -o pipefail

THIS_FILE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CI="${THIS_FILE_DIR}/../../wg-app-platform-runtime-ci"
. "$CI/shared/helpers/git-helpers.bash"
REPO_NAME=$(git_get_remote_name)
REPO_PATH="${THIS_FILE_DIR}/../"
unset THIS_FILE_DIR

if [[ ${DB:-empty} == "empty" ]]; then
DB=mysql
fi

CONTAINER_NAME="$REPO_NAME-$DB-docker-container"
if [[ "${DB}" == "mysql" ]] || [[ "${DB}" == "mysql-8.0" ]]; then
IMAGE="cloudfoundry/tas-runtime-mysql-8.0"
DB="mysql"
elif [[ "${DB}" == "mysql-5.7" ]]; then
IMAGE="cloudfoundry/tas-runtime-mysql-5.7"
DB="mysql"
elif [[ "${DB}" == "mysql-8.4" ]]; then
IMAGE="cloudfoundry/tas-runtime-mysql-8.4"
DB="mysql"
elif [[ "${DB}" == "mysql-9.7" ]]; then
IMAGE="cloudfoundry/tas-runtime-mysql-9.7"
DB="mysql"
elif [[ "${DB}" == "postgres" ]]; then
IMAGE="cloudfoundry/tas-runtime-postgres"
else
echo "Unsupported DB flavor"
exit 1
fi

DB_USER="root"
DB_PASSWORD="password"

if [[ $# -eq 0 ]]; then
ARGS=(-it)
else
ARGS=("${@}")
fi

docker pull "${IMAGE}"
docker rm -f "${CONTAINER_NAME}" || true
docker run \
--env "DB=${DB}" \
--env "DB_USER=${DB_USER}" \
--env "DB_PASSWORD=${DB_PASSWORD}" \
--env "REPO_NAME=$REPO_NAME" \
--env "REPO_PATH=/repo" \
--rm \
--name "$CONTAINER_NAME" \
-v "${REPO_PATH}:/repo" \
-v "${CI}:/ci" \
"${ARGS[@]}" \
"${IMAGE}" \
/bin/bash
26 changes: 26 additions & 0 deletions scripts/docker/test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -eu
set -o pipefail

. "/ci/shared/helpers/git-helpers.bash"

function test() {
local package="${1:?Provide a package}"
local sub_package="${2:-}"

export DIR=${package}
. <(/ci/shared/helpers/extract-default-params-for-task.bash /ci/shared/tasks/run-bin-test/linux.yml)

export GOFLAGS="-buildvcs=false"
export DB="${DB}"
/ci/shared/tasks/run-bin-test/task.bash "${sub_package}"
}

pushd / > /dev/null
if [[ -n "${1:-}" ]]; then
test "${1}" "${2:-}"
else
test "."
fi
popd > /dev/null
17 changes: 17 additions & 0 deletions scripts/test-in-docker.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -eu

THIS_FILE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CI="${THIS_FILE_DIR}/../../wg-app-platform-runtime-ci"
. "$CI/shared/helpers/git-helpers.bash"
REPO_NAME=$(git_get_remote_name)

if [[ ${DB:-empty} == "empty" ]]; then
DB=mysql
fi
CONTAINER_NAME="$REPO_NAME-$DB-docker-container"

DB="${DB}" "${THIS_FILE_DIR}/create-docker-container.bash" -td

docker exec $CONTAINER_NAME '/repo/scripts/docker/test.bash' "$@"