Call upload status tests
Fix metadata status not returning correct reference string Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
bb3c9c5927
commit
8e1591bd8b
@ -20,6 +20,7 @@ import (
|
||||
// ContentSuite runs a test suite on the snapshotter given a factory function.
|
||||
func ContentSuite(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func(), error)) {
|
||||
t.Run("Writer", makeTest(t, name, storeFn, checkContentStoreWriter))
|
||||
t.Run("UploadStatus", makeTest(t, name, storeFn, checkUploadStatus))
|
||||
}
|
||||
|
||||
func makeTest(t *testing.T, name string, storeFn func(ctx context.Context, root string) (content.Store, func(), error), fn func(ctx context.Context, t *testing.T, cs content.Store)) func(t *testing.T) {
|
||||
@ -162,12 +163,12 @@ func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
|
||||
// Write next 128 bytes
|
||||
preUpdate = time.Now()
|
||||
if _, err := w1.Write(c1[64:128]); err != nil {
|
||||
if _, err := w1.Write(c1[64:192]); err != nil {
|
||||
t.Fatalf("Failed to write: %+v", err)
|
||||
}
|
||||
postUpdate = time.Now()
|
||||
expected.Offset = 192
|
||||
d = digest.FromBytes(c1[64:128])
|
||||
d = digest.FromBytes(c1[:192])
|
||||
if err := checkStatus(w1, expected, d, preStart, postStart, preUpdate, postUpdate); err != nil {
|
||||
t.Fatalf("Status check failed: %+v", err)
|
||||
}
|
||||
@ -179,8 +180,7 @@ func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) {
|
||||
}
|
||||
postUpdate = time.Now()
|
||||
expected.Offset = 256
|
||||
d = digest.FromBytes(c1[192:])
|
||||
if err := checkStatus(w1, expected, d, preStart, postStart, preUpdate, postUpdate); err != nil {
|
||||
if err := checkStatus(w1, expected, d1, preStart, postStart, preUpdate, postUpdate); err != nil {
|
||||
t.Fatalf("Status check failed: %+v", err)
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ func checkStatus(w content.Writer, expected content.Status, d digest.Digest, pre
|
||||
}
|
||||
|
||||
if st.Ref != expected.Ref {
|
||||
return errors.Errorf("unexpected ref %v, expected %v", st.Ref, expected.Ref)
|
||||
return errors.Errorf("unexpected ref %q, expected %q", st.Ref, expected.Ref)
|
||||
}
|
||||
|
||||
if st.Offset != expected.Offset {
|
||||
@ -223,9 +223,10 @@ func checkStatus(w content.Writer, expected content.Status, d digest.Digest, pre
|
||||
return errors.Errorf("unexpected total %d, expected %d", st.Total, expected.Total)
|
||||
}
|
||||
|
||||
if st.Expected != expected.Expected {
|
||||
return errors.Errorf("unexpected \"expected digest\" %v, expected %v", st.Expected, expected.Expected)
|
||||
}
|
||||
// TODO: Add this test once all implementations guarantee this value is held
|
||||
//if st.Expected != expected.Expected {
|
||||
// return errors.Errorf("unexpected \"expected digest\" %q, expected %q", st.Expected, expected.Expected)
|
||||
//}
|
||||
|
||||
if st.StartedAt.After(postStart) || st.StartedAt.Before(preStart) {
|
||||
return errors.Errorf("unexpected started at time %s, expected between %s and %s", st.StartedAt, preStart, postStart)
|
||||
|
@ -251,7 +251,12 @@ func (cs *contentStore) Status(ctx context.Context, ref string) (content.Status,
|
||||
return content.Status{}, err
|
||||
}
|
||||
|
||||
return cs.Store.Status(ctx, bref)
|
||||
st, err := cs.Store.Status(ctx, bref)
|
||||
if err != nil {
|
||||
return content.Status{}, err
|
||||
}
|
||||
st.Ref = ref
|
||||
return st, nil
|
||||
}
|
||||
|
||||
func (cs *contentStore) Abort(ctx context.Context, ref string) error {
|
||||
@ -403,6 +408,14 @@ func (nw *namespacedWriter) commit(tx *bolt.Tx, size int64, expected digest.Dige
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nw *namespacedWriter) Status() (content.Status, error) {
|
||||
st, err := nw.Writer.Status()
|
||||
if err == nil {
|
||||
st.Ref = nw.ref
|
||||
}
|
||||
return st, err
|
||||
}
|
||||
|
||||
func (cs *contentStore) Reader(ctx context.Context, dgst digest.Digest) (io.ReadCloser, error) {
|
||||
if err := cs.checkAccess(ctx, dgst); err != nil {
|
||||
return nil, err
|
||||
|
@ -23,8 +23,9 @@ func TestContent(t *testing.T) {
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
cs = NewContentStore(db, cs)
|
||||
|
||||
return cs, func() {}, nil
|
||||
return NewContentStore(db, cs), func() {
|
||||
db.Close()
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user