forked from TrueCloudLab/distribution
Path prefix support for running registry somewhere other than root of server
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
parent
00ce453315
commit
871cf9dd01
7 changed files with 161 additions and 9 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/distribution/configuration"
|
||||
|
@ -57,6 +58,40 @@ func TestCheckAPI(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestURLPrefix(t *testing.T) {
|
||||
config := configuration.Configuration{
|
||||
Storage: configuration.Storage{
|
||||
"inmemory": configuration.Parameters{},
|
||||
},
|
||||
}
|
||||
config.HTTP.Prefix = "/test/"
|
||||
|
||||
env := newTestEnvWithConfig(t, &config)
|
||||
|
||||
baseURL, err := env.builder.BuildBaseURL()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error building base url: %v", err)
|
||||
}
|
||||
|
||||
parsed, _ := url.Parse(baseURL)
|
||||
if !strings.HasPrefix(parsed.Path, config.HTTP.Prefix) {
|
||||
t.Fatalf("Prefix %v not included in test url %v", config.HTTP.Prefix, baseURL)
|
||||
}
|
||||
|
||||
resp, err := http.Get(baseURL)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error issuing request: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
checkResponse(t, "issuing api base check", resp, http.StatusOK)
|
||||
checkHeaders(t, resp, http.Header{
|
||||
"Content-Type": []string{"application/json; charset=utf-8"},
|
||||
"Content-Length": []string{"2"},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// TestLayerAPI conducts a full of the of the layer api.
|
||||
func TestLayerAPI(t *testing.T) {
|
||||
// TODO(stevvooe): This test code is complete junk but it should cover the
|
||||
|
@ -356,16 +391,21 @@ type testEnv struct {
|
|||
}
|
||||
|
||||
func newTestEnv(t *testing.T) *testEnv {
|
||||
ctx := context.Background()
|
||||
config := configuration.Configuration{
|
||||
Storage: configuration.Storage{
|
||||
"inmemory": configuration.Parameters{},
|
||||
},
|
||||
}
|
||||
|
||||
app := NewApp(ctx, config)
|
||||
return newTestEnvWithConfig(t, &config)
|
||||
}
|
||||
|
||||
func newTestEnvWithConfig(t *testing.T, config *configuration.Configuration) *testEnv {
|
||||
ctx := context.Background()
|
||||
|
||||
app := NewApp(ctx, *config)
|
||||
server := httptest.NewServer(handlers.CombinedLoggingHandler(os.Stderr, app))
|
||||
builder, err := v2.NewURLBuilderFromString(server.URL)
|
||||
builder, err := v2.NewURLBuilderFromString(server.URL + config.HTTP.Prefix)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("error creating url builder: %v", err)
|
||||
|
@ -379,7 +419,7 @@ func newTestEnv(t *testing.T) *testEnv {
|
|||
return &testEnv{
|
||||
pk: pk,
|
||||
ctx: ctx,
|
||||
config: config,
|
||||
config: *config,
|
||||
app: app,
|
||||
server: server,
|
||||
builder: builder,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue