Skip to content

Commit

Permalink
Individuate archive tests #2293
Browse files Browse the repository at this point in the history
  • Loading branch information
rosecodym authored Jan 12, 2024
1 parent 651beff commit b03cc30
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions pkg/handlers/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,38 @@ func TestArchiveHandler(t *testing.T) {
}

for name, testCase := range tests {
resp, err := http.Get(testCase.archiveURL)
if err != nil || resp.StatusCode != http.StatusOK {
t.Error(err)
}
defer resp.Body.Close()
t.Run(name, func(t *testing.T) {
resp, err := http.Get(testCase.archiveURL)
if err != nil || resp.StatusCode != http.StatusOK {
t.Error(err)
}
defer resp.Body.Close()

archive := Archive{}
archive.New()
archive := Archive{}
archive.New()

newReader, err := diskbufferreader.New(resp.Body)
if err != nil {
t.Errorf("error creating reusable reader: %s", err)
}
archiveChan := archive.FromFile(logContext.Background(), newReader)

count := 0
re := regexp.MustCompile(testCase.matchString)
matched := false
for chunk := range archiveChan {
count++
if re.Match(chunk) {
matched = true
newReader, err := diskbufferreader.New(resp.Body)
if err != nil {
t.Errorf("error creating reusable reader: %s", err)
}
}
if !matched && len(testCase.matchString) > 0 {
t.Errorf("%s: Expected string not found in archive.", name)
}
if count != testCase.expectedChunks {
t.Errorf("%s: Unexpected number of chunks. Got %d, expected: %d", name, count, testCase.expectedChunks)
}
archiveChan := archive.FromFile(logContext.Background(), newReader)

count := 0
re := regexp.MustCompile(testCase.matchString)
matched := false
for chunk := range archiveChan {
count++
if re.Match(chunk) {
matched = true
}
}
if !matched && len(testCase.matchString) > 0 {
t.Errorf("%s: Expected string not found in archive.", name)
}
if count != testCase.expectedChunks {
t.Errorf("%s: Unexpected number of chunks. Got %d, expected: %d", name, count, testCase.expectedChunks)
}
})
}
}

Expand Down

0 comments on commit b03cc30

Please sign in to comment.