- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 584
feat: allow overriding the session ID #3051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
dc868e2
              72f37e1
              33f15d9
              00c2c93
              57dda3e
              50fa9f3
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,6 +8,8 @@ import ( | |
|  | ||
| "github.com/google/uuid" | ||
| "github.com/shirou/gopsutil/v4/process" | ||
|  | ||
| "github.com/testcontainers/testcontainers-go/internal/config" | ||
| ) | ||
|  | ||
| // sessionID returns a unique session ID for the current test session. Because each Go package | ||
|  | @@ -45,6 +47,11 @@ var processID string | |
| const sessionIDPlaceholder = "testcontainers-go:%d:%d" | ||
|  | ||
| func init() { | ||
| cfg := config.Read() | ||
|          | ||
| if cfg.SessionID != "" { | ||
| sessionID = cfg.SessionID | ||
| } | ||
|  | ||
| processID = uuid.New().String() | ||
|  | ||
| parentPid := os.Getppid() | ||
|  | @@ -57,7 +64,9 @@ func init() { | |
|  | ||
| processes, err := process.Processes() | ||
| if err != nil { | ||
| sessionID = uuid.New().String() | ||
| if sessionID == "" { | ||
| sessionID = uuid.New().String() | ||
| } | ||
|         
                  jcmfernandes marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| projectPath = fallbackCwd | ||
| return | ||
| } | ||
|  | @@ -75,22 +84,26 @@ func init() { | |
|  | ||
| t, err := p.CreateTime() | ||
| if err != nil { | ||
| sessionID = uuid.New().String() | ||
| if sessionID == "" { | ||
| sessionID = uuid.New().String() | ||
| } | ||
| return | ||
| } | ||
|  | ||
| createTime = t | ||
| break | ||
| } | ||
|  | ||
| hasher := sha256.New() | ||
| _, err = fmt.Fprintf(hasher, sessionIDPlaceholder, parentPid, createTime) | ||
| if err != nil { | ||
| sessionID = uuid.New().String() | ||
| return | ||
| } | ||
| if sessionID == "" { | ||
| hasher := sha256.New() | ||
| _, err = fmt.Fprintf(hasher, sessionIDPlaceholder, parentPid, createTime) | ||
| if err != nil { | ||
| sessionID = uuid.New().String() | ||
| return | ||
| } | ||
|  | ||
| sessionID = hex.EncodeToString(hasher.Sum(nil)) | ||
| sessionID = hex.EncodeToString(hasher.Sum(nil)) | ||
| } | ||
| } | ||
|  | ||
| func ProcessID() string { | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.