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
112 lines
2.5 KiB
Go
112 lines
2.5 KiB
Go
package core
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
"github.com/hanzoai/pack/core/app"
|
|
"github.com/hanzoai/pack/core/config"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGenerateConfigFromEnvironment(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
envVars map[string]string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "empty environment",
|
|
envVars: map[string]string{},
|
|
expected: `{
|
|
"steps": {},
|
|
"packages": {},
|
|
"caches": {},
|
|
"deploy": {}
|
|
}`,
|
|
},
|
|
|
|
{
|
|
name: "kitchen sink",
|
|
envVars: map[string]string{
|
|
"RAILPACK_INSTALL_CMD": "npm install",
|
|
"RAILPACK_BUILD_CMD": "npm run build",
|
|
"RAILPACK_START_CMD": "npm start",
|
|
"RAILPACK_PACKAGES": "node@18 [email protected]",
|
|
"RAILPACK_BUILD_APT_PACKAGES": "build-essential libssl-dev",
|
|
"RAILPACK_DEPLOY_APT_PACKAGES": "libssl-dev",
|
|
},
|
|
expected: `{
|
|
"steps": {
|
|
"install": {
|
|
"name": "install",
|
|
"commands": [
|
|
{ "src": ".", "dest": "." },
|
|
"npm install"
|
|
],
|
|
"secrets": ["*"],
|
|
"assets": {},
|
|
"variables": {}
|
|
},
|
|
"build": {
|
|
"name": "build",
|
|
"commands": [
|
|
{ "src": ".", "dest": "." },
|
|
"npm run build"
|
|
],
|
|
"secrets": ["*"],
|
|
"assets": {},
|
|
"variables": {}
|
|
}
|
|
},
|
|
"buildAptPackages": ["build-essential", "libssl-dev"],
|
|
"packages": {
|
|
"node": "18",
|
|
"python": "3.9"
|
|
},
|
|
"caches": {},
|
|
"deploy": {
|
|
"startCommand": "npm start",
|
|
"aptPackages": ["libssl-dev"]
|
|
},
|
|
"secrets": ["RAILPACK_BUILD_APT_PACKAGES", "RAILPACK_BUILD_CMD", "RAILPACK_DEPLOY_APT_PACKAGES",
|
|
"RAILPACK_INSTALL_CMD", "RAILPACK_PACKAGES", "RAILPACK_START_CMD"]
|
|
}`,
|
|
},
|
|
|
|
{
|
|
name: "unversioned packages",
|
|
envVars: map[string]string{
|
|
"RAILPACK_PACKAGES": "jq pipx:[email protected]",
|
|
},
|
|
expected: `{
|
|
"steps": {},
|
|
"packages": {
|
|
"jq": "latest",
|
|
"pipx:httpie": "3.2.4"
|
|
},
|
|
"caches": {},
|
|
"deploy": {},
|
|
"secrets": ["RAILPACK_PACKAGES"]
|
|
}`,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
env := app.NewEnvironment(&tt.envVars)
|
|
gotConfig := GenerateConfigFromEnvironment(env)
|
|
|
|
serializedConfig := config.Config{}
|
|
err := json.Unmarshal([]byte(tt.expected), &serializedConfig)
|
|
require.NoError(t, err)
|
|
|
|
if diff := cmp.Diff(serializedConfig, *gotConfig); diff != "" {
|
|
t.Errorf("GenerateConfigFromEnvironment() mismatch (-want +got):\n%s", diff)
|
|
}
|
|
})
|
|
}
|
|
}
|