- discovery.go: Wails inferred not only from wails.json but also from go.mod or go.work + frontend manifests at root, in frontend/, or at depth-2 monorepo paths, including Deno manifests. Flows through Discover, PrimaryType, DiscoverFull, projectdetect, WailsBuilder.Detect - regressions added across discovery_test, projectdetect_test, wails_test for the new layouts - cache_test + workflow_test: migrate stale `fs.Dirs[x] = true` assertions to `fs.EnsureDir` — the io.MockMedium API moved to the method-based shape Co-Authored-By: Virgil <virgil@lethean.io>
144 lines
3.6 KiB
Go
144 lines
3.6 KiB
Go
package build
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"dappco.re/go/core/io"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCache_SetupCache_Good(t *testing.T) {
|
|
fs := io.NewMockMedium()
|
|
cfg := &CacheConfig{
|
|
Enabled: true,
|
|
Paths: []string{
|
|
"cache/go-build",
|
|
"cache/go-mod",
|
|
},
|
|
}
|
|
|
|
err := SetupCache(fs, "/workspace/project", cfg)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, cfg)
|
|
|
|
assert.Equal(t, "/workspace/project/.core/cache", cfg.Directory)
|
|
assert.Equal(t, []string{
|
|
"/workspace/project/cache/go-build",
|
|
"/workspace/project/cache/go-mod",
|
|
}, cfg.Paths)
|
|
|
|
assert.True(t, fs.Exists("/workspace/project/.core/cache"))
|
|
assert.True(t, fs.Exists("/workspace/project/cache/go-build"))
|
|
assert.True(t, fs.Exists("/workspace/project/cache/go-mod"))
|
|
}
|
|
|
|
func TestCache_SetupBuildCache_Good(t *testing.T) {
|
|
fs := io.NewMockMedium()
|
|
cfg := &BuildConfig{
|
|
Build: Build{
|
|
Cache: CacheConfig{
|
|
Enabled: true,
|
|
Paths: []string{
|
|
"cache/go-build",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := SetupBuildCache(fs, "/workspace/project", cfg)
|
|
require.NoError(t, err)
|
|
require.NotNil(t, cfg)
|
|
|
|
assert.Equal(t, "/workspace/project/.core/cache", cfg.Build.Cache.Directory)
|
|
assert.Equal(t, []string{"/workspace/project/cache/go-build"}, cfg.Build.Cache.Paths)
|
|
assert.True(t, fs.Exists("/workspace/project/.core/cache"))
|
|
assert.True(t, fs.Exists("/workspace/project/cache/go-build"))
|
|
}
|
|
|
|
func TestCache_SetupCache_Good_Disabled(t *testing.T) {
|
|
fs := io.NewMockMedium()
|
|
cfg := &CacheConfig{
|
|
Enabled: false,
|
|
Paths: []string{"cache/go-build"},
|
|
}
|
|
|
|
err := SetupCache(fs, "/workspace/project", cfg)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, fs.Exists("/workspace/project/.core/cache"))
|
|
assert.Empty(t, fs.Files)
|
|
assert.Empty(t, cfg.Directory)
|
|
assert.Equal(t, []string{"cache/go-build"}, cfg.Paths)
|
|
}
|
|
|
|
func TestCache_SetupBuildCache_Good_Disabled(t *testing.T) {
|
|
fs := io.NewMockMedium()
|
|
cfg := &BuildConfig{
|
|
Build: Build{
|
|
Cache: CacheConfig{
|
|
Enabled: false,
|
|
Paths: []string{"cache/go-build"},
|
|
},
|
|
},
|
|
}
|
|
|
|
err := SetupBuildCache(fs, "/workspace/project", cfg)
|
|
require.NoError(t, err)
|
|
|
|
assert.False(t, fs.Exists("/workspace/project/.core/cache"))
|
|
assert.Empty(t, cfg.Build.Cache.Directory)
|
|
assert.Equal(t, []string{"cache/go-build"}, cfg.Build.Cache.Paths)
|
|
}
|
|
|
|
func TestCache_CacheKey_Good(t *testing.T) {
|
|
first := CacheKey("core-build", Target{OS: "linux", Arch: "amd64"}, &CacheConfig{
|
|
KeyPrefix: "main",
|
|
Paths: []string{
|
|
"cache/go-build",
|
|
"cache/go-mod",
|
|
},
|
|
RestoreKeys: []string{
|
|
"main-linux",
|
|
},
|
|
})
|
|
second := CacheKey("core-build", Target{OS: "linux", Arch: "amd64"}, &CacheConfig{
|
|
KeyPrefix: "main",
|
|
Paths: []string{
|
|
"cache/go-mod",
|
|
"cache/go-build",
|
|
},
|
|
RestoreKeys: []string{
|
|
"main-linux",
|
|
},
|
|
})
|
|
third := CacheKey("core-build", Target{OS: "darwin", Arch: "arm64"}, &CacheConfig{
|
|
KeyPrefix: "main",
|
|
})
|
|
|
|
assert.Equal(t, first, second)
|
|
assert.NotEqual(t, first, third)
|
|
assert.Contains(t, first, "main-linux-amd64-")
|
|
}
|
|
|
|
func TestCache_CacheEnvironment_Good(t *testing.T) {
|
|
t.Run("maps cache directory and Go cache paths to env vars", func(t *testing.T) {
|
|
env := CacheEnvironment(&CacheConfig{
|
|
Enabled: true,
|
|
Paths: []string{
|
|
"/workspace/project/cache/go-build",
|
|
"/workspace/project/cache/go-mod",
|
|
"/workspace/project/cache/go-build",
|
|
},
|
|
})
|
|
|
|
assert.Equal(t, []string{
|
|
"GOCACHE=/workspace/project/cache/go-build",
|
|
"GOMODCACHE=/workspace/project/cache/go-mod",
|
|
}, env)
|
|
})
|
|
|
|
t.Run("disabled cache returns no env vars", func(t *testing.T) {
|
|
assert.Nil(t, CacheEnvironment(&CacheConfig{Enabled: false}))
|
|
})
|
|
}
|