#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

echo "==> Detecting breaking changes"

TEST_PATHS=(
	client_test.go
	completion_test.go
	message_test.go
	messagebatch_test.go
	model_test.go
	betamodel_test.go
	betamessage_test.go
	betamessagebatch_test.go
	betaagent_test.go
	betaagentversion_test.go
	betaenvironment_test.go
	betaenvironmentwork_test.go
	betasession_test.go
	betasessionevent_test.go
	betasessionresource_test.go
	betasessionthread_test.go
	betasessionthreadevent_test.go
	betavault_test.go
	betavaultcredential_test.go
	betamemorystore_test.go
	betamemorystorememory_test.go
	betamemorystorememoryversion_test.go
	betafile_test.go
	betaskill_test.go
	betaskillversion_test.go
	betawebhook_test.go
	betauserprofile_test.go
	usage_test.go
	paginationauto_test.go
	paginationmanual_test.go
)

for PATHSPEC in "${TEST_PATHS[@]}"; do
    # Try to check out previous versions of the test files
    # with the current SDK.
    git checkout "$1" -- "${PATHSPEC}" 2>/dev/null || true
done

# Instead of running the tests, use the linter to check if an
# older test is no longer compatible with the latest SDK.
./scripts/lint
