mirror of
https://github.com/hanzoai/pack.git
synced 2026-09-30 23:43:13 +00:00
* fix: respect cache backend type for registry cache import/export * docs: update local development build instructions - Update local image building to use the provided project task. - Document the workflow for building with a local registry. - Add examples for configuring buildctl with caching and debugging flags. Generated-by: aiautocommit * refactor(buildkit): clean up code comments and formatting - Remove redundant comments and improve internal documentation. - Fix minor formatting inconsistencies in code blocks and comment descriptions. Generated-by: aiautocommit * feat: add ParseBool utility to handle common boolean string variants Generated-by: aiautocommit * feat: integrate local registry and buildkit configuration - Add buildkitd configuration to enable HTTP/insecure access to the local registry. - Introduce a local registry service container on port 7890. - Update the buildkit setup to mount the new registry configuration. - Add tasks for building the frontend image and running project builds using the local registry and buildctl. Generated-by: aiautocommit * docs: update CLAUDE.md with architecture and style guidance Generated-by: aiautocommit * feat: add support for multiple cache-from and cache-to build flags - Allow users to configure external cache sources and destinations via the `build` subcommand. - Update cache parsing logic to support multiple entries matching the Docker buildx CLI format. - Remove hardcoded default cache type to provide better control over BuildKit cache configurations. Generated-by: aiautocommit * test: add integration tests for cache-import parsing Generated-by: aiautocommit * refactor(buildkit): extract cache entry parsing logic - Centralize cache configuration logic by moving loop-based parsing into a reusable `cacheEntriesFromFlags` helper. - Improve code maintainability and readability by reducing duplication in `BuildWithBuildkitClient`. - Add comprehensive unit tests for cache entry processing, including edge cases for flag parsing and empty inputs. Generated-by: aiautocommit * fix(test): remove unused buildkit cache flags from integration tests * Remove unused flag variables that were meant for remote BuildKit caching. * Ensure integration tests avoid remote cache (e.g., type=gha) to prevent exceeding GitHub Actions cache limits and excessive eviction. Generated-by: aiautocommit * test(buildkit): consolidate cache import tests - Move TestParseCacheImports from its own file to frontend_test.go to consolidate related buildkit frontend tests. Generated-by: aiautocommit * style: fix indentation in build test helper Generated-by: aiautocommit * docs: document support for BuildKit cache backends Generated-by: aiautocommit * docs(developing-locally): add information on Docker, BuildKit, and caching - Add missing setup prerequisites. - Include debugging and configuration guidance for BuildKit/Docker. - Clarify cache export and import implementation expectations in Railpack. Generated-by: aiautocommit * docs: clarify cache flag parsing and pnpm version logic Generated-by: aiautocommit --------- Co-authored-by: Matt Van Horn <[email protected]> Co-authored-by: Michael Bianco <[email protected]> Co-authored-by: Hanzo Dev <[email protected]>
148 lines
3.5 KiB
Go
148 lines
3.5 KiB
Go
package utils
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseBool(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
wantValue bool
|
|
wantOK bool
|
|
}{
|
|
{name: "true", input: "true", wantValue: true, wantOK: true},
|
|
{name: "TRUE spaced", input: " TRUE ", wantValue: true, wantOK: true},
|
|
{name: "1", input: "1", wantValue: true, wantOK: true},
|
|
{name: "yes", input: "yes", wantValue: true, wantOK: true},
|
|
{name: "on", input: "on", wantValue: true, wantOK: true},
|
|
{name: "false", input: "false", wantValue: false, wantOK: true},
|
|
{name: "0", input: "0", wantValue: false, wantOK: true},
|
|
{name: "no", input: "no", wantValue: false, wantOK: true},
|
|
{name: "off", input: "off", wantValue: false, wantOK: true},
|
|
{name: "empty", input: "", wantValue: false, wantOK: false},
|
|
{name: "unknown", input: "maybe", wantValue: false, wantOK: false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
gotValue, gotOK := ParseBool(tt.input)
|
|
if gotValue != tt.wantValue || gotOK != tt.wantOK {
|
|
t.Errorf("ParseBool(%q) = (%v, %v), want (%v, %v)", tt.input, gotValue, gotOK, tt.wantValue, tt.wantOK)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParseSemver(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
version string
|
|
want *Semver
|
|
wantErr bool
|
|
errorPrefix string
|
|
}{
|
|
{
|
|
name: "basic semver",
|
|
version: "1.2.3",
|
|
want: &Semver{Major: 1, Minor: 2, Patch: 3},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "with v prefix",
|
|
version: "v1.2.3",
|
|
want: &Semver{Major: 1, Minor: 2, Patch: 3},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "with other prefix",
|
|
version: "ruby-2.3.4",
|
|
want: nil,
|
|
wantErr: true,
|
|
errorPrefix: "invalid major version",
|
|
},
|
|
{
|
|
name: "with alpha suffix",
|
|
version: "1.2.3-alpha",
|
|
want: &Semver{Major: 1, Minor: 2, Patch: 3},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "with beta suffix",
|
|
version: "1.2.3-beta",
|
|
want: &Semver{Major: 1, Minor: 2, Patch: 3},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "two parts",
|
|
version: "1.2",
|
|
want: &Semver{Major: 1, Minor: 2, Patch: 0},
|
|
},
|
|
{
|
|
name: "invalid major",
|
|
version: "a.2.3",
|
|
want: nil,
|
|
wantErr: true,
|
|
errorPrefix: "invalid major version",
|
|
},
|
|
{
|
|
name: "invalid minor",
|
|
version: "1.b.3",
|
|
want: nil,
|
|
wantErr: true,
|
|
errorPrefix: "invalid minor version",
|
|
},
|
|
{
|
|
name: "invalid patch",
|
|
version: "1.2.c",
|
|
want: nil,
|
|
wantErr: true,
|
|
errorPrefix: "invalid patch version",
|
|
},
|
|
{
|
|
name: "invalid",
|
|
version: "1-23",
|
|
want: nil,
|
|
wantErr: true,
|
|
errorPrefix: "invalid major version",
|
|
},
|
|
{
|
|
name: "corepack version",
|
|
version: "[email protected]",
|
|
want: &Semver{
|
|
Major: 8,
|
|
Minor: 15,
|
|
Patch: 4,
|
|
},
|
|
wantErr: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := ParseSemver(tt.version)
|
|
|
|
// Check error cases
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ParseSemver() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
|
|
// If we expect an error, check the error message prefix
|
|
if tt.wantErr && err != nil {
|
|
if !strings.HasPrefix(err.Error(), tt.errorPrefix) {
|
|
t.Errorf("ParseSemver() error = %v, wantErrPrefix %v", err, tt.errorPrefix)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Check valid result cases
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("ParseSemver() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|