Skip to content

Commit afc5a0a

Browse files
authored
[Feature] Enable k8s tests (#363)
1 parent c1d2bb2 commit afc5a0a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

test/client_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ var (
5454
runPProfServerOnce sync.Once
5555
)
5656

57+
func skipOnK8S(t *testing.T) {
58+
if isK8S() {
59+
t.Skip("Skipping on k8s")
60+
}
61+
}
62+
63+
func isK8S() bool {
64+
return os.Getenv("TEST_MODE") == "k8s"
65+
}
66+
5767
// skipBetweenVersion skips the test if the current server version is less than
5868
// the min version or higher/equal max version
5969
func skipBetweenVersion(c driver.Client, minVersion, maxVersion driver.Version, t *testing.T) driver.VersionInfo {
@@ -245,7 +255,7 @@ func createClientFromEnv(t testEnv, waitUntilReady bool) driver.Client {
245255
// waitUntilServerAvailable keeps waiting until the server/cluster that the client is addressing is available.
246256
func waitUntilServerAvailable(ctx context.Context, c driver.Client, t testEnv) error {
247257
return driverErrorCheck(ctx, c, func(ctx context.Context, client driver.Client) error {
248-
if getTestMode() != testModeSingle {
258+
if getTestMode() != testModeSingle && !isK8S() {
249259
// Refresh endpoints
250260
if err := client.SynchronizeEndpoints2(ctx, "_system"); err != nil {
251261
return err
@@ -322,6 +332,10 @@ func waitUntilClusterHealthy(c driver.Client) error {
322332

323333
// waitUntilEndpointSynchronized keeps waiting until the endpoints are synchronized. leadership might be ongoing.
324334
func waitUntilEndpointSynchronized(ctx context.Context, c driver.Client, dbname string, t testEnv) error {
335+
if isK8S() {
336+
return nil
337+
}
338+
325339
return driverErrorCheck(ctx, c, func(ctx context.Context, client driver.Client) error {
326340
callCtx, cancel := context.WithTimeout(ctx, time.Second*5)
327341
defer cancel()

test/server_mode_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ package test
2424

2525
import (
2626
"context"
27-
"os"
2827
"testing"
2928

3029
driver "github.com/arangodb/go-driver"
30+
"os"
31+
"strings"
3132
)
3233

3334
// TestServerMode creates a database and checks the various server modes.
3435
func TestServerMode(t *testing.T) {
3536
c := createClientFromEnv(t, true)
3637
ctx := context.Background()
3738

38-
if os.Getenv("TEST_AUTHENTICATION") == "super:testing" {
39+
if strings.HasPrefix(os.Getenv("TEST_AUTHENTICATION"), "super:") {
3940
t.Skip("Skipping read only test because of superuser access.")
4041
}
4142
version, err := c.Version(nil)

test/server_statistics_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"time"
3131

3232
driver "github.com/arangodb/go-driver"
33+
"strings"
3334
)
3435

3536
func checkEnabled(t *testing.T, c driver.Client, ctx context.Context) {
@@ -193,16 +194,15 @@ func TestServerStatisticsTraffic(t *testing.T) {
193194
// Now check if user only stats are there and see if they should have increased:
194195
if statsBefore.ClientUser.BytesReceived.Counts != nil {
195196
t.Logf("New user only statistics API is present, testing...")
196-
auth := os.Getenv("TEST_AUTHENTICATION")
197-
if auth == "super:testing" {
198-
t.Logf("Authentication %s is jwt superuser, expecting no user traffic...", auth)
197+
if strings.HasPrefix(os.Getenv("TEST_AUTHENTICATION"), "super:") {
198+
t.Logf("Authentication %s is jwt superuser, expecting no user traffic...", os.Getenv("TEST_AUTHENTICATION"))
199199
// Traffic is superuser, so nothing should be counted in ClientUser,
200200
// not even the statistics calls.
201201
checkTrafficAtMost(t, &statsBefore, &statsAfter, user,
202202
&limits{Sent: 0.1, Recv: 0.1,
203203
SentCount: 0, RecvCount: 0}, "Cherry")
204204
} else {
205-
t.Logf("Authentication %s is not jwt superuser, expecting to see user traffic...", auth)
205+
t.Logf("Authentication %s is not jwt superuser, expecting to see user traffic...", os.Getenv("TEST_AUTHENTICATION"))
206206
// Traffic is either unauthenticated or with password, so there should
207207
// be traffic in ClientUser
208208
checkTrafficAtLeast(t, &statsBefore, &statsAfter, user,
@@ -246,7 +246,7 @@ func TestServerStatisticsForwarding(t *testing.T) {
246246
endpoints := conn.Endpoints()
247247

248248
if len(endpoints) < 2 {
249-
t.Fatalf("Did not have at least two endpoints. Giving up.")
249+
t.Skipf("Did not have at least two endpoints. Giving up.")
250250
}
251251

252252
// Do a preliminary test to see if we can do some traffic on one coordinator
@@ -348,8 +348,7 @@ func TestServerStatisticsForwarding(t *testing.T) {
348348
// However, first coordinator should have counted the user traffic,
349349
// note: it was just a single request with nearly no upload but quite
350350
// some download:
351-
auth := os.Getenv("TEST_AUTHENTICATION")
352-
if auth != "super:testing" {
351+
if !strings.HasPrefix(os.Getenv("TEST_AUTHENTICATION"), "super:") {
353352
t.Logf("Checking user traffic on coordinator1...")
354353
t.Logf("statsBefore1: %v\nstatsAfter1: %v", statsBefore1.ClientUser.BytesSent, statsAfter1.ClientUser.BytesSent)
355354
checkTrafficAtLeast(t, &statsBefore1, &statsAfter1, user,

0 commit comments

Comments
 (0)