コード例 #1
0
ファイル: registry_test.go プロジェクト: devick/flynn
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
}
コード例 #2
0
ファイル: httpfactory.go プロジェクト: technosophos/flynn
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
}
コード例 #3
0
ファイル: registry_test.go プロジェクト: devick/flynn
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")
}