-
Notifications
You must be signed in to change notification settings - Fork 73
/
bitbucket_server_test.go
76 lines (67 loc) · 2.73 KB
/
bitbucket_server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"errors"
"fmt"
"github.com/jfrog/frogbot/v2/utils"
"github.com/jfrog/froggit-go/vcsclient"
"github.com/jfrog/froggit-go/vcsutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
"net/http"
"testing"
)
const (
bitbucketServerIntegrationTokenEnv = "FROGBOT_TESTS_BB_SERVER_TOKEN"
bitbucketServerApiEndpoint = "http://localhost:7990/rest"
bitbucketServerGitCloneUrl = "http://localhost:7990/scm/frog/integration.git"
)
func buildBitbucketServerClient(t *testing.T, bitbucketServerToken string) vcsclient.VcsClient {
bbClient, err := vcsclient.NewClientBuilder(vcsutils.BitbucketServer).Username("frogbot").ApiEndpoint(bitbucketServerApiEndpoint).Token(bitbucketServerToken).Build()
assert.NoError(t, err)
return bbClient
}
func buildBitbucketServerIntegrationTestDetails(t *testing.T, useLocalRepo bool) *IntegrationTestDetails {
integrationRepoToken := getIntegrationToken(t, bitbucketServerIntegrationTokenEnv)
testDetails := NewIntegrationTestDetails(integrationRepoToken, string(utils.BitbucketServer), bitbucketServerGitCloneUrl, "FROG", useLocalRepo)
testDetails.ApiEndpoint = bitbucketServerApiEndpoint
return testDetails
}
func waitForConnection(t *testing.T) {
log.Info("Waiting for Bitbucket Server to be up and running...")
retryExecutor := vcsutils.RetryExecutor{
MaxRetries: 10,
RetriesIntervalMilliSecs: 60000,
Logger: log.Logger,
}
retryExecutor.ExecutionHandler = func() (bool, error) {
res, err := http.Get("http://localhost:7990/status")
if err != nil || res.StatusCode != http.StatusOK {
body, e := io.ReadAll(res.Body)
err = errors.Join(err, e)
log.Info(fmt.Sprintf("Status code: %d, Server current state: %s", res.StatusCode, body))
return true, err
}
return false, nil
}
require.NoError(t, retryExecutor.Execute())
}
func bitbucketServerTestsInit(t *testing.T, useLocalRepo bool) (vcsclient.VcsClient, *IntegrationTestDetails) {
testDetails := buildBitbucketServerIntegrationTestDetails(t, useLocalRepo)
bbClient := buildBitbucketServerClient(t, testDetails.GitToken)
waitForConnection(t)
return bbClient, testDetails
}
func TestBitbucketServer_ScanPullRequestIntegration(t *testing.T) {
bbClient, testDetails := bitbucketServerTestsInit(t, false)
runScanPullRequestCmd(t, bbClient, testDetails)
}
func TestBitbucketServer_ScanRepositoryIntegration(t *testing.T) {
bbClient, testDetails := bitbucketServerTestsInit(t, false)
runScanRepositoryCmd(t, bbClient, testDetails)
}
func TestBitbucketServer_ScanRepositoryWithLocalDirIntegration(t *testing.T) {
bbClient, testDetails := bitbucketServerTestsInit(t, true)
runScanRepositoryCmd(t, bbClient, testDetails)
}