storj/satellite/metainfo/metabase/common_test.go
Egon Elbre d7c6ca6013 satellite/metainfo/metabase: add package for metainfo database
Currently there is confusion between responsibilities of
metainfo.Endpoint, metainfo.Service, PointerDB.

By separating database "service" into a separate package and
its types allows to disentagle them.

This gives us responsibilities:

1. metainfo.Endpoint - translates requests and permissions
2. metainfo.Service - handles requests and coordinates with
   objectdeletion, piecedeletion, metabase
3. metabase.Service - communication with the database interface and invariants

Currently metabase will contain the types necessary to coordinate
information.

Change-Id: If8c992b4b9d9e70a56bbd8a378a5af6b1a2ec34e
2020-08-27 17:31:11 +00:00

58 lines
1.5 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package metabase_test
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/uuid"
"storj.io/storj/satellite/metainfo/metabase"
)
func TestParseBucketPrefixInvalid(t *testing.T) {
var testCases = []struct {
name string
prefix metabase.BucketPrefix
}{
{"invalid, not valid UUID", "not UUID string/bucket1"},
{"invalid, not valid UUID, no bucket", "not UUID string"},
{"invalid, no project, no bucket", ""},
}
for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
_, err := metabase.ParseBucketPrefix(tt.prefix)
require.NotNil(t, err)
require.Error(t, err)
})
}
}
func TestParseBucketPrefixValid(t *testing.T) {
var testCases = []struct {
name string
project string
bucketName string
expectedBucketName string
}{
{"valid, no bucket, no objects", "bb6218e3-4b4a-4819-abbb-fa68538e33c0", "", ""},
{"valid, with bucket", "bb6218e3-4b4a-4819-abbb-fa68538e33c0", "testbucket", "testbucket"},
}
for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
expectedProjectID, err := uuid.FromString(tt.project)
require.NoError(t, err)
bucketID := expectedProjectID.String() + "/" + tt.bucketName
bucketLocation, err := metabase.ParseBucketPrefix(metabase.BucketPrefix(bucketID))
require.NoError(t, err)
require.Equal(t, expectedProjectID, bucketLocation.ProjectID)
require.Equal(t, tt.expectedBucketName, bucketLocation.BucketName)
})
}
}