Need to include size in test data

This commit is contained in:
Steve Streeting 2015-11-24 14:26:00 +00:00
parent ab21ec8cf4
commit 44c8bc744c
2 changed files with 27 additions and 14 deletions

@ -34,7 +34,7 @@ git-lfs-test-server-api [--url=<apiurl> | --clone=<cloneurl>]
|------|-------| |------|-------|
|`--url=<apiurl>`|URL of the server API to call. This must point directly at the API root and not the clone URL, and must be HTTP[S]. You must supply either this argument or the `--clone` argument| |`--url=<apiurl>`|URL of the server API to call. This must point directly at the API root and not the clone URL, and must be HTTP[S]. You must supply either this argument or the `--clone` argument|
|`--clone=<cloneurl>`|The clone URL from which to derive the API URL. If it is HTTP[S], the test will try to find the API at `<cloneurl>/info/lfs`; if it is an SSH URL, then the test will call git-lfs-authenticate on the server to derive the API (with auth token if needed) just like the git-lfs client does. You must supply either this argument or the `--url` argument| |`--clone=<cloneurl>`|The clone URL from which to derive the API URL. If it is HTTP[S], the test will try to find the API at `<cloneurl>/info/lfs`; if it is an SSH URL, then the test will call git-lfs-authenticate on the server to derive the API (with auth token if needed) just like the git-lfs client does. You must supply either this argument or the `--url` argument|
|`<oid-exists-file> <oid-missing-file>`|Optional input files for data-driven mode (both must be supplied if this is used); each must be a file with one oid per line. The first must be a list of oids that exist on the server, the second must bea list of oids known not to exist. If supplied, the tests will not call the content server or modify any data. If omitted, the test will generate its own list of oids and will modify the server (and expects that the server is empty of oids at the start)| |`<oid-exists-file> <oid-missing-file>`|Optional input files for data-driven mode (both must be supplied if this is used); each must be a file with `<oid> <size_in_bytes>` per line. The first file must be a list of oids that exist on the server, the second must be a list of oids known not to exist. If supplied, the tests will not call the content server or modify any data. If omitted, the test will generate its own list of oids and will modify the server (and expects that the server is empty of oids at the start)|
## Authentication ## Authentication

@ -7,15 +7,21 @@ import (
"fmt" "fmt"
"math/rand" "math/rand"
"os" "os"
"strconv"
"strings" "strings"
"github.com/github/git-lfs/lfs" "github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra" "github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
) )
type TestObject struct {
Oid string
Size int64
}
type ServerTest struct { type ServerTest struct {
Name string Name string
F func(oidsExist, oidsMissing []string) error F func(oidsExist, oidsMissing []TestObject) error
} }
var ( var (
@ -54,7 +60,7 @@ func testServerApi(cmd *cobra.Command, args []string) {
} }
lfs.Config.SetManualEndpoint(endp) lfs.Config.SetManualEndpoint(endp)
var oidsExist, oidsMissing []string var oidsExist, oidsMissing []TestObject
if len(args) >= 2 { if len(args) >= 2 {
fmt.Printf("Reading test data from files (no server content changes)\n") fmt.Printf("Reading test data from files (no server content changes)\n")
oidsExist = readTestOids(args[0]) oidsExist = readTestOids(args[0])
@ -73,28 +79,33 @@ func testServerApi(cmd *cobra.Command, args []string) {
runTests(oidsExist, oidsMissing) runTests(oidsExist, oidsMissing)
} }
func readTestOids(filename string) []string { func readTestOids(filename string) []TestObject {
f, err := os.OpenFile(filename, os.O_RDONLY, 0644) f, err := os.OpenFile(filename, os.O_RDONLY, 0644)
if err != nil { if err != nil {
exit("Error opening file %s", filename) exit("Error opening file %s", filename)
} }
defer f.Close() defer f.Close()
var ret []string var ret []TestObject
rdr := bufio.NewReader(f) rdr := bufio.NewReader(f)
line, err := rdr.ReadString('\n') line, err := rdr.ReadString('\n')
for err == nil { for err == nil {
ret = append(ret, strings.TrimSpace(line)) fields := strings.Fields(strings.TrimSpace(line))
if len(fields) == 2 {
sz, _ := strconv.ParseInt(fields[1], 10, 64)
ret = append(ret, TestObject{Oid: fields[0], Size: sz})
}
line, err = rdr.ReadString('\n') line, err = rdr.ReadString('\n')
} }
return ret return ret
} }
func constructTestOids() (oidsExist, oidsMissing []string) { func constructTestOids() (oidsExist, oidsMissing []TestObject) {
const oidCount = 50 const oidCount = 50
oidsExist = make([]string, 0, oidCount) oidsExist = make([]TestObject, 0, oidCount)
oidsMissing = make([]string, 0, oidCount) oidsMissing = make([]TestObject, 0, oidCount)
// Generate SHAs, not random so repeatable // Generate SHAs, not random so repeatable
rand.Seed(int64(oidCount)) rand.Seed(int64(oidCount))
@ -102,16 +113,18 @@ func constructTestOids() (oidsExist, oidsMissing []string) {
for i := 0; i < oidCount; i++ { for i := 0; i < oidCount; i++ {
runningSha.Write([]byte{byte(rand.Intn(256))}) runningSha.Write([]byte{byte(rand.Intn(256))})
oid := hex.EncodeToString(runningSha.Sum(nil)) oid := hex.EncodeToString(runningSha.Sum(nil))
oidsExist = append(oidsExist, oid) sz := int64(rand.Intn(200)) + 50
oidsExist = append(oidsExist, TestObject{Oid: oid, Size: sz})
runningSha.Write([]byte{byte(rand.Intn(256))}) runningSha.Write([]byte{byte(rand.Intn(256))})
oid = hex.EncodeToString(runningSha.Sum(nil)) oid = hex.EncodeToString(runningSha.Sum(nil))
oidsMissing = append(oidsMissing, oid) sz = int64(rand.Intn(200)) + 50
oidsMissing = append(oidsMissing, TestObject{Oid: oid, Size: sz})
} }
return return
} }
func runTests(oidsExist, oidsMissing []string) { func runTests(oidsExist, oidsMissing []TestObject) {
fmt.Printf("Running %d tests...\n", len(tests)) fmt.Printf("Running %d tests...\n", len(tests))
for _, t := range tests { for _, t := range tests {
@ -120,7 +133,7 @@ func runTests(oidsExist, oidsMissing []string) {
} }
func runTest(t ServerTest, oidsExist, oidsMissing []string) error { func runTest(t ServerTest, oidsExist, oidsMissing []TestObject) error {
const linelen = 70 const linelen = 70
line := t.Name line := t.Name
if len(line) > linelen { if len(line) > linelen {
@ -140,7 +153,7 @@ func runTest(t ServerTest, oidsExist, oidsMissing []string) error {
return err return err
} }
func setupTestData(oidsExist, oidsMissing []string) error { func setupTestData(oidsExist, oidsMissing []TestObject) error {
// TODO // TODO
return nil return nil
} }