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]>
149 lines
4.2 KiB
Go
149 lines
4.2 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/hanzoai/cd/gitops-engine/pkg/health"
|
|
log "github.com/sirupsen/logrus"
|
|
"github.com/stretchr/testify/require"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
applicationpkg "github.com/hanzoai/cd/pkg/apiclient/application"
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/test/e2e/fixture"
|
|
utilio "github.com/hanzoai/cd/util/io"
|
|
)
|
|
|
|
// this implements the "then" part of given/when/then
|
|
type Consequences struct {
|
|
context *Context
|
|
actions *Actions
|
|
timeout int
|
|
}
|
|
|
|
func (c *Consequences) Expect(e Expectation) *Consequences {
|
|
c.context.T().Helper()
|
|
|
|
var message string
|
|
var state state
|
|
sleepIntervals := []time.Duration{
|
|
10 * time.Millisecond,
|
|
20 * time.Millisecond,
|
|
50 * time.Millisecond,
|
|
100 * time.Millisecond,
|
|
200 * time.Millisecond,
|
|
300 * time.Millisecond,
|
|
500 * time.Millisecond,
|
|
1 * time.Second,
|
|
}
|
|
sleepIntervalsIdx := -1
|
|
timeout := time.Duration(c.timeout) * time.Second
|
|
for start := time.Now(); time.Since(start) < timeout; time.Sleep(sleepIntervals[sleepIntervalsIdx]) {
|
|
if sleepIntervalsIdx < len(sleepIntervals)-1 {
|
|
sleepIntervalsIdx++
|
|
}
|
|
state, message = e(c)
|
|
switch state {
|
|
case succeeded:
|
|
log.Infof("expectation succeeded: %s", message)
|
|
return c
|
|
case failed:
|
|
c.context.T().Fatalf("failed expectation: %s", message)
|
|
return c
|
|
}
|
|
log.Infof("pending: %s", message)
|
|
}
|
|
c.context.T().Fatal("timeout waiting for: " + message)
|
|
return c
|
|
}
|
|
|
|
// ExpectConsistently will continuously evaluate a condition. Once true, it must be true each time it is evaluated, otherwise the test is failed.
|
|
// The condition will be repeatedly evaluated once it is true,until 'expirationDuration' is met, waiting 'waitDuration' after each success.
|
|
func (c *Consequences) ExpectConsistently(e Expectation, waitDuration time.Duration, expirationDuration time.Duration) *Consequences {
|
|
c.context.T().Helper()
|
|
|
|
c.Expect(e) // ensure the condition is true before expecting consistency
|
|
|
|
expiration := time.Now().Add(expirationDuration)
|
|
for time.Now().Before(expiration) {
|
|
state, message := e(c)
|
|
switch state {
|
|
case succeeded:
|
|
log.Infof("expectation succeeded: %s", message)
|
|
default:
|
|
c.context.T().Fatalf("failed expectation: %s", message)
|
|
return c
|
|
}
|
|
|
|
// On condition success: wait, then retry
|
|
log.Infof("Expectation '%s' passes, repeating to ensure consistency", message)
|
|
time.Sleep(waitDuration)
|
|
}
|
|
|
|
// If the condition never failed before expiring, it is a pass.
|
|
return c
|
|
}
|
|
|
|
func (c *Consequences) And(block func(app *v1alpha1.Application)) *Consequences {
|
|
c.context.T().Helper()
|
|
block(c.app())
|
|
return c
|
|
}
|
|
|
|
func (c *Consequences) AndAction(block func()) *Consequences {
|
|
c.context.T().Helper()
|
|
block()
|
|
return c
|
|
}
|
|
|
|
func (c *Consequences) Given() *Context {
|
|
return c.context
|
|
}
|
|
|
|
func (c *Consequences) When() *Actions {
|
|
time.Sleep(fixture.WhenThenSleepInterval)
|
|
return c.actions
|
|
}
|
|
|
|
func (c *Consequences) app() *v1alpha1.Application {
|
|
c.context.T().Helper()
|
|
app, err := c.get()
|
|
require.NoError(c.context.T(), err)
|
|
return app
|
|
}
|
|
|
|
func (c *Consequences) get() (*v1alpha1.Application, error) {
|
|
return fixture.AppClientset.ArgoprojV1alpha1().Applications(c.context.AppNamespace()).Get(context.Background(), c.context.AppName(), metav1.GetOptions{})
|
|
}
|
|
|
|
func (c *Consequences) resource(kind, name, namespace string) v1alpha1.ResourceStatus {
|
|
c.context.T().Helper()
|
|
closer, client, err := fixture.ArgoCDClientset.NewApplicationClient()
|
|
require.NoError(c.context.T(), err)
|
|
defer utilio.Close(closer)
|
|
app, err := client.Get(context.Background(), &applicationpkg.ApplicationQuery{
|
|
Name: new(c.context.AppName()),
|
|
Projects: []string{c.context.project},
|
|
AppNamespace: new(c.context.appNamespace),
|
|
})
|
|
require.NoError(c.context.T(), err)
|
|
for _, r := range app.Status.Resources {
|
|
if r.Kind == kind && r.Name == name && (namespace == "" || namespace == r.Namespace) {
|
|
return r
|
|
}
|
|
}
|
|
return v1alpha1.ResourceStatus{
|
|
Health: &v1alpha1.HealthStatus{
|
|
Status: health.HealthStatusMissing,
|
|
Message: "not found",
|
|
},
|
|
}
|
|
}
|
|
|
|
func (c *Consequences) AndCLIOutput(block func(output string, err error)) *Consequences {
|
|
c.context.T().Helper()
|
|
block(c.actions.lastOutput, c.actions.lastError)
|
|
return c
|
|
}
|