All checks were successful
default / test artifact actions (push) Successful in 26s
76 lines
2.1 KiB
Go
76 lines
2.1 KiB
Go
package internal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"code.geekeey.de/actions/artifacts/internal/pull"
|
|
"code.geekeey.de/actions/artifacts/internal/push"
|
|
"code.geekeey.de/actions/sdk"
|
|
"code.geekeey.de/actions/sdk/artifact"
|
|
)
|
|
|
|
// TestE2E_PushPullRoundTrip runs the push and pull actions against the real
|
|
// results service. It only runs inside a CI pipeline (GITHUB_ACTIONS=true) and
|
|
// is skipped locally. Its purpose is to detect drift in the artifact actions.
|
|
func TestE2E_PushPullRoundTrip(t *testing.T) {
|
|
if os.Getenv("GITHUB_ACTIONS") != "true" {
|
|
t.Skip("e2e test only runs in CI")
|
|
}
|
|
if os.Getenv("ACTIONS_RESULTS_URL") == "" || os.Getenv("ACTIONS_RUNTIME_TOKEN") == "" {
|
|
t.Skip("ACTIONS_RESULTS_URL and ACTIONS_RUNTIME_TOKEN are required")
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
|
|
name := fmt.Sprintf("e2e-%d-%d", os.Getpid(), time.Now().UnixNano())
|
|
t.Cleanup(func() {
|
|
run, job, err := artifact.JobInfo()
|
|
if err != nil {
|
|
return
|
|
}
|
|
client := artifact.NewClientFromEnv(os.Getenv)
|
|
_, _ = client.DeleteArtifact(context.Background(), artifact.DeleteArtifactRequest{RunID: run, JobRunID: job, Name: name})
|
|
})
|
|
|
|
const want = "hello e2e"
|
|
|
|
src := t.TempDir()
|
|
if err := os.MkdirAll(filepath.Join(src, "nested"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(src, "file.txt"), []byte(want), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(src, "nested", "deep.txt"), []byte(want), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Setenv("INPUT_NAME", name)
|
|
t.Setenv("INPUT_PATH", src)
|
|
t.Setenv("INPUT_PATTERN", "**/*")
|
|
if err := push.New(sdk.New()).Run(ctx); err != nil {
|
|
t.Fatalf("push: %v", err)
|
|
}
|
|
|
|
dst := t.TempDir()
|
|
t.Setenv("INPUT_PATH", dst)
|
|
if err := pull.New(sdk.New()).Run(ctx); err != nil {
|
|
t.Fatalf("pull: %v", err)
|
|
}
|
|
|
|
for _, file := range []string{"file.txt", filepath.Join("nested", "deep.txt")} {
|
|
got, err := os.ReadFile(filepath.Join(dst, file))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(got) != want {
|
|
t.Errorf("expected %q to contain %q, got %q", file, want, got)
|
|
}
|
|
}
|
|
}
|