Skip to content

Commit

Permalink
use pointer instead interface & rname signature
Browse files Browse the repository at this point in the history
  • Loading branch information
maksim.konovalov committed Dec 5, 2024
1 parent 6e2c73d commit 0444763
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions box/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ type Box struct {
conn tarantool.Doer // Connection interface for interacting with Tarantool.
}

// By returns a new instance of the box structure, which implements the Box interface.
func New(conn tarantool.Doer) Box {
// New returns a new instance of the box structure, which implements the Box interface.
func New(conn tarantool.Doer) *Box {
return &Box{
conn: conn, // Assigns the provided Tarantool connection.
}
}

// Info retrieves the current information of the Tarantool instance.
// It calls the "box.info" function and parses the result into the Info structure.
func (b *box) Info() (Info, error) {
func (b *Box) Info() (Info, error) {
var infoResp InfoResponse

// Call "box.info" to get instance information from Tarantool.
Expand Down
4 changes: 2 additions & 2 deletions box/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
"github.com/tarantool/go-tarantool/v2/box"
)

func TestBy(t *testing.T) {
func TestNew(t *testing.T) {
// 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() {
// Create a box instance with a nil connection. This should lead to a panic later.
b := box.By(nil)
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.
Expand Down
2 changes: 1 addition & 1 deletion box/tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestBox_Sugar_Info(t *testing.T) {
conn, err := tarantool.Connect(ctx, dialer, tarantool.Opts{})
require.NoError(t, err)

info, err := box.By(conn).Info()
info, err := box.New(conn).Info()
require.NoError(t, err)

validateInfo(t, info)
Expand Down

0 comments on commit 0444763

Please sign in to comment.