本文整理汇总了Golang中github.com/coreos/rkt/pkg/aci.NewDetachedSignature函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDetachedSignature函数的具体用法?Golang NewDetachedSignature怎么用?Golang NewDetachedSignature使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewDetachedSignature函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestFetchImageCache
func TestFetchImageCache(t *testing.T) {
dir, err := ioutil.TempDir("", "fetch-image-cache")
if err != nil {
t.Fatalf("error creating tempdir: %v", err)
}
defer os.RemoveAll(dir)
s, err := imagestore.NewStore(dir)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
defer s.Dump(false)
ks, ksPath, err := keystore.NewTestKeystore()
if err != nil {
t.Errorf("unexpected error %v", err)
}
defer os.RemoveAll(ksPath)
key := keystoretest.KeyMap["example.com/app"]
if _, err := ks.StoreTrustedKeyPrefix("example.com/app", bytes.NewBufferString(key.ArmoredPublicKey)); err != nil {
t.Fatalf("unexpected error %v", err)
}
a, err := aci.NewBasicACI(dir, "example.com/app")
defer a.Close()
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
asc, err := aci.NewDetachedSignature(key.ArmoredPrivateKey, a)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
aciBody, err := ioutil.ReadAll(a)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
ascBody, err := ioutil.ReadAll(asc)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
nocacheServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "",
maxAge: 0,
t: t,
}
etagServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "123456789",
maxAge: 0,
t: t,
}
maxAgeServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "",
maxAge: 10,
t: t,
}
etagMaxAgeServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "123456789",
maxAge: 10,
t: t,
}
nocacheTS := httptest.NewServer(nocacheServer)
defer nocacheTS.Close()
etagTS := httptest.NewServer(etagServer)
defer etagTS.Close()
maxAgeTS := httptest.NewServer(maxAgeServer)
defer maxAgeTS.Close()
etagMaxAgeTS := httptest.NewServer(etagMaxAgeServer)
defer etagMaxAgeTS.Close()
type testData struct {
URL string
etag string
cacheMaxAge int
shouldUseCached bool
}
tests := []testData{
{nocacheTS.URL, "", 0, false},
{etagTS.URL, "123456789", 0, true},
{maxAgeTS.URL, "", 10, true},
{etagMaxAgeTS.URL, "123456789", 10, true},
}
testFn := func(tt testData, useRedirect bool) {
aciURL := fmt.Sprintf("%s/app.aci", tt.URL)
//.........这里部分代码省略.........
开发者ID:nak3,项目名称:rkt,代码行数:101,代码来源:fetch_test.go
示例2: TestFetchImage
func TestFetchImage(t *testing.T) {
dir, err := ioutil.TempDir("", "fetch-image")
if err != nil {
t.Fatalf("error creating tempdir: %v", err)
}
defer os.RemoveAll(dir)
s, err := store.NewStore(dir)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
defer s.Dump(false)
ks, ksPath, err := keystore.NewTestKeystore()
if err != nil {
t.Errorf("unexpected error %v", err)
}
defer os.RemoveAll(ksPath)
key := keystoretest.KeyMap["example.com/app"]
if _, err := ks.StoreTrustedKeyPrefix("example.com/app", bytes.NewBufferString(key.ArmoredPublicKey)); err != nil {
t.Fatalf("unexpected error %v", err)
}
a, err := aci.NewBasicACI(dir, "example.com/app")
defer a.Close()
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
asc, err := aci.NewDetachedSignature(key.ArmoredPrivateKey, a)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI.
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch filepath.Ext(r.URL.Path) {
case ".aci":
io.Copy(w, a)
return
case ".asc":
io.Copy(w, asc)
return
default:
t.Fatalf("unknown extension %v", r.URL.Path)
}
}))
defer ts.Close()
ft := &fetcher{
imageActionData: imageActionData{
s: s,
ks: ks,
},
}
_, err = ft.fetchImage(fmt.Sprintf("%s/app.aci", ts.URL), "", true)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:67,代码来源:fetch_test.go
示例3: TestFetchImageCache
func TestFetchImageCache(t *testing.T) {
dir, err := ioutil.TempDir("", "fetch-image-cache")
if err != nil {
t.Fatalf("error creating tempdir: %v", err)
}
defer os.RemoveAll(dir)
s, err := store.NewStore(dir)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
defer s.Dump(false)
ks, ksPath, err := keystore.NewTestKeystore()
if err != nil {
t.Errorf("unexpected error %v", err)
}
defer os.RemoveAll(ksPath)
key := keystoretest.KeyMap["example.com/app"]
if _, err := ks.StoreTrustedKeyPrefix("example.com/app", bytes.NewBufferString(key.ArmoredPublicKey)); err != nil {
t.Fatalf("unexpected error %v", err)
}
a, err := aci.NewBasicACI(dir, "example.com/app")
defer a.Close()
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
asc, err := aci.NewDetachedSignature(key.ArmoredPrivateKey, a)
if err != nil {
t.Fatalf("unexpected error %v", err)
}
// Rewind the ACI
if _, err := a.Seek(0, 0); err != nil {
t.Fatalf("unexpected error %v", err)
}
aciBody, err := ioutil.ReadAll(a)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
ascBody, err := ioutil.ReadAll(asc)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
nocacheServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "",
maxAge: 0,
t: t,
}
etagServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "123456789",
maxAge: 0,
t: t,
}
maxAgeServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "",
maxAge: 10,
t: t,
}
etagMaxAgeServer := &cachingServerHandler{
aciBody: aciBody,
ascBody: ascBody,
etag: "123456789",
maxAge: 10,
t: t,
}
nocacheTS := httptest.NewServer(nocacheServer)
defer nocacheTS.Close()
etagTS := httptest.NewServer(etagServer)
defer etagTS.Close()
maxAgeTS := httptest.NewServer(maxAgeServer)
defer maxAgeTS.Close()
etagMaxAgeTS := httptest.NewServer(etagMaxAgeServer)
defer etagMaxAgeTS.Close()
tests := []struct {
URL string
etag string
cacheMaxAge int
shouldUseCached bool
}{
{nocacheTS.URL, "", 0, false},
{etagTS.URL, "123456789", 0, true},
{maxAgeTS.URL, "", 10, true},
{etagMaxAgeTS.URL, "123456789", 10, true},
}
for _, tt := range tests {
ft := &fetcher{
//.........这里部分代码省略.........
开发者ID:rhvgoyal,项目名称:rkt,代码行数:101,代码来源:fetch_test.go
注:本文中的github.com/coreos/rkt/pkg/aci.NewDetachedSignature函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论