Skip to content

Latest commit

 

History

History
94 lines (72 loc) · 2.52 KB

File metadata and controls

94 lines (72 loc) · 2.52 KB

Building and testing the CLI

How to build

go build -o konflux-build-cli main.go

or statically:

CGO_ENABLED=0 go build -o konflux-build-cli main.go

or in debug mode:

go build -gcflags "all=-N -l" -o konflux-build-cli main.go

How to run / debug a command on host

Build the CLI and setup the command environment.

Parameters can be passed via CLI arguments or environment variables, CLI arguments take precedence.

./konflux-build-cli my-command --image-url quay.io/namespace/image:tag --digest sha256:abcde1234 --tags tag1 tag2 --result-sha=/tmp/my-command-result-sha

Alternatively, it's possible to provide data via environment variables:

# my-command-env.sh
export KBC_MYCOMMAND_IMAGE_URL=quay.io/namespace/image:tag
export KBC_MYCOMMAND_DIGEST=sha256:abcde1234
export KBC_MYCOMMAND_TAGS='tag1 tag2'
export KBC_MYCOMMAND_SOME_FLAG=true

export KBC_MYCOMMAND_RESULTS_DIR="/tmp/my-command-results"
mkdir -p "$RESULTS_DIR"
export KBC_MYCOMMAND_RESULT_SHA="${RESULTS_DIR}/RESULT_SHA"
. my-command-env.sh
./konflux-build-cli my-command

or mix approaches:

export KBC_MYCOMMAND_RESULT_FILE_SHA=/tmp/my-command-result-sha
./konflux-build-cli my-command --image-url quay.io/namespace/image:tag --digest sha256:abcde1234 --tags tag1 tag2

Running tests on macOS

On macOS, the /tmp directory is a symbolic link to the /private/tmp directory. Some unit tests and integration tests rely on verbatim path comparisons. To avoid unexpected failures, you can set the TMPDIR environment variable. For example:

mkdir .tmpdir
TMPDIR="$(pwd)/.tmpdir" go test ./...

How to run unit tests

To run all unit tests:

go test ./pkg/...

To run or debug a specific test or run all tests in a single file, it's most convenient to use UI of your IDE. To run specific test from terminal execute:

go test -run ^TestMyCommand_SuccessScenario$ ./pkg/...

or for all tests in single package:

go test ./pkg/commands

How to run integration tests

Integration tests are located under integration_tests directory. Check integration tests doc for more information.

Updating the dockerfile-json dependency

The github.com/konflux-ci/dockerfile-json dependency uses a replace directive in go.mod that points to a specific commit from the dev branch. Update to the latest version with:

go mod edit -replace github.com/keilerkonzept/dockerfile-json=github.com/konflux-ci/dockerfile-json@dev
go mod tidy