mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
- Migrate module path to github.com/hanzoai/pack across all Go packages - Remove legacy upstream docs and competitor brand references - Modernize LLM.md and mise.toml for pristine Hanzo Pack builder
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
package golang
|
|
|
|
import (
|
|
"testing"
|
|
|
|
testingUtils "github.com/hanzoai/pack/core/testing"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGolang(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
detected bool
|
|
hasGoMod bool
|
|
hasWorkspace bool
|
|
goVersion string
|
|
cgoEnabled bool
|
|
}{
|
|
{
|
|
name: "go mod",
|
|
path: "../../../examples/go-mod",
|
|
detected: true,
|
|
hasGoMod: true,
|
|
goVersion: "1.25.3",
|
|
},
|
|
{
|
|
name: "go cmd dirs",
|
|
path: "../../../examples/go-cmd-dirs",
|
|
detected: true,
|
|
hasGoMod: true,
|
|
goVersion: "1.25.3",
|
|
},
|
|
{
|
|
name: "go workspaces",
|
|
path: "../../../examples/go-workspaces",
|
|
detected: true,
|
|
hasGoMod: false,
|
|
hasWorkspace: true,
|
|
goVersion: "1.25",
|
|
},
|
|
{
|
|
name: "node",
|
|
path: "../../../examples/node-npm",
|
|
detected: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := testingUtils.CreateGenerateContext(t, tt.path)
|
|
provider := GoProvider{}
|
|
detected, err := provider.Detect(ctx)
|
|
require.NoError(t, err)
|
|
require.Equal(t, tt.detected, detected)
|
|
|
|
if detected {
|
|
err = provider.Initialize(ctx)
|
|
require.NoError(t, err)
|
|
|
|
err = provider.Plan(ctx)
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, tt.hasGoMod, provider.isGoMod(ctx))
|
|
require.Equal(t, tt.hasWorkspace, provider.isGoWorkspace(ctx))
|
|
require.Equal(t, tt.cgoEnabled, provider.hasCGOEnabled(ctx))
|
|
|
|
if tt.goVersion != "" {
|
|
goVersion := ctx.Resolver.Get("go")
|
|
require.Equal(t, tt.goVersion, goVersion.Version)
|
|
}
|
|
|
|
if tt.hasWorkspace {
|
|
packages := provider.GoWorkspacePackages(ctx)
|
|
require.Greater(t, len(packages), 0, "workspace should have at least one package")
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|