예제 #1
0
func spawnTestRegistrySession(t *testing.T) *Session {
	authConfig := &AuthConfig{}
	endpoint, err := NewEndpoint(makeIndex("/v1/"))
	if err != nil {
		t.Fatal(err)
	}
	r, err := NewSession(authConfig, requestdecorator.NewRequestFactory(), endpoint, true)
	if err != nil {
		t.Fatal(err)
	}
	return r
}
예제 #2
0
func HTTPRequestFactory(metaHeaders map[string][]string) *requestdecorator.RequestFactory {
	// FIXME: this replicates the 'info' job.
	httpVersion := make([]requestdecorator.UAVersionInfo, 0, 4)
	httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("docker", dockerversion.VERSION))
	httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("go", runtime.Version()))
	httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("git-commit", dockerversion.GITCOMMIT))
	if kernelVersion, err := kernel.GetKernelVersion(); err == nil {
		httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("kernel", kernelVersion.String()))
	}
	httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("os", runtime.GOOS))
	httpVersion = append(httpVersion, requestdecorator.NewUAVersionInfo("arch", runtime.GOARCH))
	uad := &requestdecorator.UserAgentDecorator{
		Versions: httpVersion,
	}
	mhd := &requestdecorator.MetaHeadersDecorator{
		Headers: metaHeaders,
	}
	factory := requestdecorator.NewRequestFactory(uad, mhd)
	return factory
}
예제 #3
0
func TestPublicSession(t *testing.T) {
	authConfig := &AuthConfig{}

	getSessionDecorators := func(index *IndexInfo) int {
		endpoint, err := NewEndpoint(index)
		if err != nil {
			t.Fatal(err)
		}
		r, err := NewSession(authConfig, requestdecorator.NewRequestFactory(), endpoint, true)
		if err != nil {
			t.Fatal(err)
		}
		return len(r.reqFactory.GetDecorators())
	}

	decorators := getSessionDecorators(makeIndex("/v1/"))
	assertEqual(t, decorators, 0, "Expected no decorator on http session")

	decorators = getSessionDecorators(makeHttpsIndex("/v1/"))
	assertNotEqual(t, decorators, 0, "Expected decorator on https session")

	decorators = getSessionDecorators(makePublicIndex())
	assertEqual(t, decorators, 0, "Expected no decorator on public session")
}