Example #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, utils.NewHTTPRequestFactory(), endpoint, true)
	if err != nil {
		t.Fatal(err)
	}
	return r
}
Example #2
0
func HTTPRequestFactory(metaHeaders map[string][]string) *utils.HTTPRequestFactory {
	// FIXME: this replicates the 'info' job.
	httpVersion := make([]utils.VersionInfo, 0, 4)
	httpVersion = append(httpVersion, &simpleVersionInfo{"go", runtime.Version()})
	if kernelVersion, err := kernel.GetKernelVersion(); err == nil {
		httpVersion = append(httpVersion, &simpleVersionInfo{"kernel", kernelVersion.String()})
	}
	httpVersion = append(httpVersion, &simpleVersionInfo{"os", runtime.GOOS})
	httpVersion = append(httpVersion, &simpleVersionInfo{"arch", runtime.GOARCH})
	ud := utils.NewHTTPUserAgentDecorator(httpVersion...)
	md := &utils.HTTPMetaHeadersDecorator{
		Headers: metaHeaders,
	}
	factory := utils.NewHTTPRequestFactory(ud, md)
	return factory
}
Example #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, utils.NewHTTPRequestFactory(), 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")
}