summaryrefslogtreecommitdiff
path: root/plugins/broadcast/websockets/config_test.go
blob: e646fdc4d3ddbb1be4089dff808695912a75e1e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package websockets

import (
	"encoding/json"
	"testing"

	"github.com/spiral/roadrunner/service"
	"github.com/stretchr/testify/assert"
)

type mockCfg struct{ cfg string }

func (cfg *mockCfg) Get(name string) service.Config {
	if name == "same" || name == "jobs" {
		return cfg
	}

	return nil
}
func (cfg *mockCfg) Unmarshal(out interface{}) error { return json.Unmarshal([]byte(cfg.cfg), out) }

func Test_Config_Hydrate_Error(t *testing.T) {
	cfg := &mockCfg{cfg: `{"dead`}
	c := &Config{}

	assert.Error(t, c.Hydrate(cfg))
}

func Test_Config_Hydrate_OK(t *testing.T) {
	cfg := &mockCfg{cfg: `{"path":"/path"}`}
	c := &Config{}

	assert.NoError(t, c.Hydrate(cfg))
}