VERSION 0.8
FROM --pass-args ..+base

IMPORT .. AS tests

WORKDIR /test

test-all:
    BUILD +test-do-not-track

test-do-not-track:
    HOST api.earthly.dev 127.0.0.1
    ENV DO_NOT_TRACK 1
    COPY api-earthly-stub-server.py /bin/api-earthly-stub-server
    COPY api-earthly-stub-server-shutdown.py /bin/api-earthly-stub-server-shutdown
    COPY true.earth Earthfile
    COPY test-earthly-script.sh /tmp/test-earthly-script
    DO +RUN_EARTHLY_ARGS --exec_cmd=/tmp/test-earthly-script


RUN_EARTHLY_ARGS:
    FUNCTION
    ARG should_fail=false
    ARG output_contains
    ARG output_does_not_contain
    ARG pre_command
    ARG post_command
    DO --pass-args tests+RUN_EARTHLY \
        --should_fail=$should_fail \
        --output_contains=$output_contains \
        --output_does_not_contain=$output_does_not_contain \
        --pre_command=$pre_command \
        --post_command=$post_command \
        # Ensure no auto-skip requests when DO_NOT_TRACK enabled.
        --extra_args="--auto-skip --auto-skip-db-path=test.db"
