frostfs-node/pkg/services/control/ir/service_test.go
Leonard Lyubich 93803b1a90 [#414] ir: Define Control service
Define `ControlService` for IR similar to the one from storage node. Add
`HealthStatus` RPC which returns health status of the IR application.
Implement getters, setters and methods to sign/verify the messages.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-06-15 15:21:52 +03:00

47 lines
1.2 KiB
Go

package control_test
import (
"testing"
control "github.com/nspcc-dev/neofs-node/pkg/services/control/ir"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
type protoMessage interface {
StableMarshal([]byte) ([]byte, error)
proto.Message
}
func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) {
data, err := m1.StableMarshal(nil)
require.NoError(t, err)
require.NoError(t, proto.Unmarshal(data, m2))
require.True(t, cmp(m1, m2))
}
func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) {
testStableMarshal(t,
generateHealthCheckResponseBody(),
new(control.HealthCheckResponse_Body),
func(m1, m2 protoMessage) bool {
return equalHealthCheckResponseBodies(
m1.(*control.HealthCheckResponse_Body),
m2.(*control.HealthCheckResponse_Body),
)
},
)
}
func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body {
body := new(control.HealthCheckResponse_Body)
body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN)
return body
}
func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool {
return b1.GetHealthStatus() == b2.GetHealthStatus()
}