forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
box: added logic for working with Tarantool schema #446
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
Open
bigbes
wants to merge
1
commit into
master
Choose a base branch
from
bigbes/TNTP-3331-box-schema-wrappers
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
package box_test | ||
package box | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/tarantool/go-tarantool/v2/box" | ||
|
||
"github.com/tarantool/go-tarantool/v2/test_helpers" | ||
) | ||
|
||
func TestNew(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create a box instance with a nil connection. This should lead to a panic later. | ||
b := box.New(nil) | ||
b := New(nil) | ||
|
||
// Ensure the box instance is not nil (which it shouldn't be), but this is not meaningful | ||
// since we will panic when we call the Info method with the nil connection. | ||
|
@@ -27,3 +31,19 @@ func TestNew(t *testing.T) { | |
_, _ = b.Info() | ||
}) | ||
} | ||
|
||
func TestNew_Schema_PassesDoer(t *testing.T) { | ||
t.Parallel() | ||
|
||
doer := test_helpers.NewMockDoer(t) | ||
|
||
b := New(&doer) | ||
schemaObject := b.Schema() | ||
assert.Equal(t, &doer, schemaObject.conn) | ||
|
||
userSchemaObject := b.Schema().User() | ||
assert.Equal(t, &doer, userSchemaObject.conn) | ||
|
||
sessionObject := b.Session() | ||
assert.Equal(t, &doer, sessionObject.conn) | ||
} | ||
Comment on lines
+40
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could create a mock of the Doer interface here and make sure that the methods are called exactly from the mock instead of sharing the internal implementation. Or something like that... |
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
package box | ||
|
||
import "github.com/tarantool/go-tarantool/v2" | ||
|
||
// Schema represents the schema-related operations in Tarantool. | ||
// It holds a connection to interact with the Tarantool instance. | ||
type Schema struct { | ||
conn tarantool.Doer // Connection interface for interacting with Tarantool. | ||
} | ||
|
||
// NewSchema creates a new Schema instance with the provided Tarantool connection. | ||
// It initializes a Schema object that can be used for schema-related operations | ||
// such as managing users, tables, and other schema elements in the Tarantool instance. | ||
func NewSchema(conn tarantool.Doer) *Schema { | ||
return &Schema{conn: conn} // Pass the connection to the Schema. | ||
} | ||
|
||
// User returns a new SchemaUser instance, allowing schema-related user operations. | ||
func (s *Schema) User() *SchemaUser { | ||
return NewSchemaUser(s.conn) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: please, test only the public API unless otherwise really necessary.
I know that the connector is currently testing by private API in some cases. It would be nice if we could fix that in the future.
But for now, we could just to avoid the wrong way and test only the public API.