|
| 1 | +package useragent |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/databricks/databricks-sdk-go/internal/env" |
| 7 | +) |
| 8 | + |
| 9 | +func TestLookupHarnessProvider(t *testing.T) { |
| 10 | + tests := []struct { |
| 11 | + name string |
| 12 | + envs map[string]string |
| 13 | + expect string |
| 14 | + }{ |
| 15 | + { |
| 16 | + name: "no harness", |
| 17 | + envs: nil, |
| 18 | + expect: "", |
| 19 | + }, |
| 20 | + { |
| 21 | + name: "omnigent", |
| 22 | + envs: map[string]string{"OMNIGENT": "1"}, |
| 23 | + expect: "omnigent", |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "omnigent empty value still counts as set", |
| 27 | + envs: map[string]string{"OMNIGENT": ""}, |
| 28 | + expect: "omnigent", |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "agent env var does not affect harness", |
| 32 | + envs: map[string]string{"CLAUDECODE": "1"}, |
| 33 | + expect: "", |
| 34 | + }, |
| 35 | + } |
| 36 | + |
| 37 | + for _, tt := range tests { |
| 38 | + t.Run(tt.name, func(t *testing.T) { |
| 39 | + env.CleanupEnvironment(t) |
| 40 | + ClearCache() |
| 41 | + for k, v := range tt.envs { |
| 42 | + t.Setenv(k, v) |
| 43 | + } |
| 44 | + got := lookupHarnessProvider() |
| 45 | + if got != tt.expect { |
| 46 | + t.Errorf("lookupHarnessProvider() = %q, want %q", got, tt.expect) |
| 47 | + } |
| 48 | + }) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestHarnessProviderCached(t *testing.T) { |
| 53 | + env.CleanupEnvironment(t) |
| 54 | + ClearCache() |
| 55 | + t.Setenv("OMNIGENT", "1") |
| 56 | + got := HarnessProvider() |
| 57 | + if got != "omnigent" { |
| 58 | + t.Errorf("HarnessProvider() = %q, want %q", got, "omnigent") |
| 59 | + } |
| 60 | + // Change env after caching. Cached result should persist. |
| 61 | + t.Setenv("OMNIGENT", "") |
| 62 | + got = HarnessProvider() |
| 63 | + if got != "omnigent" { |
| 64 | + t.Errorf("HarnessProvider() after cache = %q, want %q", got, "omnigent") |
| 65 | + } |
| 66 | +} |
0 commit comments