OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package uniter_test | 4 package uniter_test |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "crypto/sha256" | |
9 "encoding/hex" | |
10 "fmt" | 8 "fmt" |
11 "io" | |
12 "io/ioutil" | 9 "io/ioutil" |
13 "net/rpc" | 10 "net/rpc" |
14 "net/url" | 11 "net/url" |
15 "os" | 12 "os" |
16 "os/exec" | 13 "os/exec" |
17 "path/filepath" | 14 "path/filepath" |
18 "strconv" | 15 "strconv" |
19 "strings" | 16 "strings" |
20 stdtesting "testing" | 17 stdtesting "testing" |
21 "time" | 18 "time" |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 type addCharm struct { | 1189 type addCharm struct { |
1193 dir *charm.Dir | 1190 dir *charm.Dir |
1194 curl *charm.URL | 1191 curl *charm.URL |
1195 } | 1192 } |
1196 | 1193 |
1197 func (s addCharm) step(c *gc.C, ctx *context) { | 1194 func (s addCharm) step(c *gc.C, ctx *context) { |
1198 var buf bytes.Buffer | 1195 var buf bytes.Buffer |
1199 err := s.dir.BundleTo(&buf) | 1196 err := s.dir.BundleTo(&buf) |
1200 c.Assert(err, gc.IsNil) | 1197 c.Assert(err, gc.IsNil) |
1201 body := buf.Bytes() | 1198 body := buf.Bytes() |
1202 » hasher := sha256.New() | 1199 » hash, _, err := utils.ReadSHA256(&buf) |
1203 » _, err = io.Copy(hasher, &buf) | |
1204 c.Assert(err, gc.IsNil) | 1200 c.Assert(err, gc.IsNil) |
1205 hash := hex.EncodeToString(hasher.Sum(nil)) | |
1206 key := fmt.Sprintf("/charms/%s/%d", s.dir.Meta().Name, s.dir.Revision()) | 1201 key := fmt.Sprintf("/charms/%s/%d", s.dir.Meta().Name, s.dir.Revision()) |
1207 hurl, err := url.Parse(coretesting.Server.URL + key) | 1202 hurl, err := url.Parse(coretesting.Server.URL + key) |
1208 c.Assert(err, gc.IsNil) | 1203 c.Assert(err, gc.IsNil) |
1209 ctx.charms[key] = coretesting.Response{200, nil, body} | 1204 ctx.charms[key] = coretesting.Response{200, nil, body} |
1210 ctx.sch, err = ctx.st.AddCharm(s.dir, s.curl, hurl, hash) | 1205 ctx.sch, err = ctx.st.AddCharm(s.dir, s.curl, hurl, hash) |
1211 c.Assert(err, gc.IsNil) | 1206 c.Assert(err, gc.IsNil) |
1212 } | 1207 } |
1213 | 1208 |
1214 type serveCharm struct{} | 1209 type serveCharm struct{} |
1215 | 1210 |
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 type verifyNoFile struct { | 2054 type verifyNoFile struct { |
2060 filename string | 2055 filename string |
2061 } | 2056 } |
2062 | 2057 |
2063 func (verify verifyNoFile) step(c *gc.C, ctx *context) { | 2058 func (verify verifyNoFile) step(c *gc.C, ctx *context) { |
2064 c.Assert(verify.filename, jc.DoesNotExist) | 2059 c.Assert(verify.filename, jc.DoesNotExist) |
2065 // Wait a short time and check again. | 2060 // Wait a short time and check again. |
2066 time.Sleep(coretesting.ShortWait) | 2061 time.Sleep(coretesting.ShortWait) |
2067 c.Assert(verify.filename, jc.DoesNotExist) | 2062 c.Assert(verify.filename, jc.DoesNotExist) |
2068 } | 2063 } |
OLD | NEW |