http_upstream_profile_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "context"
  4. "testing"
  5. )
  6. func TestWithHTTPUpstreamProfile_DefaultKeepsContext(t *testing.T) {
  7. ctx := context.Background()
  8. got := WithHTTPUpstreamProfile(ctx, HTTPUpstreamProfileDefault)
  9. if got != ctx {
  10. t.Fatal("default profile should not wrap context")
  11. }
  12. }
  13. func TestWithHTTPUpstreamProfile_OpenAI(t *testing.T) {
  14. ctx := WithHTTPUpstreamProfile(context.TODO(), HTTPUpstreamProfileOpenAI)
  15. if profile := HTTPUpstreamProfileFromContext(ctx); profile != HTTPUpstreamProfileOpenAI {
  16. t.Fatalf("expected profile %q, got %q", HTTPUpstreamProfileOpenAI, profile)
  17. }
  18. }
  19. func TestWithHTTPUpstreamProfile_LongStream(t *testing.T) {
  20. ctx := WithHTTPUpstreamProfile(context.TODO(), HTTPUpstreamProfileLongStream)
  21. if profile := HTTPUpstreamProfileFromContext(ctx); profile != HTTPUpstreamProfileLongStream {
  22. t.Fatalf("expected profile %q, got %q", HTTPUpstreamProfileLongStream, profile)
  23. }
  24. }
  25. func TestWithHTTPUpstreamRedirectsDisabled(t *testing.T) {
  26. //nolint:staticcheck // Exercises the defensive nil-context fallback.
  27. ctx := WithHTTPUpstreamRedirectsDisabled(nil)
  28. if !HTTPUpstreamRedirectsDisabled(ctx) {
  29. t.Fatal("expected redirects to be disabled")
  30. }
  31. if HTTPUpstreamRedirectsDisabled(context.Background()) {
  32. t.Fatal("redirects should remain enabled by default")
  33. }
  34. }
  35. func TestWithHTTPUpstreamPublicHostsOnly(t *testing.T) {
  36. //nolint:staticcheck // Exercises the defensive nil-context fallback.
  37. ctx := WithHTTPUpstreamPublicHostsOnly(nil)
  38. if !HTTPUpstreamPublicHostsOnly(ctx) {
  39. t.Fatal("expected public-hosts-only marker to be set")
  40. }
  41. if HTTPUpstreamPublicHostsOnly(context.Background()) {
  42. t.Fatal("marker must be absent by default")
  43. }
  44. if HTTPUpstreamRedirectsDisabled(ctx) {
  45. t.Fatal("public-hosts-only must not disable redirects")
  46. }
  47. }