#!/usr/bin/env bash

unset GITHUB_TOKEN GITHUB_API_TOKEN

# Create an ubi stub that just output the value of GITHUB_TOKEN
cat >~/bin/ubi <<'EOF'
#!/usr/bin/env bash
echo "token=$GITHUB_TOKEN"
EOF
chmod u+x ~/bin/ubi
export PATH="$HOME/bin:$PATH"

# This should reuse the existing GITHUB_TOKEN variable
assert_contains "GITHUB_TOKEN=foobar mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar"

# This should use the GITHUB_API_TOKEN variable
assert_contains "GITHUB_API_TOKEN=foobar mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar"

# This should prefer GITHUB_API_TOKEN
assert_contains "GITHUB_TOKEN=foobar GITHUB_API_TOKEN=barquz mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar"
