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]>
88 lines
2.6 KiB
Go
88 lines
2.6 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/hanzoai/cd/cmpserver/plugin"
|
|
"github.com/hanzoai/cd/test/e2e/fixture"
|
|
"github.com/hanzoai/cd/util/errors"
|
|
)
|
|
|
|
// RunningCMPServer starts a CMP server with the given config directory and waits for it to be ready.
|
|
// It blocks until the CMP socket is created or times out after 10 seconds.
|
|
func (c *Context) RunningCMPServer(configFile string) *Context {
|
|
c.T().Helper()
|
|
startCMPServer(c.T(), configFile)
|
|
c.T().Setenv("CD_BINARY_NAME", "cd")
|
|
return c
|
|
}
|
|
|
|
// startCMPServer starts the CMP server and waits for its socket to be ready.
|
|
// It blocks until the socket file is created or times out after 10 seconds.
|
|
func startCMPServer(t *testing.T, configDir string) {
|
|
t.Helper()
|
|
pluginSockFilePath := path.Join(fixture.TmpDir(), fixture.PluginSockFilePath)
|
|
t.Setenv("CD_BINARY_NAME", "cd-cmp-server")
|
|
// CD_PLUGINSOCKFILEPATH should be set as the same value as repo server env var
|
|
t.Setenv("CD_PLUGINSOCKFILEPATH", pluginSockFilePath)
|
|
if _, err := os.Stat(pluginSockFilePath); os.IsNotExist(err) {
|
|
err := os.Mkdir(pluginSockFilePath, 0o700)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
// Read plugin config to get expected socket path
|
|
cfg, err := plugin.ReadPluginConfig(configDir)
|
|
require.NoError(t, err, "failed to read plugin config from %s", configDir)
|
|
expectedSocket := cfg.Address()
|
|
|
|
// Remove stale socket if it exists from a previous test run
|
|
if err := os.Remove(expectedSocket); err != nil && !os.IsNotExist(err) {
|
|
require.NoError(t, err, "failed to remove stale socket")
|
|
}
|
|
|
|
// Start CMP server in goroutine (non-blocking)
|
|
go func() {
|
|
errors.NewHandler(t).FailOnErr(fixture.RunWithStdin("", "", "../../dist/cd", "--config-dir-path", configDir))
|
|
}()
|
|
|
|
// Wait for socket to be created
|
|
waitForSocket(t, expectedSocket, 10*time.Second)
|
|
}
|
|
|
|
// waitForSocket polls for a socket file to exist with exponential backoff
|
|
func waitForSocket(t *testing.T, socketPath string, timeout time.Duration) {
|
|
t.Helper()
|
|
deadline := time.Now().Add(timeout)
|
|
|
|
sleepIntervals := []time.Duration{
|
|
10 * time.Millisecond,
|
|
20 * time.Millisecond,
|
|
50 * time.Millisecond,
|
|
100 * time.Millisecond,
|
|
200 * time.Millisecond,
|
|
500 * time.Millisecond,
|
|
}
|
|
sleepIdx := 0
|
|
|
|
for time.Now().Before(deadline) {
|
|
if info, err := os.Stat(socketPath); err == nil {
|
|
if info.Mode()&os.ModeSocket != 0 {
|
|
return // Socket exists and is a socket!
|
|
}
|
|
}
|
|
if sleepIdx < len(sleepIntervals) {
|
|
time.Sleep(sleepIntervals[sleepIdx])
|
|
sleepIdx++
|
|
} else {
|
|
time.Sleep(500 * time.Millisecond)
|
|
}
|
|
}
|
|
|
|
t.Fatalf("CMP socket %s did not appear within %v", socketPath, timeout)
|
|
}
|