From c26b724946b0fc868b056a255f22728b22a052f7 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 13 Dec 2024 11:24:10 +0100 Subject: [PATCH] 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 --- internal/main_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 internal/main_test.go diff --git a/internal/main_test.go b/internal/main_test.go new file mode 100644 index 00000000..e77e2fde --- /dev/null +++ b/internal/main_test.go @@ -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() +}