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
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
package buildkit
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
|
"github.com/hanzoai/pack/buildkit/build_llb"
|
|
"github.com/hanzoai/pack/core/plan"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetImageEnvIncludesBuiltAt(t *testing.T) {
|
|
graphOutput := &build_llb.BuildGraphOutput{
|
|
GraphEnv: build_llb.NewGraphEnvironment(),
|
|
}
|
|
buildPlan := plan.NewBuildPlan()
|
|
buildPlan.Deploy.Variables = map[string]string{
|
|
"RAILPACK_BUILT_AT": "custom",
|
|
}
|
|
before := time.Now().Unix()
|
|
|
|
env := getImageEnv(graphOutput, buildPlan)
|
|
after := time.Now().Unix()
|
|
|
|
builtAt := ""
|
|
for _, variable := range env {
|
|
if value, ok := strings.CutPrefix(variable, "RAILPACK_BUILT_AT="); ok {
|
|
builtAt = value
|
|
}
|
|
}
|
|
timestamp, err := strconv.ParseInt(builtAt, 10, 64)
|
|
require.NoError(t, err)
|
|
require.GreaterOrEqual(t, timestamp, before)
|
|
require.LessOrEqual(t, timestamp, after)
|
|
require.True(t, slices.IsSorted(env))
|
|
}
|
|
|
|
func TestDeployVariablesDoNotAffectLLB(t *testing.T) {
|
|
firstPlan := plan.NewBuildPlan()
|
|
firstPlan.Deploy.Base = plan.NewImageLayer("alpine:latest")
|
|
firstPlan.Deploy.Variables = map[string]string{"VALUE": "one"}
|
|
secondPlan := plan.NewBuildPlan()
|
|
secondPlan.Deploy.Base = plan.NewImageLayer("alpine:latest")
|
|
secondPlan.Deploy.Variables = map[string]string{"VALUE": "two"}
|
|
opts := ConvertPlanOptions{
|
|
BuildPlatform: specs.Platform{
|
|
OS: "linux",
|
|
Architecture: "amd64",
|
|
},
|
|
}
|
|
|
|
firstState, firstImage, err := ConvertPlanToLLB(firstPlan, opts)
|
|
require.NoError(t, err)
|
|
secondState, secondImage, err := ConvertPlanToLLB(secondPlan, opts)
|
|
require.NoError(t, err)
|
|
|
|
firstDefinition, err := firstState.Marshal(context.Background())
|
|
require.NoError(t, err)
|
|
secondDefinition, err := secondState.Marshal(context.Background())
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, firstDefinition.ToPB(), secondDefinition.ToPB())
|
|
require.NotEqual(t, firstImage.Config.Env, secondImage.Config.Env)
|
|
}
|