MCPcopy
hub / github.com/grpc/grpc-go / TestGetLabels

Method TestGetLabels

stats/opentelemetry/csm/pluginoption_test.go:61–261  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func (s) TestGetLabels(t *testing.T) {
62 clearEnv()
63 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
64 defer cancel()
65 cpo := newPluginOption(ctx)
66
67 tests := []struct {
68 name string
69 unsetHeader bool // Should trigger "unknown" labels
70 twoValues bool // Should trigger "unknown" labels
71 metadataExchangeLabels map[string]string
72 labelsWant map[string]string
73 }{
74 {
75 name: "unset-labels",
76 metadataExchangeLabels: nil,
77 labelsWant: map[string]string{
78 "csm.workload_canonical_service": "unknown",
79 "csm.mesh_id": "unknown",
80
81 "csm.remote_workload_type": "unknown",
82 "csm.remote_workload_canonical_service": "unknown",
83 },
84 },
85 {
86 name: "metadata-partially-set",
87 metadataExchangeLabels: map[string]string{
88 "type": "not-gce-or-gke",
89 "ignore-this": "ignore-this",
90 },
91 labelsWant: map[string]string{
92 "csm.workload_canonical_service": "unknown",
93 "csm.mesh_id": "unknown",
94
95 "csm.remote_workload_type": "not-gce-or-gke",
96 "csm.remote_workload_canonical_service": "unknown",
97 },
98 },
99 {
100 name: "google-compute-engine",
101 metadataExchangeLabels: map[string]string{ // All of these labels get emitted when type is "gcp_compute_engine".
102 "type": "gcp_compute_engine",
103 "canonical_service": "canonical_service_val",
104 "project_id": "unique-id",
105 "location": "us-east",
106 "workload_name": "workload_name_val",
107 },
108 labelsWant: map[string]string{
109 "csm.workload_canonical_service": "unknown",
110 "csm.mesh_id": "unknown",
111
112 "csm.remote_workload_type": "gcp_compute_engine",
113 "csm.remote_workload_canonical_service": "canonical_service_val",
114 "csm.remote_workload_project_id": "unique-id",
115 "csm.remote_workload_location": "us-east",
116 "csm.remote_workload_name": "workload_name_val",
117 },
118 },

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
clearEnvFunction · 0.85
newPluginOptionFunction · 0.85
AppendMethod · 0.80
MarshalMethod · 0.65
FatalfMethod · 0.65
GetLabelsMethod · 0.65
DeleteMethod · 0.45

Tested by

no test coverage detected