Esempio n. 1
0
func TestConsulDelete(t *testing.T) {
	mc := NewMockConsul("n", MockKVBytes, nil)
	cs := New(config.TestConfig(), mc)

	err := cs.Delete("n")

	assert.NoError(t, err)
}
Esempio n. 2
0
func TestConsulPut(t *testing.T) {
	mc := NewMockConsul("n", MockKVBytes, nil)
	cs := New(config.TestConfig(), mc)

	err := cs.Set("n", MockBytes)

	assert.NoError(t, err)
}
Esempio n. 3
0
func TestConsulList(t *testing.T) {
	mc := NewMockConsul("n", MockKVBytes, nil)
	cs := New(config.TestConfig(), mc)

	bts, err := cs.List("n")

	assert.NoError(t, err)
	assert.Equal(t, MockKVBytes, bts)
}
Esempio n. 4
0
func TestSet(t *testing.T) {
	r := &client.Response{}
	e := &Store{
		kv: &MockAPI{
			Response: r,
		},
		config: config.TestConfig(),
	}

	err := e.Set("k", []byte("v"))
	assert.NoError(t, err)
}
Esempio n. 5
0
func TestFetchKeys(t *testing.T) {
	r := &Store{
		cfg: config.TestConfig(),
		conn: &MockRedis{
			Response: []interface{}{[]byte("k")},
		},
	}

	bts, err := r.fetchKeys("k")

	assert.NoError(t, err)
	assert.Equal(t, []byte("k"), bts[0])
}
Esempio n. 6
0
func TestGetNilError(t *testing.T) {
	r := &Store{
		cfg: config.TestConfig(),
		conn: &MockRedis{
			Error: errors.New("nil returned"),
		},
	}

	kv, err := r.Get("foo")

	assert.Nil(t, kv)
	assert.NoError(t, err)
}
Esempio n. 7
0
func TestGet(t *testing.T) {
	r := &Store{
		cfg: config.TestConfig(),
		conn: &MockRedis{
			Response: "abcde",
		},
	}

	kv, err := r.Get("foo")

	assert.NoError(t, err)
	assert.Equal(t, "foo", kv.Key)
	assert.Equal(t, []byte("abcde"), kv.Bytes)
}
Esempio n. 8
0
func TestList(t *testing.T) {
	r := &client.Response{
		Node: &client.Node{
			Key:   "k",
			Value: "v",
		},
	}
	e := &Store{
		kv: &MockAPI{
			Response: r,
		},
		config: config.TestConfig(),
	}

	kv, err := e.List("k")
	assert.NoError(t, err)
	assert.Equal(t, "k", kv[0].Key)
	assert.Equal(t, []byte("v"), kv[0].Bytes)
}
Esempio n. 9
0
func TestUpdated(t *testing.T) {
	s := New(config.TestConfig())

	s.Register(func(kvb stores.KVBytes) {
		assert.Equal(t, 1, len(kvb))

		var f models.Feature
		err := json.Unmarshal(kvb[0].Bytes, &f)

		assert.NoError(t, err)
		assert.Equal(t, "test", f.Key)
		assert.Equal(t, "dcdr", f.Namespace)
		assert.Equal(t, "default", f.Scope)
		assert.Equal(t, false, f.Value.(bool))
		assert.Equal(t, "dcdr/features/default/test", kvb[0].Key)
	})

	var resp client.Response
	err := json.Unmarshal(jsonBytes, &resp)
	assert.NoError(t, err)
	s.Updated(resp.Node)
}
Esempio n. 10
0
func TestUpdated(t *testing.T) {
	mc := NewMockConsul("n", MockKVBytes, nil)
	cs := New(config.TestConfig(), mc)
	cs.Register(func(kvb stores.KVBytes) {
		assert.Equal(t, 1, len(kvb))

		var f models.Feature
		err := json.Unmarshal(kvb[0].Bytes, &f)

		assert.NoError(t, err)
		assert.Equal(t, "b", f.Key)
		assert.Equal(t, "dcdr/features", f.Namespace)
		assert.Equal(t, "cc", f.Scope)
		assert.Equal(t, 1.0, f.Value.(float64))
		assert.Equal(t, "dcdr/features/cc/b", kvb[0].Key)
	})

	var kvp api.KVPairs
	err := json.Unmarshal(jsonBytes, &kvp)
	assert.NoError(t, err)
	cs.Updated(kvp)
}
Esempio n. 11
0
	"bytes"

	"time"

	"github.com/stretchr/testify/assert"
	"github.com/vsco/dcdr/client"
	"github.com/vsco/dcdr/config"
	"github.com/vsco/dcdr/models"
	"github.com/vsco/dcdr/server/handlers"
	"github.com/vsco/dcdr/server/middleware"
	http_assert "github.com/vsco/http-test/assert"
	"github.com/vsco/http-test/builder"
)

var fm = models.EmptyFeatureMap()
var cfg = config.TestConfig()
var cl, _ = client.New(cfg)

func mockServer() *Server {
	cl.SetFeatureMap(fm)
	return New(cfg, cl)
}

func TestGetFeatures(t *testing.T) {
	srv := mockServer()
	resp := builder.WithMux(srv).Get(srv.config.Server.Endpoint).Do()
	http_assert.Response(t, resp.Response).
		IsOK().
		IsJSON()

	var m models.FeatureMap