mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-10 23:43:03 -04:00
Add getState to protoClient
This commit is contained in:
parent
c08787ce80
commit
019003337f
4 changed files with 80 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/coordinator/pubapi/pubproto"
|
||||
"github.com/edgelesssys/constellation/coordinator/state"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
|
@ -65,6 +66,48 @@ func TestClose(t *testing.T) {
|
|||
assert.Equal(connectivity.Shutdown, conn.GetState())
|
||||
}
|
||||
|
||||
func TestGetState(t *testing.T) {
|
||||
someErr := errors.New("some error")
|
||||
|
||||
testCases := map[string]struct {
|
||||
pubAPIClient pubproto.APIClient
|
||||
wantErr bool
|
||||
wantState state.State
|
||||
}{
|
||||
"success": {
|
||||
pubAPIClient: &stubPubAPIClient{getStateState: state.IsNode},
|
||||
wantState: state.IsNode,
|
||||
},
|
||||
"getState error": {
|
||||
pubAPIClient: &stubPubAPIClient{getStateErr: someErr},
|
||||
wantErr: true,
|
||||
},
|
||||
"uninitialized": {
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
client := Client{}
|
||||
if tc.pubAPIClient != nil {
|
||||
client.pubapi = tc.pubAPIClient
|
||||
}
|
||||
|
||||
state, err := client.GetState(context.Background())
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.wantState, state)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestActivate(t *testing.T) {
|
||||
testKey := base64.StdEncoding.EncodeToString([]byte("32bytesWireGuardKeyForTheTesting"))
|
||||
someErr := errors.New("failed")
|
||||
|
@ -135,6 +178,8 @@ func TestActivate(t *testing.T) {
|
|||
}
|
||||
|
||||
type stubPubAPIClient struct {
|
||||
getStateState state.State
|
||||
getStateErr error
|
||||
activateAsCoordinatorErr error
|
||||
activateAdditionalNodesErr error
|
||||
activateAsCoordinatorReqKey []byte
|
||||
|
@ -145,6 +190,10 @@ type stubPubAPIClient struct {
|
|||
pubproto.APIClient
|
||||
}
|
||||
|
||||
func (s *stubPubAPIClient) GetState(ctx context.Context, in *pubproto.GetStateRequest, opts ...grpc.CallOption) (*pubproto.GetStateResponse, error) {
|
||||
return &pubproto.GetStateResponse{State: uint32(s.getStateState)}, s.getStateErr
|
||||
}
|
||||
|
||||
func (s *stubPubAPIClient) ActivateAsCoordinator(ctx context.Context, in *pubproto.ActivateAsCoordinatorRequest,
|
||||
opts ...grpc.CallOption,
|
||||
) (pubproto.API_ActivateAsCoordinatorClient, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue