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]>
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package appstate
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
. "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
cacheutil "github.com/hanzoai/cd/util/cache"
|
|
)
|
|
|
|
type fixtures struct {
|
|
*Cache
|
|
}
|
|
|
|
func newFixtures() *fixtures {
|
|
return &fixtures{NewCache(
|
|
cacheutil.NewCache(cacheutil.NewInMemoryCache(1*time.Hour)),
|
|
1*time.Minute,
|
|
)}
|
|
}
|
|
|
|
func TestCache_GetAppManagedResources(t *testing.T) {
|
|
t.Parallel()
|
|
cache := newFixtures().Cache
|
|
// cache miss
|
|
value := &[]*ResourceDiff{}
|
|
err := cache.GetAppManagedResources("my-appname", value)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// populate cache
|
|
err = cache.SetAppManagedResources("my-appname", []*ResourceDiff{{Name: "my-name"}})
|
|
require.NoError(t, err)
|
|
// cache miss
|
|
err = cache.GetAppManagedResources("other-appname", value)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// cache hit
|
|
err = cache.GetAppManagedResources("my-appname", value)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, &[]*ResourceDiff{{Name: "my-name"}}, value)
|
|
}
|
|
|
|
func TestCache_GetAppResourcesTree(t *testing.T) {
|
|
t.Parallel()
|
|
cache := newFixtures().Cache
|
|
// cache miss
|
|
value := &ApplicationTree{}
|
|
err := cache.GetAppResourcesTree("my-appname", value)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// populate cache
|
|
err = cache.SetAppResourcesTree("my-appname", &ApplicationTree{Nodes: []ResourceNode{{}}})
|
|
require.NoError(t, err)
|
|
// cache miss
|
|
err = cache.GetAppResourcesTree("other-appname", value)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// cache hit
|
|
err = cache.GetAppResourcesTree("my-appname", value)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, &ApplicationTree{Nodes: []ResourceNode{{}}}, value)
|
|
}
|
|
|
|
func TestCache_GetClusterInfo(t *testing.T) {
|
|
t.Parallel()
|
|
cache := newFixtures().Cache
|
|
// cache miss
|
|
res := &ClusterInfo{}
|
|
err := cache.GetClusterInfo("http://minikube", res)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// populate cache
|
|
err = cache.SetClusterInfo("http://kind-cluster", &ClusterInfo{ServerVersion: "0.24.0"})
|
|
require.NoError(t, err)
|
|
// cache miss
|
|
err = cache.GetClusterInfo("http://kind-clusterss", res)
|
|
assert.Equal(t, ErrCacheMiss, err)
|
|
// cache hit
|
|
err = cache.GetClusterInfo("http://kind-cluster", res)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, &ClusterInfo{ServerVersion: "0.24.0"}, res)
|
|
}
|
|
|
|
func TestAddCacheFlagsToCmd(t *testing.T) {
|
|
t.Parallel()
|
|
cache, err := AddCacheFlagsToCmd(&cobra.Command{})()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, 1*time.Hour, cache.appStateCacheExpiration)
|
|
}
|