Skip to content

Commit 4625771

Browse files
authored
ci: add Docker credentials env vars and skip test if not set (#4687)
Signed-off-by: Gaius <gaius.qi@gmail.com>
1 parent eda0bdc commit 4625771

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ jobs:
3737
sudo ip addr
3838
3939
- name: Run Unit tests
40+
env:
41+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
42+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
4043
run: |-
4144
# switch to installed go
4245
sudo ln -sf `which go` `sudo which go`

internal/job/image_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ package job
1818

1919
import (
2020
"context"
21+
"os"
2122
"testing"
2223
"time"
2324

2425
"github.com/stretchr/testify/assert"
2526
)
2627

2728
func TestPreheat_CreatePreheatRequestsByManifestURL(t *testing.T) {
29+
username := os.Getenv("DOCKER_USERNAME")
30+
password := os.Getenv("DOCKER_PASSWORD")
31+
if username == "" || password == "" {
32+
t.Skip("DOCKER_USERNAME or DOCKER_PASSWORD is not set, skipping test")
33+
}
34+
2835
tests := []struct {
2936
name string
3037
req *ManifestRequest
@@ -34,6 +41,8 @@ func TestPreheat_CreatePreheatRequestsByManifestURL(t *testing.T) {
3441
name: "get image layers with manifest url",
3542
req: &ManifestRequest{
3643
URL: "https://registry-1.docker.io/v2/dragonflyoss/busybox/manifests/1.35.0",
44+
Username: username,
45+
Password: password,
3746
Timeout: 30 * time.Second,
3847
InsecureSkipVerify: true,
3948
},
@@ -47,6 +56,8 @@ func TestPreheat_CreatePreheatRequestsByManifestURL(t *testing.T) {
4756
req: &ManifestRequest{
4857
URL: "https://registry-1.docker.io/v2/dragonflyoss/scheduler/manifests/v2.1.0",
4958
Platform: "linux/amd64",
59+
Username: username,
60+
Password: password,
5061
Timeout: 30 * time.Second,
5162
InsecureSkipVerify: true,
5263
},

0 commit comments

Comments
 (0)