コード例 #1
0
ファイル: server_test.go プロジェクト: vsco/dcdr
func TestHTTPCaching(t *testing.T) {
	srv := mockServer()
	ts := time.Now().Unix()
	fm := models.EmptyFeatureMap()
	fm.Dcdr.Info.CurrentSHA = "current-sha"
	fm.Dcdr.Info.LastModifiedDate = ts
	srv.Client.SetFeatureMap(fm)

	resp := builder.WithMux(srv).
		Get(srv.config.Server.Endpoint).
		Header(middleware.IfNoneMatchHeader, fm.Dcdr.Info.CurrentSHA).Do()

	http_assert.Response(t, resp.Response).
		HasStatusCode(http.StatusNotModified).
		ContainsHeaderValue(middleware.EtagHeader, fm.Dcdr.CurrentSHA()).
		ContainsHeaderValue(middleware.LastModifiedHeader, time.Unix(ts, 0).Format(time.RFC1123)).
		ContainsHeaderValue(middleware.CacheControlHeader, middleware.CacheControl).
		ContainsHeaderValue(middleware.PragmaHeader, middleware.Pragma).
		ContainsHeaderValue(middleware.ExpiresHeader, middleware.Expires)

	resp = builder.WithMux(srv).
		Get(srv.config.Server.Endpoint).
		Header(middleware.IfNoneMatchHeader, "").Do()

	http_assert.Response(t, resp.Response).
		HasStatusCode(http.StatusOK).
		ContainsHeaderValue(middleware.EtagHeader, fm.Dcdr.CurrentSHA()).
		ContainsHeaderValue(middleware.CacheControlHeader, middleware.CacheControl).
		ContainsHeaderValue(middleware.PragmaHeader, middleware.Pragma).
		ContainsHeaderValue(middleware.ExpiresHeader, middleware.Expires)
}
コード例 #2
0
ファイル: client.go プロジェクト: vsco/dcdr
// ScopedMap a `FeatureMap` containing only merged features and `Info`.
func (c *Client) ScopedMap() *models.FeatureMap {
	fm := models.EmptyFeatureMap()
	fm.Dcdr.FeatureScopes = c.Features()
	fm.Dcdr.Info = c.FeatureMap().Dcdr.Info

	return fm
}
コード例 #3
0
ファイル: client.go プロジェクト: vsco/dcdr
// FeatureMap `featureMap` accessor. Returns an empty `FeatureMap`
// if the `featureMap` is nil.
func (c *Client) FeatureMap() *models.FeatureMap {
	if c.featureMap != nil {
		return c.featureMap
	}

	return models.EmptyFeatureMap()
}
コード例 #4
0
ファイル: client.go プロジェクト: vsco/dcdr
// KVsToFeatures helper for unmarshalling `KVBytes` to a `FeatureMap`
func (c *Client) KVsToFeatureMap(kvb stores.KVBytes) (*models.FeatureMap, error) {
	fm := models.EmptyFeatureMap()

	for _, v := range kvb {
		var key string
		var value interface{}

		if v.Key == config.DefaultInfoNamespace {
			var info models.Info
			err := json.Unmarshal(v.Bytes, &info)

			if err != nil {
				return fm, err
			}

			fm.Dcdr.Info = &info
		} else {
			var ft models.Feature
			err := json.Unmarshal(v.Bytes, &ft)

			if err != nil {
				printer.SayErr("%s: %s", v.Key, v.Bytes)
				return fm, err
			}

			key = strings.Replace(v.Key, fmt.Sprintf("%s/features/", c.Namespace()), "", 1)
			value = ft.Value
		}

		explode(fm.Dcdr.FeatureScopes, key, value)
	}

	return fm, nil
}
コード例 #5
0
ファイル: mock_client.go プロジェクト: vsco/dcdr
// New creates a `Client` with an empty `FeatureMap` and `Config`.
func New() (d *Client) {
	c, _ := client.New(&config.Config{
		Watcher: config.Watcher{
			OutputPath: "",
		},
	})

	d = &Client{
		Client:     *c,
		featureMap: models.EmptyFeatureMap(),
	}

	d.Client.SetFeatureMap(d.featureMap)
	return
}
コード例 #6
0
ファイル: server_test.go プロジェクト: vsco/dcdr
	"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()