|
| 1 | +package observability |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestNewObservabilityPlugin(t *testing.T) { |
| 8 | + expectedServiceName := "test-service" |
| 9 | + expectedServiceVersion := "1.0.0" |
| 10 | + |
| 11 | + plugin := NewObservabilityPlugin(WithServiceName(expectedServiceName), WithServiceVersion(expectedServiceVersion)) |
| 12 | + |
| 13 | + if plugin == nil { |
| 14 | + t.Fatal("Expected plugin to be created, got nil") |
| 15 | + } |
| 16 | + |
| 17 | + if plugin.config.serviceName != expectedServiceName { |
| 18 | + t.Errorf("Expected service name %s, got %s", expectedServiceName, plugin.config.serviceName) |
| 19 | + } |
| 20 | + |
| 21 | + if plugin.config.serviceVersion != expectedServiceVersion { |
| 22 | + t.Errorf("Expected service version %s, got %s", expectedServiceVersion, plugin.config.serviceVersion) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestNewObservabilityPlugin_WithDefaults(t *testing.T) { |
| 27 | + plugin := NewObservabilityPlugin() |
| 28 | + |
| 29 | + if plugin == nil { |
| 30 | + t.Fatal("Expected plugin to be created, got nil") |
| 31 | + } |
| 32 | + |
| 33 | + // Test that default values are empty strings |
| 34 | + if plugin.config.serviceName != "" { |
| 35 | + t.Errorf("Expected empty service name, got %s", plugin.config.serviceName) |
| 36 | + } |
| 37 | + |
| 38 | + if plugin.config.serviceVersion != "" { |
| 39 | + t.Errorf("Expected empty service version, got %s", plugin.config.serviceVersion) |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestNewObservabilityPlugin_WithPartialOptions(t *testing.T) { |
| 44 | + expectedServiceName := "partial-service" |
| 45 | + |
| 46 | + plugin := NewObservabilityPlugin(WithServiceName(expectedServiceName)) |
| 47 | + |
| 48 | + if plugin == nil { |
| 49 | + t.Fatal("Expected plugin to be created, got nil") |
| 50 | + } |
| 51 | + |
| 52 | + if plugin.config.serviceName != expectedServiceName { |
| 53 | + t.Errorf("Expected service name %s, got %s", expectedServiceName, plugin.config.serviceName) |
| 54 | + } |
| 55 | + |
| 56 | + // Service version should be empty when not provided |
| 57 | + if plugin.config.serviceVersion != "" { |
| 58 | + t.Errorf("Expected empty service version, got %s", plugin.config.serviceVersion) |
| 59 | + } |
| 60 | +} |
0 commit comments