Skip to content

Commit

Permalink
test: refactor e2e tests to use parallel (#133)
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Yuichi Okimoto <[email protected]>
  • Loading branch information
cre8ivejp authored Jun 13, 2024
1 parent ea8092d commit ca71f2c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 54 deletions.
6 changes: 6 additions & 0 deletions test/e2e/sdk_local_evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

func TestLocalStringVariation(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
user *user.User
Expand Down Expand Up @@ -58,6 +59,7 @@ func TestLocalStringVariation(t *testing.T) {
}

func TestLocalBoolVariation(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
user *user.User
Expand Down Expand Up @@ -98,6 +100,7 @@ func TestLocalBoolVariation(t *testing.T) {
}

func TestLocalIntVariation(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
user *user.User
Expand Down Expand Up @@ -138,6 +141,7 @@ func TestLocalIntVariation(t *testing.T) {
}

func TestLocalInt64Variation(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
user *user.User
Expand Down Expand Up @@ -178,6 +182,7 @@ func TestLocalInt64Variation(t *testing.T) {
}

func TestLocalFloat64Variation(t *testing.T) {
t.Parallel()
tests := []struct {
desc string
user *user.User
Expand Down Expand Up @@ -218,6 +223,7 @@ func TestLocalFloat64Variation(t *testing.T) {
}

func TestLocalJSONVariation(t *testing.T) {
t.Parallel()
type TestJson struct {
Str string `json:"str"`
Int string `json:"int"`
Expand Down
108 changes: 54 additions & 54 deletions test/e2e/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ func TestStringVariation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

actual := sdk.StringVariation(ctx, tt.user, tt.featureID, "default")
assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
})
Expand Down Expand Up @@ -79,17 +79,17 @@ func TestBoolVariation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

actual := sdk.BoolVariation(ctx, tt.user, tt.featureID, false)
assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
})
Expand Down Expand Up @@ -119,17 +119,17 @@ func TestIntVariation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

actual := sdk.IntVariation(ctx, tt.user, tt.featureID, -1)
assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
})
Expand Down Expand Up @@ -159,17 +159,17 @@ func TestInt64Variation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

actual := sdk.Int64Variation(ctx, tt.user, tt.featureID, -1000000000)
assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
})
Expand Down Expand Up @@ -199,17 +199,17 @@ func TestFloat64Variation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

actual := sdk.Float64Variation(ctx, tt.user, tt.featureID, -1.1)
assert.Equal(t, tt.expected, actual, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
})
Expand Down Expand Up @@ -244,17 +244,17 @@ func TestJSONVariation(t *testing.T) {
},
}

ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
sdk := newSDK(t, ctx)
defer func() {
// Close
err := sdk.Close(ctx)
assert.NoError(t, err)
}()

v := &TestJson{}
sdk.JSONVariation(ctx, tt.user, tt.featureID, v)
assert.Equal(t, tt.expected, v, "userID: %s, featureID: %s", tt.user.ID, tt.featureID)
Expand Down

0 comments on commit ca71f2c

Please sign in to comment.