| 1 | // Copyright 2026 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package otelscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/ |
| 6 | |
| 7 | import ( |
| 8 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 9 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 10 | |
| 11 | "golang.org/x/tools/internal/event/keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/" |
| 12 | ) |
| 13 | |
| 14 | func TestLabelToAttribute_Stringscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/TestLabelToAttribute_String().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 15 | key := keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.NewStringscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/NewString().("mykey", "") |
| 16 | l := key.Ofscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/String#Of().("myvalue") |
| 17 | |
| 18 | attr, ok := labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l) |
| 19 | if !ok { |
| 20 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("expected ok=true") |
| 21 | } |
| 22 | if attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key. != "mykey" { |
| 23 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected key 'mykey', got %q", attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key.) |
| 24 | } |
| 25 | if attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue. == nil || *attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue. != "myvalue" { |
| 26 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected stringValue 'myvalue', got %v", attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TestLabelToAttribute_Intscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/TestLabelToAttribute_Int().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 31 | key := keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.NewIntscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/NewInt().("count", "") |
| 32 | l := key.Ofscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Int#Of().(42) |
| 33 | |
| 34 | attr, ok := labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l) |
| 35 | if !ok { |
| 36 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("expected ok=true") |
| 37 | } |
| 38 | if attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key. != "count" { |
| 39 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected key 'count', got %q", attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key.) |
| 40 | } |
| 41 | if attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue. == nil || *attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue. != 42 { |
| 42 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected intValue 42, got %v", attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..IntValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#IntValue.) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func TestLabelToAttribute_Floatscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/TestLabelToAttribute_Float().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 47 | key := keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.NewFloatscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/NewFloat().("ratio", "") |
| 48 | l := key.Ofscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Float#Of().(3.14) |
| 49 | |
| 50 | attr, ok := labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l) |
| 51 | if !ok { |
| 52 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("expected ok=true") |
| 53 | } |
| 54 | if attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key. != "ratio" { |
| 55 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected key 'ratio', got %q", attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key.) |
| 56 | } |
| 57 | if attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..DoubleValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#DoubleValue. == nil || *attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..DoubleValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#DoubleValue. != 3.14 { |
| 58 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected doubleValue 3.14, got %v", attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..DoubleValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#DoubleValue.) |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | func TestLabelToAttribute_Errorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/TestLabelToAttribute_Error().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 63 | key := keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.NewErrorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/NewError().("err", "") |
| 64 | l := key.Ofscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Error#Of().(errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("something failed")) |
| 65 | |
| 66 | attr, ok := labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l) |
| 67 | if !ok { |
| 68 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().("expected ok=true") |
| 69 | } |
| 70 | if attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key. != "err" { |
| 71 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected key 'err', got %q", attr.Keyscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Key.) |
| 72 | } |
| 73 | if attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue. == nil || *attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue. != "something failed" { |
| 74 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected stringValue 'something failed', got %v", attr.Valuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttribute#Value..StringValuescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/otlpAttributeValue#StringValue.) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func TestLabelToAttribute_NilErrorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/TestLabelToAttribute_NilError().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 79 | key := keysscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/.NewErrorscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/NewError().("err", "") |
| 80 | l := key.Ofscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/keys`/Error#Of().(nil) |
| 81 | |
| 82 | _, ok := labelToAttributescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/event/export/otel`/labelToAttribute().(l) |
| 83 | if ok { |
| 84 | t.Errorscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Error().("expected ok=false for nil error") |
| 85 | } |
| 86 | } |