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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,88 @@ | ||
package box_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"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) { | ||
// Create a box instance with a nil connection. This should lead to a panic later. | ||
b := box.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. | ||
require.NotNil(t, b) | ||
|
||
// We expect a panic because we are passing a nil connection (nil Doer) to the By function. | ||
// The library does not control this zone, and the nil connection would cause a runtime error | ||
// when we attempt to call methods (like Info) on it. | ||
// This test ensures that such an invalid state is correctly handled by causing a panic, | ||
// as it's outside the library's responsibility. | ||
require.Panics(t, func() { | ||
|
||
// Calling Info on a box with a nil connection will result in a panic, since the underlying | ||
// connection (Doer) cannot perform the requested action (it's nil). | ||
_, _ = b.Info() | ||
}) | ||
t.Parallel() | ||
|
||
// Create a box instance with a nil connection. This should lead to a panic. | ||
require.Panics(t, func() { box.New(nil) }) | ||
} | ||
|
||
func TestMocked_BoxInfo(t *testing.T) { | ||
t.Parallel() | ||
|
||
data := []interface{}{ | ||
map[string]interface{}{ | ||
"version": "1.0.0", | ||
"id": nil, | ||
"ro": false, | ||
"uuid": "uuid", | ||
"pid": 456, | ||
"status": "status", | ||
"lsn": 123, | ||
"replication": nil, | ||
}, | ||
} | ||
mock := test_helpers.NewMockDoer(t, | ||
test_helpers.NewMockResponse(t, data), | ||
) | ||
b := box.New(&mock) | ||
|
||
info, err := b.Info() | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, "1.0.0", info.Version) | ||
assert.Equal(t, 456, info.PID) | ||
} | ||
|
||
func TestMocked_BoxSchemaUserInfo(t *testing.T) { | ||
t.Parallel() | ||
|
||
data := []interface{}{ | ||
[]interface{}{ | ||
[]interface{}{"read,write,execute", "universe", ""}, | ||
}, | ||
} | ||
mock := test_helpers.NewMockDoer(t, | ||
test_helpers.NewMockResponse(t, data), | ||
) | ||
b := box.New(&mock) | ||
|
||
privs, err := b.Schema().User().Info(context.Background(), "username") | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, []box.Privilege{ | ||
{ | ||
Permissions: []box.Permission{ | ||
box.PermissionRead, | ||
box.PermissionWrite, | ||
box.PermissionExecute, | ||
}, | ||
Type: box.PrivilegeUniverse, | ||
Name: "", | ||
}, | ||
}, privs) | ||
} | ||
|
||
func TestMocked_BoxSessionSu(t *testing.T) { | ||
t.Parallel() | ||
|
||
mock := test_helpers.NewMockDoer(t, | ||
test_helpers.NewMockResponse(t, []interface{}{}), | ||
errors.New("user not found or supplied credentials are invalid"), | ||
) | ||
b := box.New(&mock) | ||
|
||
err := b.Session().Su(context.Background(), "admin") | ||
require.NoError(t, err) | ||
} |
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
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.