Mixed download test
This commit is contained in:
parent
d995ad5d51
commit
a613919607
@ -4,6 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/github/git-lfs/lfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
// "download" - all present
|
// "download" - all present
|
||||||
@ -65,7 +68,74 @@ func downloadAllMissing(oidsExist, oidsMissing []TestObject) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "download" - mixture
|
||||||
|
func downloadMixed(oidsExist, oidsMissing []TestObject) error {
|
||||||
|
|
||||||
|
existSet := lfs.NewStringSetWithCapacity(len(oidsExist))
|
||||||
|
missingSet := lfs.NewStringSetWithCapacity(len(oidsMissing))
|
||||||
|
|
||||||
|
// Predictable sequence, mixin existing & missing semi-randomly
|
||||||
|
rand.Seed(21)
|
||||||
|
count := len(oidsExist) + len(oidsMissing)
|
||||||
|
calloids := make([]TestObject, 0, count)
|
||||||
|
existIdx := 0
|
||||||
|
missingIdx := 0
|
||||||
|
for left := count; left > 0; {
|
||||||
|
for i := rand.Intn(3) + 1; existIdx < len(oidsExist) && i > 0; i-- {
|
||||||
|
obj := oidsExist[existIdx]
|
||||||
|
existSet.Add(obj.Oid)
|
||||||
|
calloids = append(calloids, obj)
|
||||||
|
existIdx++
|
||||||
|
left--
|
||||||
|
}
|
||||||
|
for i := rand.Intn(3) + 1; missingIdx < len(oidsMissing) && i > 0; i-- {
|
||||||
|
obj := oidsMissing[missingIdx]
|
||||||
|
missingSet.Add(obj.Oid)
|
||||||
|
calloids = append(calloids, obj)
|
||||||
|
missingIdx++
|
||||||
|
left--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
retobjs, err := callBatchApi("download", calloids)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(retobjs) != count {
|
||||||
|
return fmt.Errorf("Incorrect number of returned objects, expected %d, got %d", count, len(retobjs))
|
||||||
|
}
|
||||||
|
|
||||||
|
var errbuf bytes.Buffer
|
||||||
|
for _, o := range retobjs {
|
||||||
|
link, ok := o.Rel("download")
|
||||||
|
if missingSet.Contains(o.Oid) {
|
||||||
|
if ok {
|
||||||
|
errbuf.WriteString(fmt.Sprintf("Download link should not exist for %s, was %s\n", o.Oid, link))
|
||||||
|
}
|
||||||
|
if o.Error == nil {
|
||||||
|
errbuf.WriteString(fmt.Sprintf("Download should include an error for missing object %s, was %s\n", o.Oid))
|
||||||
|
} else if o.Error.Code != 404 {
|
||||||
|
errbuf.WriteString(fmt.Sprintf("Download error code for missing object %s should be 404, got %d\n", o.Oid, o.Error.Code))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if existSet.Contains(o.Oid) && !ok {
|
||||||
|
errbuf.WriteString(fmt.Sprintf("Missing download link for %s\n", o.Oid))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if errbuf.Len() > 0 {
|
||||||
|
return errors.New(errbuf.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
addTest("Test download: all existing", downloadAllExist)
|
addTest("Test download: all existing", downloadAllExist)
|
||||||
addTest("Test download: all missing", downloadAllMissing)
|
addTest("Test download: all missing", downloadAllMissing)
|
||||||
|
addTest("Test download: mixed", downloadMixed)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user