Files
zeekay ee53f0bd67 refactor: migrate CRD API groups to hanzo.ai and labels to ingress.*
- CRD API group: traefik.io -> hanzo.ai (GroupName, apiVersion, RBAC)
- Docker/provider label prefix: traefik.* -> ingress.* (all providers)
- CRD kind: TraefikService -> IngressService
- Directory renames: traefikio/ -> hanzoai/ (types, generated code, listers, informers, clientset)
- Config root name: traefik -> ingress (KV stores, file paths, env prefix)
- Metrics prefix: traefik_ -> ingress_
- Kubernetes annotations: traefik.ingress.kubernetes.io/ -> ingress.kubernetes.io/
- Gateway annotations: traefik.io/ -> hanzo.ai/
- Internal provider package: provider/traefik -> provider/builtins
- Type renames: TraefikLog -> IngressLog, TraefikCmdConfiguration -> IngressCmdConfiguration
- Generated client methods: TraefikV1alpha1() -> HanzoV1alpha1(), Traefik() -> Hanzo()
- Sample configs: traefik.sample.{toml,yml} -> ingress.sample.{toml,yml}
- Config paths: /etc/traefik/ -> /etc/ingress/, ~/.config/traefik -> ~/.config/ingress
- Default cert CN: TRAEFIK DEFAULT CERT -> INGRESS DEFAULT CERT
2026-02-26 10:33:54 -08:00

80 lines
2.1 KiB
Go

package observability
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
)
func TestNewService(t *testing.T) {
type expected struct {
attributes []attribute.KeyValue
name string
}
testCases := []struct {
desc string
service string
expected []expected
}{
{
desc: "base",
service: "myService",
expected: []expected{
{
name: "GET",
attributes: []attribute.KeyValue{
attribute.String("span.kind", "server"),
},
},
{
name: "Service",
attributes: []attribute.KeyValue{
attribute.String("span.kind", "internal"),
attribute.String("http.request.method", "GET"),
attribute.Int64("http.response.status_code", int64(404)),
attribute.String("network.protocol.version", "1.1"),
attribute.String("server.address", "www.test.com"),
attribute.Int64("server.port", int64(80)),
attribute.String("url.full", "http://www.test.com/traces?p=OpenTelemetry"),
attribute.String("url.scheme", "http"),
attribute.String("ingress.service.name", "myService"),
attribute.String("user_agent.original", "service-test"),
},
},
},
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "http://www.test.com/traces?p=OpenTelemetry", nil)
req.RemoteAddr = "10.0.0.1:1234"
req.Header.Set("User-Agent", "service-test")
tracer := &mockTracer{}
tracingCtx, entryPointSpan := tracer.Start(req.Context(), http.MethodGet, trace.WithSpanKind(trace.SpanKindServer))
defer entryPointSpan.End()
req = req.WithContext(tracingCtx)
rw := httptest.NewRecorder()
next := http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {
rw.WriteHeader(http.StatusNotFound)
})
handler := NewService(t.Context(), test.service, next)
handler.ServeHTTP(rw, req)
for i, span := range tracer.spans {
assert.Equal(t, test.expected[i].name, span.name)
assert.Equal(t, test.expected[i].attributes, span.attributes)
}
})
}
}