Example: use TESTS_DATABRICKS_HOST in integration tests

This serves 2 purposes:
 - flag to enable integration tests; without this env var they are not run
 - way to pass DATABRICKS_HOST without accidentally picking user's real config
This commit is contained in:
Denis Bilenko 2024-12-13 11:24:10 +01:00
parent 61b0c59137
commit c26b724946
1 changed files with 23 additions and 0 deletions

23
internal/main_test.go Normal file
View File

@ -0,0 +1,23 @@
package internal
import (
"fmt"
"os"
"testing"
)
func TestMain(m *testing.M) {
// 1. Redefine env vars to avoid accidentally picking up user's credentials
// 2. TESTS_DATABRICKS_TOKEN is also a gate enabling integration tests
host := os.Getenv("TESTS_DATABRICKS_HOST")
if host == "" {
fmt.Println("TESTS_DATABRICKS_HOST is not set, skipping integration tests")
return
}
token := os.Getenv("TESTS_DATABRICKS_TOKEN")
os.Setenv("DATABRICKS_HOST", host)
os.Setenv("DATABRICKS_TOKEN", token)
m.Run()
}