-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Rewrite the tests using Ginkgo and Gomega, fix some bugs. (#147)
* test: Convert tests to Ginkgo and Gomega RSpec style testing. * fix: CredentialProvider returns InvalidArgument when the token cannot be parsed. * test: Make sure to cleanup the client and caches between all tests. * fix: Values are allowed to be blank. * chore: Remove `go vet` from the `make test` target, it's already part of `make lint`. * fix: DeleteCache() should succeed if the cache doesn't exist. * chore: Allow us to see why the CI lint checks failed.
- Loading branch information
Showing
18 changed files
with
619 additions
and
915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package auth_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestAuth(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Auth Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package auth_test | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/momentohq/client-sdk-go/auth" | ||
"github.com/momentohq/client-sdk-go/internal/momentoerrors" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("CredentialProvider", func() { | ||
It(`errors on a invalid auth token`, func() { | ||
badCredentialProvider, err := auth.NewStringMomentoTokenProvider("Invalid token") | ||
|
||
Expect(badCredentialProvider).To(BeNil()) | ||
Expect(err).NotTo(BeNil()) | ||
|
||
var momentoErr momentoerrors.MomentoSvcErr | ||
if errors.As(err, &momentoErr) { | ||
Expect(momentoErr.Code()).To(Equal(momentoerrors.InvalidArgumentError)) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package momento_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/momentohq/client-sdk-go/config" | ||
. "github.com/momentohq/client-sdk-go/momento" | ||
) | ||
|
||
var _ = Describe("Control ops", func() { | ||
var client SimpleCacheClient | ||
var ctx context.Context | ||
|
||
BeforeEach(func() { | ||
ctx = context.Background() | ||
|
||
client = getClient(&SimpleCacheClientProps{ | ||
Configuration: config.LatestLaptopConfig(), | ||
DefaultTTL: 60 * time.Second, | ||
}) | ||
|
||
DeferCleanup(func() { client.Close() }) | ||
}) | ||
|
||
Describe(`Happy Path`, func() { | ||
It(`creates, lists, and deletes caches`, func() { | ||
cacheNames := []string{uuid.NewString(), uuid.NewString()} | ||
defer func() { | ||
for _, cacheName := range cacheNames { | ||
_, err := client.DeleteCache(ctx, &DeleteCacheRequest{CacheName: cacheName}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
}() | ||
|
||
for _, cacheName := range cacheNames { | ||
Expect( | ||
client.CreateCache(ctx, &CreateCacheRequest{CacheName: cacheName}), | ||
).To(BeAssignableToTypeOf(&CreateCacheSuccess{})) | ||
|
||
Expect( | ||
client.CreateCache(ctx, &CreateCacheRequest{CacheName: cacheName}), | ||
).To(BeAssignableToTypeOf(&CreateCacheAlreadyExists{})) | ||
} | ||
|
||
resp, err := client.ListCaches(ctx, &ListCachesRequest{}) | ||
Expect(err).To(Succeed()) | ||
|
||
listedCaches := []string{} | ||
switch r := resp.(type) { | ||
case *ListCachesSuccess: | ||
for _, info := range r.Caches() { | ||
listedCaches = append(listedCaches, info.Name()) | ||
} | ||
Expect(listedCaches).To(ContainElements(cacheNames)) | ||
default: | ||
Fail("Unexpected repsonse type") | ||
} | ||
|
||
for _, cacheName := range cacheNames { | ||
Expect( | ||
client.DeleteCache(ctx, &DeleteCacheRequest{CacheName: cacheName}), | ||
).To(BeAssignableToTypeOf(&DeleteCacheSuccess{})) | ||
} | ||
resp, err = client.ListCaches(ctx, &ListCachesRequest{}) | ||
Expect(err).To(Succeed()) | ||
Expect(resp).To(BeAssignableToTypeOf(&ListCachesSuccess{})) | ||
switch r := resp.(type) { | ||
case *ListCachesSuccess: | ||
Expect(r.Caches()).To(Not(ContainElements(cacheNames))) | ||
default: | ||
Fail("Unexpected repsonse type") | ||
} | ||
}) | ||
}) | ||
|
||
Describe(`Validate cache name`, func() { | ||
It(`CreateCache and DeleteCache errors on bad cache names`, func() { | ||
badCacheNames := []string{``, ` `} | ||
for _, badCacheName := range badCacheNames { | ||
createResp, err := client.CreateCache(ctx, &CreateCacheRequest{CacheName: badCacheName}) | ||
Expect(createResp).To(BeNil()) | ||
var momentoErr MomentoError | ||
if errors.As(err, &momentoErr) { | ||
Expect(momentoErr.Code()).To(Equal(InvalidArgumentError)) | ||
} | ||
|
||
deleteResp, err := client.DeleteCache(ctx, &DeleteCacheRequest{CacheName: badCacheName}) | ||
Expect(deleteResp).To(BeNil()) | ||
if errors.As(err, &momentoErr) { | ||
Expect(momentoErr.Code()).To(Equal(InvalidArgumentError)) | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
Describe(`DeleteCache`, func() { | ||
It(`succeeds even if the cache does not exist`, func() { | ||
Expect( | ||
client.DeleteCache(ctx, &DeleteCacheRequest{CacheName: uuid.NewString()}), | ||
).To(BeAssignableToTypeOf(&DeleteCacheSuccess{})) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package momento_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestMomento(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Momento Suite") | ||
} |
Oops, something went wrong.