2023-07-05 15:30:54 +00:00
|
|
|
package acc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
2023-10-16 06:56:06 +00:00
|
|
|
"strings"
|
2023-07-05 15:30:54 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Detects if test is run from "debug test" feature in VS Code.
|
|
|
|
func isInDebug() bool {
|
|
|
|
ex, _ := os.Executable()
|
2023-10-16 06:56:06 +00:00
|
|
|
return strings.HasPrefix(path.Base(ex), "__debug_bin")
|
2023-07-05 15:30:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Loads debug environment from ~/.databricks/debug-env.json.
|
|
|
|
func loadDebugEnvIfRunFromIDE(t *testing.T, key string) {
|
|
|
|
if !isInDebug() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
home, err := os.UserHomeDir()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot find user home: %s", err)
|
|
|
|
}
|
|
|
|
raw, err := os.ReadFile(filepath.Join(home, ".databricks/debug-env.json"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot load ~/.databricks/debug-env.json: %s", err)
|
|
|
|
}
|
|
|
|
var conf map[string]map[string]string
|
|
|
|
err = json.Unmarshal(raw, &conf)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("cannot parse ~/.databricks/debug-env.json: %s", err)
|
|
|
|
}
|
|
|
|
vars, ok := conf[key]
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("~/.databricks/debug-env.json#%s not configured", key)
|
|
|
|
}
|
|
|
|
for k, v := range vars {
|
|
|
|
os.Setenv(k, v)
|
|
|
|
}
|
|
|
|
}
|