2018-05-08 21:57:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2018-05-08 21:57:29 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2018-06-12 16:50:25 +00:00
|
|
|
// nolint: deadcode
|
2018-05-08 21:57:29 +00:00
|
|
|
func TestStatusFlag(t *testing.T) {
|
|
|
|
service := "status"
|
|
|
|
|
|
|
|
scenarios := []struct {
|
|
|
|
ipcEnabled bool
|
|
|
|
httpEnabled bool
|
|
|
|
flag string
|
|
|
|
err error
|
|
|
|
enabled bool
|
|
|
|
public bool
|
|
|
|
}{
|
|
|
|
// no flags
|
|
|
|
{},
|
|
|
|
// -status=ipc -ipc
|
|
|
|
{
|
|
|
|
ipcEnabled: true,
|
|
|
|
flag: "ipc",
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
// -status=http -http
|
|
|
|
{
|
|
|
|
httpEnabled: true,
|
|
|
|
flag: "http",
|
|
|
|
enabled: true,
|
|
|
|
public: true,
|
|
|
|
},
|
|
|
|
// -status=ipc -http -ipc
|
|
|
|
{
|
|
|
|
httpEnabled: true,
|
|
|
|
ipcEnabled: true,
|
|
|
|
flag: "ipc",
|
|
|
|
enabled: true,
|
|
|
|
},
|
|
|
|
// -http -ipc
|
|
|
|
{
|
|
|
|
httpEnabled: true,
|
|
|
|
ipcEnabled: true,
|
|
|
|
flag: "",
|
|
|
|
},
|
|
|
|
// -status=ipc
|
|
|
|
{
|
|
|
|
err: errStatusServiceRequiresIPC,
|
|
|
|
flag: "ipc",
|
|
|
|
},
|
|
|
|
// -status=http
|
|
|
|
{
|
|
|
|
err: errStatusServiceRequiresHTTP,
|
|
|
|
flag: "http",
|
|
|
|
},
|
|
|
|
// -status=bad-value
|
|
|
|
{
|
|
|
|
err: errStatusServiceInvalidFlag,
|
|
|
|
flag: "bad-value",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, s := range scenarios {
|
|
|
|
msg := fmt.Sprintf("scenario %d", i)
|
|
|
|
|
2018-09-21 14:09:31 +00:00
|
|
|
c, err := params.NewNodeConfig("", 0)
|
2018-05-08 21:57:29 +00:00
|
|
|
require.Nil(t, err, msg)
|
|
|
|
|
|
|
|
c.IPCEnabled = s.ipcEnabled
|
2018-09-21 14:09:31 +00:00
|
|
|
c.HTTPEnabled = s.httpEnabled
|
2018-05-08 21:57:29 +00:00
|
|
|
|
|
|
|
c, err = configureStatusService(s.flag, c)
|
|
|
|
|
|
|
|
if s.err != nil {
|
|
|
|
require.Equal(t, s.err, err, msg)
|
|
|
|
require.Nil(t, c, msg)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Nil(t, err, msg)
|
|
|
|
require.Equal(t, s.enabled, c.StatusServiceEnabled, msg)
|
|
|
|
|
|
|
|
modules := c.FormatAPIModules()
|
|
|
|
if s.public {
|
|
|
|
require.Contains(t, modules, service, msg)
|
|
|
|
} else {
|
|
|
|
require.NotContains(t, modules, service, msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|