-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move gha cache to its own suite
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
85 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
//go:build !ghacache | ||
|
||
package client | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//go:build ghacache | ||
|
||
package client | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/moby/buildkit/util/testutil/integration" | ||
"github.com/moby/buildkit/util/testutil/workers" | ||
) | ||
|
||
func init() { | ||
if workers.IsTestDockerd() { | ||
workers.InitDockerdWorker() | ||
} else { | ||
workers.InitOCIWorker() | ||
workers.InitContainerdWorker() | ||
} | ||
} | ||
|
||
func TestGhaCacheIntegration(t *testing.T) { | ||
testIntegration(t, testBasicGhaCacheImportExportExtraTimeout) | ||
} | ||
|
||
func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sandbox)) { | ||
mirroredImagesUnix := integration.OfficialImages("busybox:latest", "alpine:latest") | ||
mirroredImagesWin := integration.OfficialImages("nanoserver:latest", "nanoserver:plus") | ||
mirroredImages := integration.UnixOrWindows(mirroredImagesUnix, mirroredImagesWin) | ||
mirrors := integration.WithMirroredImages(mirroredImages) | ||
integration.Run(t, integration.TestFuncs(funcs...), mirrors) | ||
} | ||
|
||
func testBasicGhaCacheImportExportExtraTimeout(t *testing.T, sb integration.Sandbox) { | ||
workers.CheckFeatureCompat(t, sb, | ||
workers.FeatureCacheExport, | ||
workers.FeatureCacheImport, | ||
workers.FeatureCacheBackendGha, | ||
) | ||
runtimeToken := os.Getenv("ACTIONS_RUNTIME_TOKEN") | ||
cacheURL := os.Getenv("ACTIONS_CACHE_URL") | ||
if runtimeToken == "" || cacheURL == "" { | ||
t.Skip("ACTIONS_RUNTIME_TOKEN and ACTIONS_CACHE_URL must be set") | ||
} | ||
|
||
scope := "buildkit-" + t.Name() | ||
if ref := os.Getenv("GITHUB_REF"); ref != "" { | ||
if strings.HasPrefix(ref, "refs/heads/") { | ||
scope += "-" + strings.TrimPrefix(ref, "refs/heads/") | ||
} else if strings.HasPrefix(ref, "refs/tags/") { | ||
scope += "-" + strings.TrimPrefix(ref, "refs/tags/") | ||
} else if strings.HasPrefix(ref, "refs/pull/") { | ||
scope += "-pr" + strings.TrimPrefix(strings.TrimSuffix(strings.TrimSuffix(ref, "/head"), "/merge"), "refs/pull/") | ||
} | ||
} | ||
|
||
im := CacheOptionsEntry{ | ||
Type: "gha", | ||
Attrs: map[string]string{ | ||
"url": cacheURL, | ||
"token": runtimeToken, | ||
"scope": scope, | ||
}, | ||
} | ||
ex := CacheOptionsEntry{ | ||
Type: "gha", | ||
Attrs: map[string]string{ | ||
"url": cacheURL, | ||
"token": runtimeToken, | ||
"scope": scope, | ||
"mode": "max", | ||
}, | ||
} | ||
testBasicCacheImportExport(t, sb, []CacheOptionsEntry{im}, []CacheOptionsEntry{ex}) | ||
} |