Reduce indentation and long lines in test
This commit is contained in:
parent
0aea5f81ef
commit
77a4a3da90
|
@ -84,12 +84,13 @@ func writeSourceCache(t *testing.T, basePath string, fixtures []SourceFixture) {
|
|||
if err := ioutil.WriteFile(path, f.content, perms); err != nil {
|
||||
t.Fatalf("Unable to write cache file %s: %v", path, err)
|
||||
}
|
||||
if !f.mtime.IsZero() {
|
||||
if f.mtime.IsZero() {
|
||||
continue
|
||||
}
|
||||
if err := os.Chtimes(path, f.mtime, f.mtime); err != nil {
|
||||
t.Fatalf("Unable to touch cache file %s to %v: %v", path, f.mtime, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkSourceCache(c *check.C, basePath string, fixtures []SourceFixture) {
|
||||
|
@ -122,22 +123,15 @@ func loadTestSourceNames(t *testing.T, d *SourceTestData) {
|
|||
}
|
||||
}
|
||||
|
||||
func loadFixtures(t *testing.T, d *SourceTestData) {
|
||||
d.fixtures = map[SourceTestState]map[string]SourceFixture{TestStateCorrect: map[string]SourceFixture{}}
|
||||
for _, source := range d.sources {
|
||||
for _, suffix := range [...]string{"", ".minisig"} {
|
||||
file := source + suffix
|
||||
d.fixtures[TestStateCorrect][file] = SourceFixture{suffix: suffix, content: readFixture(t, filepath.Join("sources", file)), mtime: d.timeNow}
|
||||
for _, state := range [...]SourceTestState{TestStateExpired, TestStatePartial, TestStateReadErr, TestStateOpenErr,
|
||||
TestStatePartialSig, TestStateMissingSig, TestStateReadSigErr, TestStateOpenSigErr} {
|
||||
func generateFixtureState(t *testing.T, d *SourceTestData, suffix, file string, state SourceTestState) {
|
||||
if _, ok := d.fixtures[state]; !ok {
|
||||
d.fixtures[state] = map[string]SourceFixture{}
|
||||
}
|
||||
if suffix != ".minisig" {
|
||||
switch state {
|
||||
case TestStatePartialSig, TestStateMissingSig, TestStateReadSigErr, TestStateOpenSigErr:
|
||||
if suffix != ".minisig" {
|
||||
d.fixtures[state][file] = d.fixtures[TestStateCorrect][file]
|
||||
continue
|
||||
return
|
||||
}
|
||||
}
|
||||
f := SourceFixture{suffix: suffix, mtime: d.timeNow}
|
||||
|
@ -152,6 +146,29 @@ func loadFixtures(t *testing.T, d *SourceTestData) {
|
|||
f.content, f.perms = d.fixtures[TestStateCorrect][file].content[:1], 0200
|
||||
}
|
||||
d.fixtures[state][file] = f
|
||||
}
|
||||
|
||||
func loadFixtures(t *testing.T, d *SourceTestData) {
|
||||
d.fixtures = map[SourceTestState]map[string]SourceFixture{TestStateCorrect: map[string]SourceFixture{}}
|
||||
for _, source := range d.sources {
|
||||
for _, suffix := range [...]string{"", ".minisig"} {
|
||||
file := source + suffix
|
||||
d.fixtures[TestStateCorrect][file] = SourceFixture{
|
||||
suffix: suffix,
|
||||
content: readFixture(t, filepath.Join("sources", file)),
|
||||
mtime: d.timeNow,
|
||||
}
|
||||
for _, state := range [...]SourceTestState{
|
||||
TestStateExpired,
|
||||
TestStatePartial,
|
||||
TestStateReadErr,
|
||||
TestStateOpenErr,
|
||||
TestStatePartialSig,
|
||||
TestStateMissingSig,
|
||||
TestStateReadSigErr,
|
||||
TestStateOpenSigErr,
|
||||
} {
|
||||
generateFixtureState(t, d, suffix, file, state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -261,22 +278,11 @@ func prepSourceTestCache(t *testing.T, d *SourceTestData, e *SourceTestExpect, s
|
|||
}
|
||||
|
||||
func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect, source string, downloadTest []SourceTestState) {
|
||||
if len(downloadTest) > 0 {
|
||||
if len(downloadTest) == 0 {
|
||||
return
|
||||
}
|
||||
for _, state := range downloadTest {
|
||||
path := "/" + strconv.FormatUint(uint64(state), 10) + "/" + source
|
||||
if !e.success {
|
||||
switch state {
|
||||
case TestStateCorrect:
|
||||
e.cache = []SourceFixture{d.fixtures[state][source], d.fixtures[state][source+".minisig"]}
|
||||
e.Source.in, e.success = e.cache[0].content, true
|
||||
fallthrough
|
||||
case TestStateMissingSig, TestStatePartial, TestStatePartialSig, TestStateReadSigErr:
|
||||
d.reqExpect[path+".minisig"]++
|
||||
fallthrough
|
||||
case TestStateMissing, TestStateReadErr:
|
||||
d.reqExpect[path]++
|
||||
}
|
||||
}
|
||||
switch state {
|
||||
case TestStateMissing, TestStateMissingSig:
|
||||
e.err = "404 Not Found"
|
||||
|
@ -294,6 +300,20 @@ func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect
|
|||
e.Source.urls = append(e.Source.urls, u)
|
||||
}
|
||||
e.urls = append(e.urls, d.server.URL+path)
|
||||
if e.success {
|
||||
continue
|
||||
}
|
||||
switch state {
|
||||
case TestStateCorrect:
|
||||
e.cache = []SourceFixture{d.fixtures[state][source], d.fixtures[state][source+".minisig"]}
|
||||
e.Source.in, e.success = e.cache[0].content, true
|
||||
fallthrough
|
||||
case TestStateMissingSig, TestStatePartial, TestStatePartialSig, TestStateReadSigErr:
|
||||
d.reqExpect[path+".minisig"]++
|
||||
fallthrough
|
||||
case TestStateMissing, TestStateReadErr:
|
||||
d.reqExpect[path]++
|
||||
}
|
||||
}
|
||||
if e.success {
|
||||
e.err = ""
|
||||
|
@ -306,7 +326,6 @@ func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect
|
|||
} else {
|
||||
e.success = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setupSourceTestCase(t *testing.T, d *SourceTestData, i int,
|
||||
|
|
Loading…
Reference in New Issue