github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/services/v0/sharestore_test.go (about) 1 package v0 2 3 import ( 4 "net/http/httptest" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/credentials" 9 "github.com/johannesboyne/gofakes3" 10 "github.com/johannesboyne/gofakes3/backend/s3mem" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestS3ShareStore(t *testing.T) { 15 backend := s3mem.New() 16 faker := gofakes3.New(backend) 17 ts := httptest.NewServer(faker.Server()) 18 defer ts.Close() 19 20 require := require.New(t) 21 22 s3Config := &aws.Config{ 23 Credentials: credentials.NewStaticCredentials("YOUR-ACCESSKEYID", "YOUR-SECRETACCESSKEY", ""), 24 Endpoint: aws.String(ts.URL), 25 Region: aws.String("eu-central-1"), 26 DisableSSL: aws.Bool(true), 27 S3ForcePathStyle: aws.Bool(true), 28 } 29 30 sharestore, err := NewS3ShareStore("foo", "bar", s3Config) 31 require.NoError(err) 32 33 err = sharestore.(*s3ShareStore).createBucketForTesting() 34 require.NoError(err) 35 36 // Check for invalid share. 37 _, _, err = sharestore.LookupSharedByReference("someref/foobar") 38 require.Error(err) 39 40 // Check for non-existent share. 41 _, status, err := sharestore.LookupSharedByReference("someref") 42 require.NoError(err) 43 require.Equal(LookupNotFound, status) 44 45 // Add a share. 46 reference, err := sharestore.StoreShared(SharedDataV2{ 47 Version: sharedDataVersion, 48 Schema: "foo", 49 }) 50 require.NoError(err) 51 52 // Lookup the share and compare. 53 sd, status, err := sharestore.LookupSharedByReference(reference) 54 require.NoError(err) 55 require.Equal(LookupSuccess, status) 56 require.Equal("foo", sd.Schema) 57 }