Commit bb374fbd authored by Grzegorz Bizon's avatar Grzegorz Bizon

Extend specs for metadata, improve internal loop

parent d76b7599
......@@ -79,9 +79,11 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
for d := path.Dir(entry.Name); d != "." && d != "/"; d = path.Dir(d) {
entryDir := d + "/"
if _, ok := zipMap[entryDir]; !ok {
zipMap[entryDir] = nil
// If entryDir is already in the zipMap then so are all its parent directories
if _, ok := zipMap[entryDir]; ok {
break
}
zipMap[entryDir] = nil
}
}
......
......@@ -13,28 +13,29 @@ func TestMissingMetadataEntries(t *testing.T) {
archive := zip.NewWriter(&zipBuffer)
firstFile, err := archive.Create("file1")
if err != nil {
t.Fatal(err)
}
fmt.Fprint(firstFile, "test12")
files := []string{"file1", "some/file/dir/file2", "../../test12/test",
"/usr/bin/test", `c:\windows\win32.exe`, `c:/windows/win.dll`, "./f/asd", "/"}
secondFile, err := archive.Create("some/file/dir/file2")
for _, file := range files {
archiveFile, err := archive.Create(file)
if err != nil {
t.Fatal(err)
}
fmt.Fprint(secondFile, "test125678")
fmt.Fprint(archiveFile, file)
}
archive.Close()
zipReader := bytes.NewReader(zipBuffer.Bytes())
zipArchiveReader, _ := zip.NewReader(zipReader, int64(binary.Size(zipBuffer.Bytes())))
err = generateZipMetadata(&metaBuffer, zipArchiveReader)
if err := generateZipMetadata(&metaBuffer, zipArchiveReader); err != nil {
t.Fatal("zipartifacts: generateZipMetadata failed", err)
}
paths := []string{"file1", "some/", "some/file/", "some/file/dir", "some/file/dir/file2"}
for _, path := range paths {
if !bytes.Contains(metaBuffer.Bytes(), []byte(path)) {
t.Fatalf("zipartifacts: metadata for path %s not found!", path)
t.Fatal("zipartifacts: metadata for path", path, "not found")
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment