mirror of
https://github.com/juanfont/headscale.git
synced 2025-08-11 15:27:37 +00:00
integration: replace time.Sleep with assert.EventuallyWithT (#2680)
This commit is contained in:
@@ -33,26 +33,27 @@ func DockerAddIntegrationLabels(opts *dockertest.RunOptions, testType string) {
|
||||
}
|
||||
|
||||
// GenerateRunID creates a unique run identifier with timestamp and random hash.
|
||||
// Format: YYYYMMDD-HHMMSS-HASH (e.g., 20250619-143052-a1b2c3)
|
||||
// Format: YYYYMMDD-HHMMSS-HASH (e.g., 20250619-143052-a1b2c3).
|
||||
func GenerateRunID() string {
|
||||
now := time.Now()
|
||||
timestamp := now.Format("20060102-150405")
|
||||
|
||||
|
||||
// Add a short random hash to ensure uniqueness
|
||||
randomHash := util.MustGenerateRandomStringDNSSafe(6)
|
||||
|
||||
return fmt.Sprintf("%s-%s", timestamp, randomHash)
|
||||
}
|
||||
|
||||
// ExtractRunIDFromContainerName extracts the run ID from container name.
|
||||
// Expects format: "prefix-YYYYMMDD-HHMMSS-HASH"
|
||||
// Expects format: "prefix-YYYYMMDD-HHMMSS-HASH".
|
||||
func ExtractRunIDFromContainerName(containerName string) string {
|
||||
parts := strings.Split(containerName, "-")
|
||||
if len(parts) >= 3 {
|
||||
// Return the last three parts as the run ID (YYYYMMDD-HHMMSS-HASH)
|
||||
return strings.Join(parts[len(parts)-3:], "-")
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("unexpected container name format: %s", containerName))
|
||||
|
||||
panic("unexpected container name format: " + containerName)
|
||||
}
|
||||
|
||||
// IsRunningInContainer checks if the current process is running inside a Docker container.
|
||||
@@ -62,4 +63,4 @@ func IsRunningInContainer() bool {
|
||||
// This could be improved with more robust detection if needed
|
||||
_, err := os.Stat("/.dockerenv")
|
||||
return err == nil
|
||||
}
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ func ExecuteCommandTimeout(timeout time.Duration) ExecuteCommandOption {
|
||||
})
|
||||
}
|
||||
|
||||
// buffer is a goroutine safe bytes.buffer
|
||||
// buffer is a goroutine safe bytes.buffer.
|
||||
type buffer struct {
|
||||
store bytes.Buffer
|
||||
mutex sync.Mutex
|
||||
@@ -58,8 +58,8 @@ func ExecuteCommand(
|
||||
env []string,
|
||||
options ...ExecuteCommandOption,
|
||||
) (string, string, error) {
|
||||
var stdout = buffer{}
|
||||
var stderr = buffer{}
|
||||
stdout := buffer{}
|
||||
stderr := buffer{}
|
||||
|
||||
execConfig := ExecuteCommandConfig{
|
||||
timeout: dockerExecuteTimeout,
|
||||
|
Reference in New Issue
Block a user