github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/integration_test/itest/logdir.go (about)

     1  package itest
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  	"regexp"
     9  
    10  	"github.com/datawire/dlib/dlog"
    11  	"github.com/telepresenceio/telepresence/v2/pkg/filelocation"
    12  )
    13  
    14  func CleanLogDir(ctx context.Context, require *Requirements, nsRx, mgrNamespace, svcNameRx string) {
    15  	logDir := filelocation.AppUserLogDir(ctx)
    16  	files, err := os.ReadDir(logDir)
    17  	require.NoError(err)
    18  	match := regexp.MustCompile(
    19  		fmt.Sprintf(`^(?:traffic-manager-[0-9a-z-]+\.%s|%s-[0-9a-z-]+\.%s)\.(?:log|yaml)$`,
    20  			mgrNamespace, svcNameRx, nsRx))
    21  
    22  	for _, file := range files {
    23  		if match.MatchString(file.Name()) {
    24  			dlog.Infof(ctx, "Deleting log-file %s", file.Name())
    25  			require.NoError(os.Remove(filepath.Join(logDir, file.Name())))
    26  		}
    27  	}
    28  }