Skip to content

Commit

Permalink
feat: generate deterministic namespaces for test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dervoeti committed Nov 5, 2024
1 parent 5ce3d62 commit 8eca2e1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/test/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package test
import (
"bytes"
"context"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"math/rand"
Expand Down Expand Up @@ -79,11 +81,22 @@ func (h *Harness) LoadTests(dir string) ([]*Case, error) {
continue
}

// Calculate the namespace to use for the test case
// Get the sha256 hash the test case name
hasher := sha256.New()
hasher.Write([]byte(file.Name()))
hash := hex.EncodeToString(hasher.Sum(nil))

truncatedFileName := file.Name()
if len(truncatedFileName) > 32 {
truncatedFileName = truncatedFileName[:32]
}

tests = append(tests, &Case{
Timeout: timeout,
Steps: []*Step{},
Name: file.Name(),
PreferredNamespace: h.TestSuite.Namespace,
PreferredNamespace: fmt.Sprintf("kuttl-%s-%s", hash[:10], truncatedFileName),
Dir: filepath.Join(dir, file.Name()),
SkipDelete: h.TestSuite.SkipDelete,
Suppress: h.TestSuite.Suppress,
Expand Down

0 comments on commit 8eca2e1

Please sign in to comment.