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]>
126 lines
3.2 KiB
Go
126 lines
3.2 KiB
Go
package project
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/test/e2e/fixture"
|
|
)
|
|
|
|
// this implements the "when" part of given/when/then
|
|
//
|
|
// none of the func implement error checks, and that is complete intended, you should check for errors
|
|
// using the Then()
|
|
type Actions struct {
|
|
context *Context
|
|
lastError error
|
|
ignoreErrors bool
|
|
}
|
|
|
|
func (a *Actions) IgnoreErrors() *Actions {
|
|
a.ignoreErrors = true
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) DoNotIgnoreErrors() *Actions {
|
|
a.ignoreErrors = false
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) Create(args ...string) *Actions {
|
|
args = a.prepareCreateArgs(args)
|
|
|
|
// are you adding new context values? if you only use them for this func, then use args instead
|
|
a.runCli(args...)
|
|
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) AddDestination(cluster string, namespace string) *Actions {
|
|
a.runCli("proj", "add-destination", a.context.GetName(), cluster, namespace)
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) AddDestinationServiceAccount(cluster string, namespace string) *Actions {
|
|
a.runCli("proj", "add-destination-service-account", a.context.GetName(), cluster, namespace)
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) AddSource(repo string) *Actions {
|
|
a.runCli("proj", "add-source", a.context.GetName(), repo)
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) UpdateProject(updater func(project *v1alpha1.AppProject)) *Actions {
|
|
proj, err := fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Get(context.TODO(), a.context.GetName(), metav1.GetOptions{})
|
|
require.NoError(a.context.T(), err)
|
|
updater(proj)
|
|
_, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.TestNamespace()).Update(context.TODO(), proj, metav1.UpdateOptions{})
|
|
require.NoError(a.context.T(), err)
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) SetName(name string) *Actions {
|
|
a.context.SetName(name)
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) prepareCreateArgs(args []string) []string {
|
|
a.context.T().Helper()
|
|
args = append([]string{
|
|
"proj", "create", a.context.GetName(),
|
|
}, args...)
|
|
|
|
if a.context.destination != "" {
|
|
args = append(args, "--dest", a.context.destination)
|
|
}
|
|
|
|
if len(a.context.sourceNamespaces) > 0 {
|
|
args = append(args, "--source-namespaces", strings.Join(a.context.sourceNamespaces, ","))
|
|
}
|
|
|
|
if len(a.context.repos) > 0 {
|
|
for _, repo := range a.context.repos {
|
|
args = append(args, "--src", repo)
|
|
}
|
|
}
|
|
|
|
if len(a.context.destinationServiceAccounts) != 0 {
|
|
for _, destinationServiceAccount := range a.context.destinationServiceAccounts {
|
|
args = append(args, "--dest-service-accounts", destinationServiceAccount)
|
|
}
|
|
}
|
|
return args
|
|
}
|
|
|
|
func (a *Actions) Delete() *Actions {
|
|
a.context.T().Helper()
|
|
a.runCli("proj", "delete", a.context.GetName())
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) And(block func()) *Actions {
|
|
a.context.T().Helper()
|
|
block()
|
|
return a
|
|
}
|
|
|
|
func (a *Actions) Then() *Consequences {
|
|
a.context.T().Helper()
|
|
time.Sleep(fixture.WhenThenSleepInterval)
|
|
return &Consequences{a.context, a}
|
|
}
|
|
|
|
func (a *Actions) runCli(args ...string) {
|
|
a.context.T().Helper()
|
|
_, a.lastError = fixture.RunCli(args...)
|
|
if !a.ignoreErrors {
|
|
require.NoError(a.context.T(), a.lastError)
|
|
}
|
|
}
|