github.com/freiheit-com/kuberpult@v1.24.2-0.20240328135542-315d5630abe6/pkg/tracing/service_test.go (about) 1 /*This file is part of kuberpult. 2 3 Kuberpult is free software: you can redistribute it and/or modify 4 it under the terms of the Expat(MIT) License as published by 5 the Free Software Foundation. 6 7 Kuberpult is distributed in the hope that it will be useful, 8 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 MIT License for more details. 11 12 You should have received a copy of the MIT License 13 along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. 14 15 Copyright 2023 freiheit.com*/ 16 17 package tracing 18 19 import "testing" 20 21 func TestServiceName(t *testing.T) { 22 tcs := []struct { 23 Name string 24 DdServiceEnv string 25 DefaultName string 26 ExpectedName string 27 }{ 28 { 29 Name: "takes the default name without dd service name", 30 DdServiceEnv: "", 31 DefaultName: "foo", 32 ExpectedName: "foo", 33 }, 34 { 35 Name: "prefers the dd service name over the default", 36 DdServiceEnv: "bar", 37 DefaultName: "foo", 38 ExpectedName: "bar", 39 }, 40 } 41 42 for _, tc := range tcs { 43 tc := tc 44 t.Run(tc.Name, func(t *testing.T) { 45 t.Setenv("DD_SERVICE", tc.DdServiceEnv) 46 result := ServiceName(tc.DefaultName) 47 if result != tc.ExpectedName { 48 t.Errorf("wrong service name, expected %q, got %q", tc.ExpectedName, result) 49 } 50 }) 51 } 52 53 }