Commit d76b7599 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for generated artifacts metadata paths

parent 53e345d2
...@@ -77,8 +77,8 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error { ...@@ -77,8 +77,8 @@ func generateZipMetadata(output io.Writer, archive *zip.Reader) error {
for _, entry := range archive.File { for _, entry := range archive.File {
zipMap[entry.Name] = entry zipMap[entry.Name] = entry
for entryPath := path.Dir(entry.Name); entryPath != "." && entryPath != "/"; entryPath = path.Dir(entryPath) { for d := path.Dir(entry.Name); d != "." && d != "/"; d = path.Dir(d) {
entryDir := entryPath + "/" entryDir := d + "/"
if _, ok := zipMap[entryDir]; !ok { if _, ok := zipMap[entryDir]; !ok {
zipMap[entryDir] = nil zipMap[entryDir] = nil
} }
......
package zipartifacts
import (
"archive/zip"
"bytes"
"encoding/binary"
"fmt"
"testing"
)
func TestMissingMetadataEntries(t *testing.T) {
var zipBuffer, metaBuffer bytes.Buffer
archive := zip.NewWriter(&zipBuffer)
firstFile, err := archive.Create("file1")
if err != nil {
t.Fatal(err)
}
fmt.Fprint(firstFile, "test12")
secondFile, err := archive.Create("some/file/dir/file2")
if err != nil {
t.Fatal(err)
}
fmt.Fprint(secondFile, "test125678")
archive.Close()
zipReader := bytes.NewReader(zipBuffer.Bytes())
zipArchiveReader, _ := zip.NewReader(zipReader, int64(binary.Size(zipBuffer.Bytes())))
err = generateZipMetadata(&metaBuffer, zipArchiveReader)
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)
}
}
}
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