Skip to content

Commit

Permalink
internal/civisibility: simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Oct 3, 2024
1 parent 15620a7 commit d332b0d
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions internal/civisibility/integrations/manual_api_ddtestsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"time"

Expand All @@ -37,29 +35,11 @@ type tslvTestSession struct {

// CreateTestSession initializes a new test session. It automatically determines the command and working directory.
func CreateTestSession() DdTestSession {
var cmd string
var ok bool
tags := utils.GetCITags()
if cmd, ok = tags[constants.TestCommand]; !ok || cmd == "" {
if len(os.Args) == 1 {
cmd = filepath.Base(os.Args[0])
} else {
cmd = fmt.Sprintf("%s %s ", filepath.Base(os.Args[0]), strings.Join(os.Args[1:], " "))
}

// Filter out some parameters to make the command more stable.
cmd = regexp.MustCompile(`(?si)-test.gocoverdir=(.*)\s`).ReplaceAllString(cmd, "")
cmd = regexp.MustCompile(`(?si)-test.v=(.*)\s`).ReplaceAllString(cmd, "")
cmd = regexp.MustCompile(`(?si)-test.testlogfile=(.*)\s`).ReplaceAllString(cmd, "")
cmd = strings.TrimSpace(cmd)
tags[constants.TestCommand] = cmd
}

wd, err := os.Getwd()
if err == nil {
wd = utils.GetRelativePathFromCITagsSourceRoot(wd)
}
return CreateTestSessionWith(cmd, wd, "", time.Now())
return CreateTestSessionWith(utils.GetCITags()[constants.TestCommand], wd, "", time.Now())
}

// CreateTestSessionWith initializes a new test session with specified command, working directory, framework, and start time.
Expand Down

0 comments on commit d332b0d

Please sign in to comment.