VERSION 0.8
PROJECT earthly-technologies/core
FROM --pass-args ..+base

IMPORT .. AS tests

WORKDIR /test

test:
    RUN earthly web 2>&1 | grep -qE "https://cloud.earthly.dev/login"
    RUN earthly web --provider github 2>output-file \
        && output=$(cat output-file) \
        && rm output-file \
        && if [[ "$output" != *"provider=github"* ]]; then echo "failed to find provider=github in output" && exit 1; fi

    RUN --secret EARTHLY_TOKEN=fake-user-write-token earthly web 2>&1 | grep -qE "https://cloud.earthly.dev/login\?token=.+"
    RUN --secret EARTHLY_TOKEN=fake-user-write-token earthly web --provider github 2>output-file \
        && output=$(cat output-file) \
        && rm output-file \
        && if [[ "$output" != *"provider=github"* ]]; then echo "failed to find provider=github in output" && exit 1; fi \
        && if [[ "$output" != *"token="* ]]; then echo "failed to find provider= in output" && exit 1; fi

    # test correct address if staging
    ENV EARTHLY_GRPC_ADDRESS=some.staging-url.dev
    RUN earthly web 2>&1 | grep -qE "https://cloud.staging.earthly.dev/login"
    RUN earthly web --provider github 2>output-file \
        && output=$(cat output-file) \
        && rm output-file \
        && if [[ "$output" != *"provider=github"* ]]; then echo "failed to find provider=github in output" && exit 1; fi

    # test correct address if local dev
    ENV EARTHLY_GRPC_ADDRESS=earthly.local:80
    RUN earthly web 2>&1 | grep -qE "http://earthly.local:3000/login"
    RUN earthly web --provider github 2>output-file \
        && output=$(cat output-file) \
        && rm output-file \
        && if [[ "$output" != *"provider=github"* ]]; then echo "failed to find provider=github in output" && exit 1; fi
