Skip to content

Commit 8ecea2d

Browse files
author
Aya Lubbad
committed
added test suite for v2 api keys
1 parent 4bb45cd commit 8ecea2d

File tree

8 files changed

+1181
-9
lines changed

8 files changed

+1181
-9
lines changed

.github/workflows/on-pull-request.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ jobs:
8787
contents: read
8888
pull-requests: read
8989
env:
90-
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
90+
MOMENTO_API_KEY: ${{ secrets.ALPHA_API_KEYS_V2 }}
91+
MOMENTO_ENDPOINT: "cell-alpha-dev.preprod.a.momentohq.com"
92+
V1_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
9193
steps:
9294
- name: Setup repo
9395
uses: actions/checkout@v3

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
func main() {
5353
context := context.Background()
5454
configuration := config.LaptopLatestWithLogger(logger.NewNoopMomentoLoggerFactory()).WithClientTimeout(15 * time.Second)
55-
credentialProvider, err := auth.NewEnvMomentoV2TokenProvider()
55+
credentialProvider, err := auth.NewEnvMomentoTokenProvider("MOMENTO_API_KEY")
5656
if err != nil {
5757
panic(err)
5858
}

batchutils/batch_operations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var _ = Describe("batch-utils", Label("cache-service"), func() {
2828
BeforeEach(func() {
2929
ctx = context.Background()
3030
cacheName = fmt.Sprintf("golang-%s", uuid.NewString())
31-
credentialProvider, err := auth.FromEnvironmentVariablesV2()
31+
credentialProvider, err := auth.FromEnvironmentVariable("V1_API_KEY")
3232
if err != nil {
3333
panic(err)
3434
}

batchutils/batch_set_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var _ = Describe("batch-utils", Label("cache-service"), func() {
2727
BeforeEach(func() {
2828
ctx = context.Background()
2929
cacheName = fmt.Sprintf("golang-%s", uuid.NewString())
30-
credentialProvider, err := auth.FromEnvironmentVariablesV2()
30+
credentialProvider, err := auth.FromEnvironmentVariable("V1_API_KEY")
3131
if err != nil {
3232
panic(err)
3333
}

config/middleware/impl/compression_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func cleanup() {
3434

3535
// Each test may use a different compression middleware in the config
3636
func createCacheClient(config config.Configuration) {
37-
credentialProvider, err := auth.FromEnvironmentVariablesV2()
37+
credentialProvider, err := auth.FromEnvironmentVariable("V1_API_KEY")
3838
Expect(err).To(BeNil())
3939

4040
cacheClient, err = NewCacheClient(

momento/momento_suite_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var CACHE_SERVICE_LABEL = "cache-service"
1919
var LEADERBOARD_SERVICE_LABEL = "leaderboard-service"
2020
var TOPICS_SERVICE_LABEL = "topics-service"
2121
var MOMENTO_LOCAL_LABEL = "momento-local"
22+
var V2_API_LABEL = "v2-api-key"
2223
var RETRY_LABEL = "retry"
2324

2425
func TestMomento(t *testing.T) {
@@ -28,7 +29,7 @@ func TestMomento(t *testing.T) {
2829

2930
var _ = BeforeSuite(func() {
3031
sharedContext = helpers.NewSharedContext(
31-
helpers.SharedContextProps{IsMomentoLocal: includesMomentoLocalTests()})
32+
helpers.SharedContextProps{IsMomentoLocal: includesMomentoLocalTests(), IsV2ApiKey: includesV2ApiKeyTests()})
3233
sharedContext.CreateDefaultCaches()
3334
})
3435

@@ -51,6 +52,16 @@ func includesMomentoLocalTests() bool {
5152
}
5253
return true
5354
}
55+
func includesV2ApiKeyTests() bool {
56+
labelFilter := GinkgoLabelFilter()
57+
r := regexp.MustCompile(`(!?)` + V2_API_LABEL)
58+
matches := r.FindStringSubmatch(labelFilter)
59+
if len(matches) == 0 || (len(matches) == 2 && matches[1] == "!") {
60+
// the momento local label is not present, or it is present but is negated
61+
return false
62+
}
63+
return true
64+
}
5465

5566
func HaveMomentoErrorCode(code string) types.GomegaMatcher {
5667
return WithTransform(

momento/test_helpers/shared_context.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type SharedContext struct {
5050

5151
type SharedContextProps struct {
5252
IsMomentoLocal bool
53+
IsV2ApiKey bool
5354
}
5455

5556
func NewSharedContext(props SharedContextProps) SharedContext {
@@ -74,9 +75,16 @@ func NewSharedContext(props SharedContextProps) SharedContext {
7475
panic(err)
7576
}
7677
} else {
77-
credentialProvider, err = auth.NewEnvMomentoV2TokenProvider()
78-
if err != nil {
79-
panic(err)
78+
if props.IsV2ApiKey {
79+
credentialProvider, err = auth.NewEnvMomentoV2TokenProvider()
80+
if err != nil {
81+
panic(err)
82+
}
83+
} else {
84+
credentialProvider, err = auth.NewEnvMomentoTokenProvider("V1_API_KEY")
85+
if err != nil {
86+
panic(err)
87+
}
8088
}
8189
}
8290
shared.CredentialProvider = credentialProvider

0 commit comments

Comments
 (0)