github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/ddevapp/instrumentation_test.go (about) 1 package ddevapp_test 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/ddev/ddev/pkg/ddevapp" 9 "github.com/ddev/ddev/pkg/nodeps" 10 "github.com/ddev/ddev/pkg/testcommon" 11 "github.com/ddev/ddev/pkg/util" 12 asrt "github.com/stretchr/testify/assert" 13 ) 14 15 // TestSetInstrumentationAppTags checks to see that tags are properly set 16 // and tries to make sure no leakage happens with URLs or other 17 // tags that we don't want to see. 18 func TestSetInstrumentationAppTags(t *testing.T) { 19 assert := asrt.New(t) 20 21 site := TestSites[0] 22 runTime := util.TimeTrackC(fmt.Sprintf("%s %s", site.Name, t.Name())) 23 24 testcommon.ClearDockerEnv() 25 app := new(ddevapp.DdevApp) 26 27 err := app.Init(site.Dir) 28 assert.NoError(err) 29 t.Cleanup(func() { 30 _ = app.Stop(true, false) 31 }) 32 app.SetInstrumentationAppTags() 33 34 // Make sure that none of the "url" items in app.desc are being reported 35 for k := range nodeps.InstrumentationTags { 36 assert.NotContains(strings.ToLower(k), "url") 37 } 38 39 for _, unwanted := range []string{"approot", "hostname", "hostnames", "name", "router_status_log", "shortroot"} { 40 assert.Empty(nodeps.InstrumentationTags[unwanted]) 41 } 42 43 // Make sure that expected attributes come through 44 for _, wanted := range []string{"database_type", "ProjectID", "performance_mode", "php_version", "router_http_port", "router_https_port", "router_status", "ssh_agent_status", "status", "type", "webimg", "webserver_type"} { 45 assert.NotEmpty(nodeps.InstrumentationTags[wanted], "tag '%s' was not found and it should have been", wanted) 46 } 47 runTime() 48 }