-
Notifications
You must be signed in to change notification settings - Fork 0
api: namer implementation #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/tarantool/go-storage/crypto" | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
| package namer | ||
|
|
||
| import ( | ||
| "fmt" | ||
| ) | ||
|
|
||
| // InvalidKeyError represents an error for invalid key format. | ||
| type InvalidKeyError struct { | ||
| Key string | ||
| Problem string | ||
| } | ||
|
|
||
| func (e InvalidKeyError) Error() string { | ||
| return fmt.Sprintf("invalid key '%s': %s", e.Key, e.Problem) | ||
| } | ||
|
|
||
| func errInvalidKey(key string, problem string) error { | ||
| return InvalidKeyError{ | ||
| Key: key, | ||
| Problem: problem, | ||
| } | ||
| } | ||
|
|
||
| // InvalidNameError represents an error for invalid name format. | ||
| type InvalidNameError struct { | ||
| Name string | ||
| Problem string | ||
| } | ||
|
|
||
| func (e InvalidNameError) Error() string { | ||
| return fmt.Sprintf("invalid name '%s': %s", e.Name, e.Problem) | ||
| } | ||
|
|
||
| func errInvalidName(name string, problem string) error { | ||
| return InvalidNameError{ | ||
| Name: name, | ||
| Problem: problem, | ||
| } | ||
| } |
This file contains hidden or 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,23 @@ | ||
| package namer_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/tarantool/go-storage/namer" | ||
| ) | ||
|
|
||
| func TestInvalidNameError_Error(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := namer.InvalidNameError{Name: "name", Problem: "problem"} | ||
| assert.Equal(t, "invalid name 'name': problem", err.Error()) | ||
| } | ||
|
|
||
| func TestInvalidKeyError_Error(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := namer.InvalidKeyError{Key: "name", Problem: "problem"} | ||
| assert.Equal(t, "invalid key 'name': problem", err.Error()) | ||
| } |
This file contains hidden or 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,59 @@ | ||
| package namer | ||
|
|
||
| // KeyType represents key types. | ||
| type KeyType int | ||
|
|
||
| const ( | ||
| // KeyTypeValue represents data type. | ||
| KeyTypeValue KeyType = iota + 1 | ||
| // KeyTypeHash represents hash of the data type. | ||
| KeyTypeHash | ||
| // KeyTypeSignature represents signature of the data type. | ||
| KeyTypeSignature | ||
| ) | ||
|
|
||
| // Key defines the minimal interface required by keys. | ||
| type Key interface { | ||
| Name() string // Get object name. | ||
| Type() KeyType // Get key type. | ||
| Property() string // Get metadata (e.g., algorithm version). | ||
| Build() string // Reconstruct raw key string. | ||
| } | ||
|
|
||
| // DefaultKey implements default realization. | ||
| type DefaultKey struct { | ||
| name string // Object identifier. | ||
| keyType KeyType // Type of object (hash/signature/value). | ||
| property string // Additional metadata (version/algorithm). | ||
| raw string // Raw key string. | ||
| } | ||
|
|
||
| // NewDefaultKey returns new Key object. | ||
| func NewDefaultKey(name string, keytype KeyType, property string, raw string) DefaultKey { | ||
oleg-jukovec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return DefaultKey{ | ||
| name: name, | ||
| keyType: keytype, | ||
| property: property, | ||
| raw: raw, | ||
| } | ||
| } | ||
|
|
||
| // Name returns name of the key. | ||
| func (k DefaultKey) Name() string { | ||
| return k.name | ||
| } | ||
|
|
||
| // Type returns type of the key. | ||
| func (k DefaultKey) Type() KeyType { | ||
| return k.keyType | ||
| } | ||
|
|
||
| // Property returns property of the key. | ||
| func (k DefaultKey) Property() string { | ||
| return k.property | ||
| } | ||
|
|
||
| // Build reconstructs key string. | ||
| func (k DefaultKey) Build() string { | ||
| return k.raw | ||
| } | ||
This file contains hidden or 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,52 @@ | ||
| package namer_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/tarantool/go-storage/namer" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultName = "all" | ||
| defaultType = namer.KeyTypeHash | ||
| defaultProperty = "sha256" | ||
| defaultRaw = "/config/hash/sha256/all" | ||
| ) | ||
|
|
||
| func TestNewDefaultKey(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw) | ||
| require.NotEmpty(t, a) | ||
| } | ||
|
|
||
| func TestDefaultKey_Build(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw) | ||
| require.Equal(t, defaultRaw, a.Build()) | ||
| } | ||
|
|
||
| func TestDefaultKey_Name(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw) | ||
| assert.Equal(t, defaultName, a.Name()) | ||
| } | ||
|
|
||
| func TestDefaultKey_Type(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw) | ||
| assert.Equal(t, defaultType, a.Type()) | ||
| } | ||
|
|
||
| func TestDefaultKey_Property(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| a := namer.NewDefaultKey(defaultName, defaultType, defaultProperty, defaultRaw) | ||
| assert.Equal(t, defaultProperty, a.Property()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.