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]>
128 lines
3.2 KiB
Go
128 lines
3.2 KiB
Go
package manifeststream_test
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"math"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
applicationpkg "github.com/hanzoai/cd/pkg/apiclient/application"
|
|
"github.com/hanzoai/cd/reposerver/apiclient"
|
|
"github.com/hanzoai/cd/test"
|
|
"github.com/hanzoai/cd/util/io/files"
|
|
"github.com/hanzoai/cd/util/manifeststream"
|
|
)
|
|
|
|
type applicationStreamMock struct {
|
|
messages chan *applicationpkg.ApplicationManifestQueryWithFilesWrapper
|
|
done chan bool
|
|
}
|
|
|
|
func (m *applicationStreamMock) Recv() (*applicationpkg.ApplicationManifestQueryWithFilesWrapper, error) {
|
|
select {
|
|
case message := <-m.messages:
|
|
return message, nil
|
|
case <-m.done:
|
|
return nil, io.EOF
|
|
case <-time.After(500 * time.Millisecond):
|
|
return nil, errors.New("timeout receiving message mock")
|
|
}
|
|
}
|
|
|
|
func (m *applicationStreamMock) Send(message *applicationpkg.ApplicationManifestQueryWithFilesWrapper) error {
|
|
m.messages <- message
|
|
return nil
|
|
}
|
|
|
|
func newApplicationStreamMock() *applicationStreamMock {
|
|
messagesCh := make(chan *applicationpkg.ApplicationManifestQueryWithFilesWrapper)
|
|
doneCh := make(chan bool)
|
|
return &applicationStreamMock{
|
|
messages: messagesCh,
|
|
done: doneCh,
|
|
}
|
|
}
|
|
|
|
type repoStreamMock struct {
|
|
messages chan *apiclient.ManifestRequestWithFiles
|
|
done chan bool
|
|
}
|
|
|
|
func (m *repoStreamMock) Recv() (*apiclient.ManifestRequestWithFiles, error) {
|
|
select {
|
|
case message := <-m.messages:
|
|
return message, nil
|
|
case <-m.done:
|
|
return nil, io.EOF
|
|
case <-time.After(500 * time.Millisecond):
|
|
return nil, errors.New("timeout receiving message mock")
|
|
}
|
|
}
|
|
|
|
func (m *repoStreamMock) Send(message *apiclient.ManifestRequestWithFiles) error {
|
|
m.messages <- message
|
|
return nil
|
|
}
|
|
|
|
func newRepoStreamMock() *repoStreamMock {
|
|
messagesCh := make(chan *apiclient.ManifestRequestWithFiles)
|
|
doneCh := make(chan bool)
|
|
return &repoStreamMock{
|
|
messages: messagesCh,
|
|
done: doneCh,
|
|
}
|
|
}
|
|
|
|
func TestManifestStream(t *testing.T) {
|
|
t.Parallel()
|
|
appStreamMock := newApplicationStreamMock()
|
|
repoStreamMock := newRepoStreamMock()
|
|
workdir, err := files.CreateTempDir("")
|
|
require.NoError(t, err)
|
|
|
|
appDir := filepath.Join(getTestDataDir(t), "app")
|
|
|
|
go func() {
|
|
err := manifeststream.SendApplicationManifestQueryWithFiles(t.Context(), appStreamMock, "test", "test", appDir, nil)
|
|
assert.NoError(t, err)
|
|
appStreamMock.done <- true
|
|
}()
|
|
|
|
query, err := manifeststream.ReceiveApplicationManifestQueryWithFiles(appStreamMock)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, query)
|
|
|
|
req := &apiclient.ManifestRequest{}
|
|
|
|
go func() {
|
|
err = manifeststream.SendRepoStream(repoStreamMock, appStreamMock, req, *query.Checksum)
|
|
assert.NoError(t, err)
|
|
repoStreamMock.done <- true
|
|
}()
|
|
|
|
req2, meta, err := manifeststream.ReceiveManifestFileStream(t.Context(), repoStreamMock, workdir, math.MaxInt64, math.MaxInt64)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, req2)
|
|
require.NotNil(t, meta)
|
|
|
|
files, err := os.ReadDir(workdir)
|
|
require.NoError(t, err)
|
|
require.Len(t, files, 1)
|
|
names := []string{}
|
|
for _, f := range files {
|
|
names = append(names, f.Name())
|
|
}
|
|
assert.Contains(t, names, "DUMMY.md")
|
|
}
|
|
|
|
func getTestDataDir(t *testing.T) string {
|
|
t.Helper()
|
|
return filepath.Join(test.GetTestDir(t), "testdata")
|
|
}
|