示例#1
0
// TestDoubleFault checks that, if there is an error serializing a JSON
// response, it doesn't actually panic the process.
func TestDoubleFault(t *testing.T) {
	backend := memory.New()
	namespace, err := backend.Namespace("")
	if !assert.NoError(t, err) {
		return
	}
	_, err = namespace.SetWorkSpec(map[string]interface{}{
		"name": "spec",
	})
	if !assert.NoError(t, err) {
		return
	}

	router := NewRouter(backend)
	req := &http.Request{
		Method: http.MethodGet,
		URL: &url.URL{
			Path: "/namespace/-/work_spec/spec",
		},
		Proto:      "HTTP/1.1",
		ProtoMajor: 1,
		ProtoMinor: 1,
		Header:     http.Header{},
		Close:      true,
		Host:       "localhost",
	}
	resp := &failResponseWriter{}
	router.ServeHTTP(resp, req)
	assert.Equal(t, http.StatusOK, resp.StatusCode)
}
示例#2
0
func NewCacheAssertions(t assert.TestingT) *CacheAssertions {
	backend := memory.New()
	return &CacheAssertions{
		assert.New(t),
		backend,
		cache.New(backend),
	}
}
示例#3
0
// Coordinate creates a new coordinate interface.  This generally should be
// only called once.  If the backend has in-process state, such as a
// database connection pool or an in-memory story, calling this multiple
// times will create multiple copies of that state.  In particular, if
// b.Implementation is "memory", multiple calls to this will create
// multiple independent coordinate "worlds".
//
// If b.Implementation does not match a known implementation, returns
// an error.  It is assumed that Set() will validate at least the
// implementation.  The choice of implementation can also produce
// errors (invalid connection string, etc.)
func (b *Backend) Coordinate() (coordinate.Coordinate, error) {
	switch b.Implementation {
	case "http", "https":
		return restclient.New(b.String())
	case "memory":
		return memory.New(), nil
	case "postgres":
		return postgres.New(b.Address)
	default:
		return nil, errors.New("unknown coordinate backend " + b.Implementation)
	}
}