* chore(io): Migrate pkg/build to Medium abstraction - Updated io.Medium interface with Open() and Create() methods to support streaming. - Migrated pkg/build, pkg/build/builders, and pkg/build/signing to use io.Medium. - Added FS field to build.Config and updated build.Builder interface. - Refactored checksum and archive logic to use io.Medium streaming. - Updated pkg/release and pkg/build/buildcmd to use io.Local. - Updated unit tests to match new signatures. * chore(io): Migrate pkg/build to Medium abstraction (fix CI) - Fixed formatting in pkg/build/builders/wails.go. - Fixed TestLoadConfig_Testdata and TestDiscover_Testdata to use absolute paths with io.Local to ensure compatibility with GitHub CI. - Verified that all build and release tests pass. * chore(io): Migrate pkg/build to Medium abstraction (fix CI paths) - Ensured that outputDir and configPath are absolute in runProjectBuild. - Fixed TestLoadConfig_Testdata and TestDiscover_Testdata to use absolute paths correctly. - Verified that all build and release tests pass locally. * chore(io): Migrate pkg/build to Medium abstraction (final fix) - Improved io.Local to handle relative paths relative to CWD when rooted at "/". - This makes io.Local a drop-in replacement for the 'os' package for most use cases. - Ensured absolute paths are used in build logic and tests where appropriate. - Fixed formatting and cleaned up debug prints. * chore(io): address code review and fix CI - Fix MockFile.Read to return io.EOF - Use filepath.Match in TaskfileBuilder for precise globbing - Stream xz data in createTarXzArchive to avoid in-memory string conversion - Fix TestPath_RootFilesystem in local medium tests - Fix formatting in pkg/build/buildcmd/cmd_project.go * chore(io): resolve merge conflicts and final migration of pkg/build - Resolved merge conflicts in pkg/io/io.go, pkg/io/local/client.go, and pkg/release/release.go. - Reconciled io.Medium interface with upstream changes (unifying to fs.File for Open). - Integrated upstream validatePath logic into the local medium. - Completed migration of pkg/build and related packages to io.Medium. - Addressed previous code review feedback on MockMedium and TaskfileBuilder. * chore(io): resolve merge conflicts and finalize migration - Resolved merge conflicts with dev branch. - Unified io.Medium interface (Open returns fs.File, Create returns io.WriteCloser). - Integrated upstream validatePath logic. - Ensured all tests pass across pkg/io, pkg/build, and pkg/release. --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
162 lines
3.3 KiB
Go
162 lines
3.3 KiB
Go
package signing
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/host-uk/core/pkg/io"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSignBinaries_Good_SkipsNonDarwin(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: true,
|
|
MacOS: MacOSConfig{
|
|
Identity: "Developer ID Application: Test",
|
|
},
|
|
}
|
|
|
|
// Create fake artifact for linux
|
|
artifacts := []Artifact{
|
|
{Path: "/tmp/test-binary", OS: "linux", Arch: "amd64"},
|
|
}
|
|
|
|
// Should not error even though binary doesn't exist (skips non-darwin)
|
|
err := SignBinaries(ctx, fs, cfg, artifacts)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSignBinaries_Good_DisabledConfig(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: false,
|
|
}
|
|
|
|
artifacts := []Artifact{
|
|
{Path: "/tmp/test-binary", OS: "darwin", Arch: "arm64"},
|
|
}
|
|
|
|
err := SignBinaries(ctx, fs, cfg, artifacts)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSignBinaries_Good_SkipsOnNonMacOS(t *testing.T) {
|
|
if runtime.GOOS == "darwin" {
|
|
t.Skip("Skipping on macOS - this tests non-macOS behavior")
|
|
}
|
|
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: true,
|
|
MacOS: MacOSConfig{
|
|
Identity: "Developer ID Application: Test",
|
|
},
|
|
}
|
|
|
|
artifacts := []Artifact{
|
|
{Path: "/tmp/test-binary", OS: "darwin", Arch: "arm64"},
|
|
}
|
|
|
|
err := SignBinaries(ctx, fs, cfg, artifacts)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNotarizeBinaries_Good_DisabledConfig(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: false,
|
|
}
|
|
|
|
artifacts := []Artifact{
|
|
{Path: "/tmp/test-binary", OS: "darwin", Arch: "arm64"},
|
|
}
|
|
|
|
err := NotarizeBinaries(ctx, fs, cfg, artifacts)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNotarizeBinaries_Good_NotarizeDisabled(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: true,
|
|
MacOS: MacOSConfig{
|
|
Notarize: false,
|
|
},
|
|
}
|
|
|
|
artifacts := []Artifact{
|
|
{Path: "/tmp/test-binary", OS: "darwin", Arch: "arm64"},
|
|
}
|
|
|
|
err := NotarizeBinaries(ctx, fs, cfg, artifacts)
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSignChecksums_Good_SkipsNoKey(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: true,
|
|
GPG: GPGConfig{
|
|
Key: "", // No key configured
|
|
},
|
|
}
|
|
|
|
// Should silently skip when no key
|
|
err := SignChecksums(ctx, fs, cfg, "/tmp/CHECKSUMS.txt")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSignChecksums_Good_Disabled(t *testing.T) {
|
|
ctx := context.Background()
|
|
fs := io.Local
|
|
cfg := SignConfig{
|
|
Enabled: false,
|
|
}
|
|
|
|
err := SignChecksums(ctx, fs, cfg, "/tmp/CHECKSUMS.txt")
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestDefaultSignConfig(t *testing.T) {
|
|
cfg := DefaultSignConfig()
|
|
assert.True(t, cfg.Enabled)
|
|
}
|
|
|
|
func TestSignConfig_ExpandEnv(t *testing.T) {
|
|
t.Setenv("TEST_KEY", "ABC")
|
|
cfg := SignConfig{
|
|
GPG: GPGConfig{Key: "$TEST_KEY"},
|
|
}
|
|
cfg.ExpandEnv()
|
|
assert.Equal(t, "ABC", cfg.GPG.Key)
|
|
}
|
|
|
|
func TestWindowsSigner_Good(t *testing.T) {
|
|
fs := io.Local
|
|
s := NewWindowsSigner(WindowsConfig{})
|
|
assert.Equal(t, "signtool", s.Name())
|
|
assert.False(t, s.Available())
|
|
assert.NoError(t, s.Sign(context.Background(), fs, "test.exe"))
|
|
}
|