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

Method TestSetLabels

stats/opentelemetry/csm/pluginoption_test.go:309–464  ·  view source on GitHub ↗

TestSetLabels tests the setting of labels, which snapshots the resource and environment. It mocks the resource and environment, and then calls into labels creation. It verifies to local labels created and metadata exchange labels emitted from the setLabels function.

(t *testing.T)

Source from the content-addressed store, hash-verified

307// labels creation. It verifies to local labels created and metadata exchange
308// labels emitted from the setLabels function.
309func (s) TestSetLabels(t *testing.T) {
310 clearEnv()
311 tests := []struct {
312 name string
313 resourceKeyValues map[string]string
314 csmCanonicalServiceNamePopulated bool
315 csmWorkloadNamePopulated bool
316 meshIDPopulated bool
317 localLabelsWant map[string]string
318 metadataExchangeLabelsWant map[string]string
319 }{
320 {
321 name: "no-type",
322 csmCanonicalServiceNamePopulated: true,
323 meshIDPopulated: true,
324 resourceKeyValues: map[string]string{},
325 localLabelsWant: map[string]string{
326 "csm.workload_canonical_service": "canonical_service_name_val", // env var populated so should be set.
327 "csm.mesh_id": "mesh_id", // env var populated so should be set.
328 },
329 metadataExchangeLabelsWant: map[string]string{
330 "type": "unknown",
331 "canonical_service": "canonical_service_name_val", // env var populated so should be set.
332 },
333 },
334 {
335 name: "gce",
336 csmWorkloadNamePopulated: true,
337 resourceKeyValues: map[string]string{
338 "cloud.platform": "gcp_compute_engine",
339 // csm workload name is an env var
340 "cloud.availability_zone": "cloud_availability_zone_val",
341 "cloud.region": "should-be-ignored", // cloud.availability_zone takes precedence
342 "cloud.account.id": "cloud_account_id_val",
343 },
344 localLabelsWant: map[string]string{
345 "csm.workload_canonical_service": "unknown",
346 "csm.mesh_id": "unknown",
347 },
348 metadataExchangeLabelsWant: map[string]string{
349 "type": "gcp_compute_engine",
350 "canonical_service": "unknown",
351 "workload_name": "workload_name_val",
352 "location": "cloud_availability_zone_val",
353 "project_id": "cloud_account_id_val",
354 },
355 },
356 {
357 name: "gce-half-unset",
358 resourceKeyValues: map[string]string{
359 "cloud.platform": "gcp_compute_engine",
360 // csm workload name is an env var
361 "cloud.availability_zone": "cloud_availability_zone_val",
362 "cloud.region": "should-be-ignored", // cloud.availability_zone takes precedence
363 },
364 localLabelsWant: map[string]string{
365 "csm.workload_canonical_service": "unknown",
366 "csm.mesh_id": "unknown",

Callers

nothing calls this directly

Calls 5

clearEnvFunction · 0.85
constructMetadataFromEnvFunction · 0.85
StringMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected