Skip to content

Commit bbaa3de

Browse files
authored
skipped tests with credentials from fork PRs (#104)
Signed-off-by: Tullio Sebastiani <tsebasti@redhat.com>
1 parent 44a55c3 commit bbaa3de

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
./staticcheck/staticcheck -checks all ./...
7474
7575
- name: run test suite
76+
env:
77+
CI_FORK_PR: ${{ github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
7678
run: |
7779
export USERID=$(id -u)
7880
go test -tags containers_image_openpgp -race -json -v -coverprofile=coverage.out ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
@@ -88,13 +90,15 @@ jobs:
8890
echo "TOTAL_COVERAGE=$COVERAGE" >> $GITHUB_ENV
8991
9092
- name: check out doc repo
93+
if: ${{ !github.event.pull_request.head.repo.fork }}
9194
uses: actions/checkout@v4
9295
with:
9396
repository: krkn-chaos/krkn-lib-docs
9497
path: krkn-lib-docs
9598
ssh-key: ${{ secrets.KRKN_LIB_DOCS_PRIV_KEY }}
9699

97100
- name: push updated coverage badge
101+
if: ${{ !github.event.pull_request.head.repo.fork }}
98102
env:
99103
COLOR: yellow
100104
run: |

pkg/provider/registryv2/scenario_provider_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package registryv2
22

33
import (
44
json_parser "encoding/json"
5+
"os"
6+
"testing"
7+
58
krknctlconfig "github.com/krkn-chaos/krknctl/pkg/config"
69
"github.com/krkn-chaos/krknctl/pkg/provider"
710
"github.com/krkn-chaos/krknctl/pkg/provider/models"
11+
"github.com/krkn-chaos/krknctl/pkg/utils"
812
"github.com/stretchr/testify/assert"
9-
"os"
10-
"testing"
1113
)
1214

1315
func getConfig(t *testing.T) krknctlconfig.Config {
@@ -46,6 +48,7 @@ curl -X GET \
4648
*/
4749

4850
func TestScenarioProvider_GetRegistryImages_jwt(t *testing.T) {
51+
utils.SkipTestIfForkPR(t)
4952
config := getConfig(t)
5053
p := ScenarioProvider{
5154
provider.BaseScenarioProvider{
@@ -141,6 +144,7 @@ func TestScenarioProvider_GetRegistryImages_Htpasswd(t *testing.T) {
141144
}
142145

143146
func TestScenarioProvider_GetScenarioDetail(t *testing.T) {
147+
utils.SkipTestIfForkPR(t)
144148
config := getConfig(t)
145149
p := ScenarioProvider{
146150
provider.BaseScenarioProvider{
@@ -169,7 +173,7 @@ func TestScenarioProvider_GetScenarioDetail(t *testing.T) {
169173
}
170174

171175
func TestScenarioProvider_GetGlobalEnvironment(t *testing.T) {
172-
176+
utils.SkipTestIfForkPR(t)
173177
config := getConfig(t)
174178
p := ScenarioProvider{
175179
provider.BaseScenarioProvider{
@@ -203,6 +207,7 @@ func TestScenarioProvider_GetGlobalEnvironment(t *testing.T) {
203207
}
204208

205209
func TestScenarioProvider_ScaffoldScenarios(t *testing.T) {
210+
utils.SkipTestIfForkPR(t)
206211
config := getConfig(t)
207212
p := ScenarioProvider{
208213
provider.BaseScenarioProvider{

pkg/scenarioorchestrator/scenarioorchestratortest/common_test_functions.go

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"os"
9+
"os/user"
10+
"path/filepath"
11+
"strconv"
12+
"strings"
13+
"testing"
14+
"time"
15+
816
"github.com/krkn-chaos/krknctl/pkg/cache"
917
krknctlconfig "github.com/krkn-chaos/krknctl/pkg/config"
1018
"github.com/krkn-chaos/krknctl/pkg/dependencygraph"
@@ -16,13 +24,6 @@ import (
1624
"github.com/krkn-chaos/krknctl/pkg/scenarioorchestrator/utils"
1725
krknctlutils "github.com/krkn-chaos/krknctl/pkg/utils"
1826
"github.com/stretchr/testify/assert"
19-
"os"
20-
"os/user"
21-
"path/filepath"
22-
"strconv"
23-
"strings"
24-
"testing"
25-
"time"
2627
)
2728

2829
func CommonGetConfig(t *testing.T) krknctlconfig.Config {
@@ -83,28 +84,33 @@ func CommonTestScenarioOrchestratorRun(t *testing.T, so scenarioorchestrator.Sce
8384
containerID, err := so.Run(registryURI+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx, nil)
8485
assert.Nil(t, err)
8586
assert.NotNil(t, containerID)
86-
87+
pr := providermodels.RegistryV2{}
8788
//pulling image from private registry with token
88-
quayToken := os.Getenv("QUAY_TOKEN")
89-
pr := providermodels.RegistryV2{
90-
RegistryURL: "quay.io",
91-
ScenarioRepository: "rh_ee_tsebasti/krkn-hub-private",
92-
Token: &quayToken,
93-
SkipTLS: true,
94-
}
9589

96-
timestamp = time.Now().Unix()
97-
containerName = fmt.Sprintf("%s-%s-%d%d", conf.ContainerPrefix, scenario.Name, timestamp, krknctlutils.RandomInt64(nil))
98-
containerID, err = so.Run(pr.GetPrivateRegistryURI()+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx, &pr)
99-
if so.GetContainerRuntime() == models.Docker {
100-
if err != nil {
101-
fmt.Println(err.Error())
90+
if os.Getenv("CI_FORK_PR") == "false" {
91+
quayToken := os.Getenv("QUAY_TOKEN")
92+
pr = providermodels.RegistryV2{
93+
RegistryURL: "quay.io",
94+
ScenarioRepository: "rh_ee_tsebasti/krkn-hub-private",
95+
Token: &quayToken,
96+
SkipTLS: true,
97+
}
98+
99+
timestamp = time.Now().Unix()
100+
containerName = fmt.Sprintf("%s-%s-%d%d", conf.ContainerPrefix, scenario.Name, timestamp, krknctlutils.RandomInt64(nil))
101+
containerID, err = so.Run(pr.GetPrivateRegistryURI()+":"+scenario.Name, containerName, env, false, map[string]string{}, nil, ctx, &pr)
102+
if so.GetContainerRuntime() == models.Docker {
103+
if err != nil {
104+
fmt.Println(err.Error())
105+
}
106+
assert.Nil(t, err)
107+
assert.NotNil(t, containerID)
108+
} else {
109+
assert.NotNil(t, err)
110+
assert.Equal(t, err.Error(), "token authentication not yet supported in podman")
102111
}
103-
assert.Nil(t, err)
104-
assert.NotNil(t, containerID)
105112
} else {
106-
assert.NotNil(t, err)
107-
assert.Equal(t, err.Error(), "token authentication not yet supported in podman")
113+
t.Log("skipping quay private registry on fork PR for lack of credentials")
108114
}
109115

110116
//pulling image from private registry with username and password

pkg/utils/utils_function.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010
"strings"
11+
"testing"
1112
)
1213

1314
func ExpandFolder(folder string, basePath *string) (*string, error) {
@@ -47,3 +48,10 @@ func RandomInt64(max *int64) int64 {
4748
}
4849
return bigRand.Int64()
4950
}
51+
52+
func SkipTestIfForkPR(t *testing.T) {
53+
t.Helper()
54+
if os.Getenv("CI_FORK_PR") == "true" {
55+
t.Skip("skipped on fork PR (no secrets / external repo)")
56+
}
57+
}

0 commit comments

Comments
 (0)