Files
zeekayandHanzo Dev 1ab6e799c1 cd: the module is github.com/hanzoai/cd, where it is actually hosted
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]>
2026-07-28 21:16:24 -07:00

150 lines
4.4 KiB
Go

package application
import (
"errors"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
"github.com/hanzoai/cd/pkg/client/clientset/versioned/fake"
clientset "github.com/hanzoai/cd/pkg/client/clientset/versioned/typed/application/v1alpha1"
"github.com/hanzoai/cd/pkg/client/clientset/versioned/typed/application/v1alpha1/mocks"
)
func Test_deepCopyAppProjectClient_Get(t *testing.T) {
type fields struct {
AppProjectInterface clientset.AppProjectInterface
}
type args struct {
name string
}
tests := []struct {
name string
fields fields
args args
want *v1alpha1.AppProject
wantErr assert.ErrorAssertionFunc
}{
{name: "Get an app project", fields: fields{AppProjectInterface: setupAppProjects("appproject")}, args: args{
name: "appproject",
}, want: &v1alpha1.AppProject{
ObjectMeta: metav1.ObjectMeta{Name: "appproject", Namespace: "deep-copy-ns"},
}, wantErr: assert.NoError},
{
name: "Error getting an app project",
fields: fields{
AppProjectInterface: func() clientset.AppProjectInterface {
appProject := &mocks.AppProjectInterface{}
appProject.EXPECT().Get(t.Context(), "appproject2", metav1.GetOptions{}).Return(nil, errors.New("error"))
return appProject
}(),
},
args: args{
name: "appproject2",
},
want: nil,
wantErr: assert.Error,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &deepCopyAppProjectClient{
AppProjectInterface: tt.fields.AppProjectInterface,
}
got, err := d.Get(t.Context(), tt.args.name, metav1.GetOptions{})
if !tt.wantErr(t, err, fmt.Sprintf("Get(%v)", tt.args.name)) {
return
}
assert.Equalf(t, tt.want, got, "Get(%v)", tt.args.name)
if tt.want != nil {
assert.NotSamef(t, tt.want, got, "%v and %v are the same ptr", tt.want, got)
}
})
}
}
func Test_deepCopyAppProjectClient_List(t *testing.T) {
type fields struct {
AppProjectInterface clientset.AppProjectInterface
}
tests := []struct {
name string
fields fields
want []v1alpha1.AppProject
wantErr assert.ErrorAssertionFunc
}{
{
name: "List app projects", fields: fields{AppProjectInterface: setupAppProjects("proj1", "proj2")},
want: createAppProject("proj1", "proj2"), wantErr: assert.NoError,
},
{name: "Error listing app project", fields: fields{
AppProjectInterface: func() clientset.AppProjectInterface {
appProject := &mocks.AppProjectInterface{}
appProject.EXPECT().List(t.Context(), metav1.ListOptions{}).Return(nil, errors.New("error"))
return appProject
}(),
}, want: nil, wantErr: assert.Error},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &deepCopyAppProjectClient{
AppProjectInterface: tt.fields.AppProjectInterface,
}
got, err := d.List(t.Context(), metav1.ListOptions{})
if !tt.wantErr(t, err, "List") {
return
}
if tt.want != nil {
assert.Equalf(t, tt.want, got.Items, "List")
for i := range tt.want {
assert.NotSamef(t, &tt.want[i], &got.Items[i], "%v and %v are the same ptr", tt.want, got)
}
}
})
}
}
func createAppProject(projects ...string) []v1alpha1.AppProject {
appProjects := make([]v1alpha1.AppProject, len(projects))
for i, p := range projects {
appProjects[i] = v1alpha1.AppProject{ObjectMeta: metav1.ObjectMeta{Name: p, Namespace: "deep-copy-ns"}}
}
return appProjects
}
func setupAppProjects(projects ...string) clientset.AppProjectInterface {
appProjects := createAppProject(projects...)
ro := make([]runtime.Object, len(appProjects))
for i := range appProjects {
ro[i] = &appProjects[i]
}
return fake.NewSimpleClientset(ro...).ArgoprojV1alpha1().AppProjects("deep-copy-ns")
}
func Test_deepCopyArgoprojV1alpha1Client_RESTClient(t *testing.T) {
fclientset := fake.NewSimpleClientset().ArgoprojV1alpha1()
type fields struct {
ArgoprojV1alpha1Interface clientset.ArgoprojV1alpha1Interface
}
tests := []struct {
name string
fields fields
want rest.Interface
}{
{name: "RestClientGetter", fields: fields{ArgoprojV1alpha1Interface: fclientset}, want: fclientset.RESTClient()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &deepCopyArgoprojV1alpha1Client{
ArgoprojV1alpha1Interface: tt.fields.ArgoprojV1alpha1Interface,
}
assert.Equalf(t, tt.want, d.RESTClient(), "RESTClient()")
})
}
}