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
3.1 KiB
Go
89 lines
3.1 KiB
Go
package discovery
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDiscover(t *testing.T) {
|
|
t.Parallel()
|
|
apps, err := Discover(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, map[string]string{
|
|
"foo": "Kustomize",
|
|
"baz": "Helm",
|
|
}, apps)
|
|
}
|
|
|
|
func TestAppType(t *testing.T) {
|
|
t.Parallel()
|
|
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", map[string]bool{}, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Kustomize", appType)
|
|
|
|
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", map[string]bool{}, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Helm", appType)
|
|
|
|
appType, err = AppType(t.Context(), "./testdata", "./testdata", map[string]bool{}, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Directory", appType)
|
|
}
|
|
|
|
func TestAppType_Disabled(t *testing.T) {
|
|
t.Parallel()
|
|
enableManifestGeneration := map[string]bool{
|
|
string(v1alpha1.ApplicationSourceTypeKustomize): false,
|
|
string(v1alpha1.ApplicationSourceTypeHelm): false,
|
|
}
|
|
appType, err := AppType(t.Context(), "./testdata/foo", "./testdata", enableManifestGeneration, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Directory", appType)
|
|
|
|
appType, err = AppType(t.Context(), "./testdata/baz", "./testdata", enableManifestGeneration, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Directory", appType)
|
|
|
|
appType, err = AppType(t.Context(), "./testdata", "./testdata", enableManifestGeneration, []string{}, []string{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "Directory", appType)
|
|
}
|
|
|
|
func Test_cmpSupports_invalidSocketPath_outsideDir(t *testing.T) {
|
|
t.Parallel()
|
|
// Use a temp dir as the base plugin socket dir and provide a fileName that
|
|
// resolves outside it to trigger the Inbound check.
|
|
pluginSockFilePath := t.TempDir()
|
|
// fileName with a path traversal that causes the address to be outside the plugin socket dir
|
|
fileName := "../outside.sock"
|
|
|
|
conn, client, found, err := cmpSupports(t.Context(), pluginSockFilePath, "appPath", "repoPath", fileName, nil, nil, true)
|
|
require.False(t, found)
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "outside plugin socket dir")
|
|
assert.Nil(t, conn)
|
|
assert.Nil(t, client)
|
|
}
|
|
|
|
func Test_cmpSupports_dialFailure_returnsError(t *testing.T) {
|
|
t.Parallel()
|
|
// Use a temp dir as the base plugin socket dir and provide a socket filename
|
|
// that does not have a listening server; dialing should fail, and the error
|
|
// returned should reflect a dialing problem.
|
|
pluginSockFilePath := t.TempDir()
|
|
fileName := "nonexistent.sock"
|
|
|
|
conn, client, found, err := cmpSupports(t.Context(), pluginSockFilePath, "appPath", "repoPath", fileName, nil, nil, true)
|
|
require.False(t, found)
|
|
require.Error(t, err)
|
|
// We expect the error to at least indicate dialing failure; exact wording may vary,
|
|
// check for the dialing error prefix used in cmpSupports.
|
|
assert.Contains(t, err.Error(), "error dialing to cmp-server")
|
|
assert.Nil(t, conn)
|
|
assert.Nil(t, client)
|
|
}
|