-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5008 from multiversx/rc/v1.6.0
RC/v1.6.0
- Loading branch information
Showing
1,436 changed files
with
93,353 additions
and
35,759 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,17 +1,92 @@ | ||
package gin | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-go/api/errors" | ||
apiErrors "github.com/multiversx/mx-chain-go/api/errors" | ||
"github.com/multiversx/mx-chain-go/testscommon/api" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewHttpServer_NilServerShouldErr(t *testing.T) { | ||
func TestNewHttpServer(t *testing.T) { | ||
t.Parallel() | ||
|
||
hs, err := NewHttpServer(nil) | ||
require.Equal(t, errors.ErrNilHttpServer, err) | ||
require.True(t, check.IfNil(hs)) | ||
t.Run("nil server should error", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
hs, err := NewHttpServer(nil) | ||
require.Equal(t, apiErrors.ErrNilHttpServer, err) | ||
require.Nil(t, hs) | ||
}) | ||
t.Run("should work", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
hs, err := NewHttpServer(&api.ServerStub{}) | ||
require.NoError(t, err) | ||
require.NotNil(t, hs) | ||
}) | ||
} | ||
|
||
func TestHttpServer_Start(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("server starts", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
wasCalled := false | ||
serverStub := &api.ServerStub{ | ||
ListenAndServeCalled: func() error { | ||
return nil | ||
}, | ||
ShutdownCalled: func(ctx context.Context) error { | ||
wasCalled = true | ||
return nil | ||
}, | ||
} | ||
hs, _ := NewHttpServer(serverStub) | ||
require.NotNil(t, hs) | ||
|
||
hs.Start() | ||
require.NoError(t, hs.Close()) | ||
require.True(t, wasCalled) | ||
}) | ||
t.Run("server is closed", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
serverStub := &api.ServerStub{ | ||
ListenAndServeCalled: func() error { | ||
return http.ErrServerClosed | ||
}, | ||
} | ||
hs, _ := NewHttpServer(serverStub) | ||
require.NotNil(t, hs) | ||
|
||
hs.Start() | ||
}) | ||
t.Run("server returns other error", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
serverStub := &api.ServerStub{ | ||
ListenAndServeCalled: func() error { | ||
return errors.New("other error") | ||
}, | ||
} | ||
hs, _ := NewHttpServer(serverStub) | ||
require.NotNil(t, hs) | ||
|
||
hs.Start() | ||
}) | ||
} | ||
|
||
func TestHttpServer_IsInterfaceNil(t *testing.T) { | ||
t.Parallel() | ||
|
||
var hs *httpServer | ||
require.True(t, hs.IsInterfaceNil()) | ||
|
||
hs, _ = NewHttpServer(&api.ServerStub{}) | ||
require.False(t, hs.IsInterfaceNil()) | ||
} |
This file contains 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,6 +1,13 @@ | ||
package gin | ||
|
||
import "context" | ||
|
||
type resetHandler interface { | ||
Reset() | ||
IsInterfaceNil() bool | ||
} | ||
|
||
type server interface { | ||
ListenAndServe() error | ||
Shutdown(ctx context.Context) error | ||
} |
This file contains 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.