mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
120 lines
3.4 KiB
Go
120 lines
3.4 KiB
Go
package fixture
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/cd/util/rand"
|
|
|
|
"github.com/hanzoai/cd/util/errors"
|
|
)
|
|
|
|
// TestContext defines the interface for test-specific state that enables parallel test execution.
|
|
// All fixture Context types should implement this interface by embedding TestState.
|
|
type TestContext interface {
|
|
// SetName sets the DNS-friendly name for this context
|
|
SetName(name string)
|
|
// GetName returns the DNS-friendly name for this context
|
|
GetName() string
|
|
// DeploymentNamespace returns the namespace where test resources are deployed
|
|
DeploymentNamespace() string
|
|
// ID returns the unique identifier for this test run
|
|
ID() string
|
|
// ShortID returns the short unique identifier suffix for this test run
|
|
ShortID() string
|
|
// Token returns the authentication token for API calls
|
|
Token() string
|
|
// SetToken sets the authentication token
|
|
SetToken(token string)
|
|
// T returns the testing.T instance for this test
|
|
T() *testing.T
|
|
}
|
|
|
|
// TestState holds test-specific variables that were previously global.
|
|
// Embed this in Context structs to enable parallel test execution.
|
|
type TestState struct {
|
|
t *testing.T
|
|
id string
|
|
shortId string
|
|
name string
|
|
deploymentNamespace string
|
|
token string
|
|
}
|
|
|
|
// NewTestState creates a new TestState with unique identifiers for this test run.
|
|
// This generates fresh id, name, and deploymentNamespace values.
|
|
func NewTestState(t *testing.T) *TestState {
|
|
t.Helper()
|
|
randString, err := rand.String(5)
|
|
errors.CheckError(err)
|
|
shortId := strings.ToLower(randString)
|
|
|
|
return &TestState{
|
|
t: t,
|
|
token: token, // Initialize with current global token
|
|
id: fmt.Sprintf("%s-%s", t.Name(), shortId),
|
|
shortId: shortId,
|
|
name: DnsFriendly(t.Name(), "-"+shortId),
|
|
deploymentNamespace: DnsFriendly("cd-e2e-"+t.Name(), "-"+shortId),
|
|
}
|
|
}
|
|
|
|
// NewTestStateFromContext creates a TestState from an existing TestContext.
|
|
// This allows GivenWithSameState functions to work across different Context types.
|
|
func NewTestStateFromContext(ctx TestContext) *TestState {
|
|
return &TestState{
|
|
t: ctx.T(),
|
|
id: ctx.ID(),
|
|
shortId: ctx.ShortID(),
|
|
name: ctx.GetName(),
|
|
deploymentNamespace: ctx.DeploymentNamespace(),
|
|
token: ctx.Token(),
|
|
}
|
|
}
|
|
|
|
// Name sets the DNS-friendly name for this context
|
|
func (s *TestState) SetName(name string) {
|
|
if name == "" {
|
|
s.name = ""
|
|
return
|
|
}
|
|
suffix := "-" + s.shortId
|
|
s.name = DnsFriendly(strings.TrimSuffix(name, suffix), suffix)
|
|
}
|
|
|
|
// GetName returns the DNS-friendly name for this context
|
|
func (s *TestState) GetName() string {
|
|
return s.name
|
|
}
|
|
|
|
// DeploymentNamespace returns the namespace where test resources are deployed
|
|
func (s *TestState) DeploymentNamespace() string {
|
|
return s.deploymentNamespace
|
|
}
|
|
|
|
// ID returns the unique identifier for this test run
|
|
func (s *TestState) ID() string {
|
|
return s.id
|
|
}
|
|
|
|
// ShortID returns the short unique identifier suffix for this test run
|
|
func (s *TestState) ShortID() string {
|
|
return s.shortId
|
|
}
|
|
|
|
// Token returns the authentication token for API calls
|
|
func (s *TestState) Token() string {
|
|
return s.token
|
|
}
|
|
|
|
// SetToken sets the authentication token
|
|
func (s *TestState) SetToken(token string) {
|
|
s.token = token
|
|
}
|
|
|
|
// T returns the testing.T instance for this test
|
|
func (s *TestState) T() *testing.T {
|
|
return s.t
|
|
}
|