| package main
|
|
|
| import (
|
| "os"
|
| "testing"
|
|
|
| "github.com/looplj/axonhub/gemini_test/internal/testutil"
|
| )
|
|
|
| func TestDisableTraceAndThread(t *testing.T) {
|
|
|
| os.Setenv("TEST_DISABLE_TRACE", "true")
|
| os.Setenv("TEST_DISABLE_THREAD", "true")
|
| os.Setenv("TEST_AXONHUB_API_KEY", "test-key")
|
|
|
| defer func() {
|
| os.Unsetenv("TEST_DISABLE_TRACE")
|
| os.Unsetenv("TEST_DISABLE_THREAD")
|
| os.Unsetenv("TEST_AXONHUB_API_KEY")
|
| }()
|
|
|
| config := testutil.DefaultConfig()
|
|
|
|
|
| if !config.DisableTrace {
|
| t.Error("Expected DisableTrace to be true")
|
| }
|
|
|
| if !config.DisableThread {
|
| t.Error("Expected DisableThread to be true")
|
| }
|
|
|
|
|
| if config.TraceID != "" {
|
| t.Errorf("Expected empty TraceID, got: %s", config.TraceID)
|
| }
|
|
|
| if config.ThreadID != "" {
|
| t.Errorf("Expected empty ThreadID, got: %s", config.ThreadID)
|
| }
|
|
|
|
|
| headers := config.GetHeaders()
|
| if len(headers) != 0 {
|
| t.Errorf("Expected no headers, got: %v", headers)
|
| }
|
|
|
|
|
| err := config.ValidateConfig()
|
| if err != nil {
|
| t.Errorf("Expected validation to pass, got error: %v", err)
|
| }
|
| }
|
|
|
| func TestDisableTraceOnly(t *testing.T) {
|
|
|
| os.Setenv("TEST_DISABLE_TRACE", "true")
|
| os.Setenv("TEST_AXONHUB_API_KEY", "test-key")
|
|
|
| defer func() {
|
| os.Unsetenv("TEST_DISABLE_TRACE")
|
| os.Unsetenv("TEST_AXONHUB_API_KEY")
|
| }()
|
|
|
| config := testutil.DefaultConfig()
|
|
|
|
|
| if !config.DisableTrace {
|
| t.Error("Expected DisableTrace to be true")
|
| }
|
|
|
| if config.DisableThread {
|
| t.Error("Expected DisableThread to be false")
|
| }
|
|
|
|
|
| if config.TraceID != "" {
|
| t.Errorf("Expected empty TraceID, got: %s", config.TraceID)
|
| }
|
|
|
| if config.ThreadID == "" {
|
| t.Error("Expected non-empty ThreadID")
|
| }
|
|
|
|
|
| headers := config.GetHeaders()
|
| if len(headers) != 1 {
|
| t.Errorf("Expected 1 header, got: %v", headers)
|
| }
|
|
|
| if _, exists := headers["AH-Trace-Id"]; exists {
|
| t.Error("Expected AH-Trace-Id header to be absent")
|
| }
|
|
|
| if _, exists := headers["AH-Thread-Id"]; !exists {
|
| t.Error("Expected AH-Thread-Id header to be present")
|
| }
|
| }
|
|
|
| func TestDisableThreadOnly(t *testing.T) {
|
|
|
| os.Setenv("TEST_DISABLE_THREAD", "true")
|
| os.Setenv("TEST_AXONHUB_API_KEY", "test-key")
|
|
|
| defer func() {
|
| os.Unsetenv("TEST_DISABLE_THREAD")
|
| os.Unsetenv("TEST_AXONHUB_API_KEY")
|
| }()
|
|
|
| config := testutil.DefaultConfig()
|
|
|
|
|
| if config.DisableTrace {
|
| t.Error("Expected DisableTrace to be false")
|
| }
|
|
|
| if !config.DisableThread {
|
| t.Error("Expected DisableThread to be true")
|
| }
|
|
|
|
|
| if config.ThreadID != "" {
|
| t.Errorf("Expected empty ThreadID, got: %s", config.ThreadID)
|
| }
|
|
|
| if config.TraceID == "" {
|
| t.Error("Expected non-empty TraceID")
|
| }
|
|
|
|
|
| headers := config.GetHeaders()
|
| if len(headers) != 1 {
|
| t.Errorf("Expected 1 header, got: %v", headers)
|
| }
|
|
|
| if _, exists := headers["AH-Thread-Id"]; exists {
|
| t.Error("Expected AH-Thread-Id header to be absent")
|
| }
|
|
|
| if _, exists := headers["AH-Trace-Id"]; !exists {
|
| t.Error("Expected AH-Trace-Id header to be present")
|
| }
|
| } |