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]>
148 lines
3.2 KiB
Go
148 lines
3.2 KiB
Go
package files_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/hanzoai/cd/util/io/files"
|
|
)
|
|
|
|
func TestRelativePath(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
type testcase struct {
|
|
name string
|
|
fullpath string
|
|
basepath string
|
|
expected string
|
|
expectedErr error
|
|
}
|
|
cases := []testcase{
|
|
{
|
|
name: "will return relative path from file path",
|
|
fullpath: "/home/test/app/readme.md",
|
|
basepath: "/home/test",
|
|
expected: "app/readme.md",
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
name: "will return relative path from dir path",
|
|
fullpath: "/home/test/app/",
|
|
basepath: "/home/test",
|
|
expected: "app",
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
name: "will return . if fullpath and basepath are the same",
|
|
fullpath: "/home/test/app/readme.md",
|
|
basepath: "/home/test/app/readme.md",
|
|
expected: ".",
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
name: "will return error if basepath does not match",
|
|
fullpath: "/home/test/app/readme.md",
|
|
basepath: "/somewhere/else",
|
|
expected: "",
|
|
expectedErr: files.ErrRelativeOutOfBound,
|
|
},
|
|
{
|
|
name: "will return relative path from dir path",
|
|
fullpath: "/home/test//app/",
|
|
basepath: "/home/test",
|
|
expected: "app",
|
|
expectedErr: nil,
|
|
},
|
|
{
|
|
name: "will handle relative fullpath",
|
|
fullpath: "./app/",
|
|
basepath: "/home/test",
|
|
expected: "",
|
|
expectedErr: files.ErrRelativeOutOfBound,
|
|
},
|
|
{
|
|
name: "will handle relative basepath",
|
|
fullpath: "/home/test/app/",
|
|
basepath: "./test",
|
|
expected: "",
|
|
expectedErr: files.ErrRelativeOutOfBound,
|
|
},
|
|
{
|
|
name: "will handle relative paths",
|
|
fullpath: "./test/app",
|
|
basepath: "./test/app",
|
|
expected: ".",
|
|
expectedErr: nil,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
// given
|
|
t.Parallel()
|
|
|
|
// when
|
|
relativePath, err := files.RelativePath(c.fullpath, c.basepath)
|
|
|
|
// then
|
|
assert.Equal(t, c.expectedErr, err)
|
|
assert.Equal(t, c.expected, relativePath)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInbound(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
type testcase struct {
|
|
name string
|
|
candidate string
|
|
basedir string
|
|
expected bool
|
|
}
|
|
cases := []testcase{
|
|
{
|
|
name: "will return true if candidate is inbound",
|
|
candidate: "/home/test/app/readme.md",
|
|
basedir: "/home/test",
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "will return false if candidate is not inbound",
|
|
candidate: "/home/test/../readme.md",
|
|
basedir: "/home/test",
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "will return true if candidate is relative inbound",
|
|
candidate: "./readme.md",
|
|
basedir: "/home/test",
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "will return false if candidate is relative outbound",
|
|
candidate: "../readme.md",
|
|
basedir: "/home/test",
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "will return false if basedir is relative",
|
|
candidate: "/home/test/app/readme.md",
|
|
basedir: "./test",
|
|
expected: false,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
// given
|
|
t.Parallel()
|
|
|
|
// when
|
|
inbound := files.Inbound(c.candidate, c.basedir)
|
|
|
|
// then
|
|
assert.Equal(t, c.expected, inbound)
|
|
})
|
|
}
|
|
}
|