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

135 lines
3.8 KiB
Go

package settings
import (
"context"
"testing"
"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
"github.com/hanzoai/cd/common"
"github.com/hanzoai/cd/util/settings"
)
const (
testNamespace = "default"
resourceOverrides = `{
"jsonPointers": [
""
],
"jqPathExpressions": [
""
],
"managedFieldsManagers": [
""
]
}`
)
func fixtures(ctx context.Context, data map[string]string) (*fake.Clientset, *settings.SettingsManager) {
kubeClient := fake.NewClientset(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: common.ArgoCDConfigMapName,
Namespace: testNamespace,
Labels: map[string]string{
"app.kubernetes.io/part-of": "cd",
},
},
Data: data,
}, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "cd-secret",
Namespace: testNamespace,
},
Data: map[string][]byte{
"admin.password": []byte("test"),
"server.secretkey": []byte("test"),
},
})
settingsManager := settings.NewSettingsManager(ctx, kubeClient, testNamespace)
return kubeClient, settingsManager
}
func TestSettingsServer(t *testing.T) {
t.Parallel()
newServer := func(data map[string]string) *Server {
_, settingsMgr := fixtures(t.Context(), data)
return NewServer(settingsMgr, nil, nil, false, false, false, false)
}
t.Run("TestGetInstallationID", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{
"installationID": "1234567890",
})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Equal(t, "1234567890", resp.InstallationID)
})
t.Run("TestGetInstallationIDNotSet", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Empty(t, resp.InstallationID)
})
t.Run("TestGetTrackingMethod", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{
"application.resourceTrackingMethod": "annotation+label",
})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Equal(t, "annotation+label", resp.TrackingMethod)
})
t.Run("TestGetAppLabelKey", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{
"application.instanceLabelKey": "instance",
})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Equal(t, "instance", resp.AppLabelKey)
})
t.Run("TestGetLoginButtonTextNotLoggedIn", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{
"ui.loginButtonText": "Sign in with SSO",
})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Equal(t, "Sign in with SSO", resp.UiLoginButtonText)
})
t.Run("TestGetResourceOverridesNotLoggedIn", func(t *testing.T) {
t.Parallel()
settingsServer := newServer(map[string]string{
"resource.customizations.ignoreResourceUpdates.all": resourceOverrides,
})
resp, err := settingsServer.Get(t.Context(), nil)
require.NoError(t, err)
assert.Nil(t, resp.ResourceOverrides)
})
t.Run("TestGetResourceOverridesLoggedIn", func(t *testing.T) {
t.Parallel()
//nolint:staticcheck // it's ok to use built-in type string as key for value for testing purposes
loggedInContext := context.WithValue(t.Context(), "claims", &jwt.MapClaims{"iss": "qux", "sub": "foo", "email": "bar", "groups": []string{"baz"}})
settingsServer := newServer(map[string]string{
"resource.customizations.ignoreResourceUpdates.all": resourceOverrides,
})
resp, err := settingsServer.Get(loggedInContext, nil)
require.NoError(t, err)
assert.NotNil(t, resp.ResourceOverrides)
assert.NotEmpty(t, resp.ResourceOverrides["*/*"])
})
}