github.com/drud/ddev@v1.21.5-alpha1.0.20230226034409-94fcc4b94453/pkg/ddevapp/instrumentation_test.go (about)

     1  package ddevapp_test
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/drud/ddev/pkg/ddevapp"
     6  	"github.com/drud/ddev/pkg/nodeps"
     7  	"github.com/drud/ddev/pkg/testcommon"
     8  	"github.com/drud/ddev/pkg/util"
     9  	asrt "github.com/stretchr/testify/assert"
    10  	"strings"
    11  	"testing"
    12  	"time"
    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.TimeTrack(time.Now(), 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", "nfs_mount_enabled", "ProjectID", "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  }