|
|
|
@ -69,57 +69,71 @@ func TestParsePackage(t *testing.T) { |
|
|
|
|
tw.Write([]byte("Package: gitea\nVersion: 1.0.0\nArchitecture: amd64\n")) |
|
|
|
|
tw.Close() |
|
|
|
|
|
|
|
|
|
t.Run("None", func(t *testing.T) { |
|
|
|
|
data := createArchive(map[string][]byte{"control.tar": buf.Bytes()}) |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("gz", func(t *testing.T) { |
|
|
|
|
var zbuf bytes.Buffer |
|
|
|
|
zw := gzip.NewWriter(&zbuf) |
|
|
|
|
zw.Write(buf.Bytes()) |
|
|
|
|
zw.Close() |
|
|
|
|
|
|
|
|
|
data := createArchive(map[string][]byte{"control.tar.gz": zbuf.Bytes()}) |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
t.Run("xz", func(t *testing.T) { |
|
|
|
|
var xbuf bytes.Buffer |
|
|
|
|
xw, _ := xz.NewWriter(&xbuf) |
|
|
|
|
xw.Write(buf.Bytes()) |
|
|
|
|
xw.Close() |
|
|
|
|
|
|
|
|
|
data := createArchive(map[string][]byte{"control.tar.xz": xbuf.Bytes()}) |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
}) |
|
|
|
|
cases := []struct { |
|
|
|
|
Extension string |
|
|
|
|
WriterFactory func(io.Writer) io.WriteCloser |
|
|
|
|
}{ |
|
|
|
|
{ |
|
|
|
|
Extension: "", |
|
|
|
|
WriterFactory: func(w io.Writer) io.WriteCloser { |
|
|
|
|
return nopCloser{w} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Extension: ".gz", |
|
|
|
|
WriterFactory: func(w io.Writer) io.WriteCloser { |
|
|
|
|
return gzip.NewWriter(w) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Extension: ".xz", |
|
|
|
|
WriterFactory: func(w io.Writer) io.WriteCloser { |
|
|
|
|
xw, _ := xz.NewWriter(w) |
|
|
|
|
return xw |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
Extension: ".zst", |
|
|
|
|
WriterFactory: func(w io.Writer) io.WriteCloser { |
|
|
|
|
zw, _ := zstd.NewWriter(w) |
|
|
|
|
return zw |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
t.Run("zst", func(t *testing.T) { |
|
|
|
|
var zbuf bytes.Buffer |
|
|
|
|
zw, _ := zstd.NewWriter(&zbuf) |
|
|
|
|
zw.Write(buf.Bytes()) |
|
|
|
|
zw.Close() |
|
|
|
|
for _, c := range cases { |
|
|
|
|
t.Run(c.Extension, func(t *testing.T) { |
|
|
|
|
var cbuf bytes.Buffer |
|
|
|
|
w := c.WriterFactory(&cbuf) |
|
|
|
|
w.Write(buf.Bytes()) |
|
|
|
|
w.Close() |
|
|
|
|
|
|
|
|
|
data := createArchive(map[string][]byte{"control.tar" + c.Extension: cbuf.Bytes()}) |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
|
|
|
|
|
t.Run("TrailingSlash", func(t *testing.T) { |
|
|
|
|
data := createArchive(map[string][]byte{"control.tar" + c.Extension + "/": cbuf.Bytes()}) |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
data := createArchive(map[string][]byte{"control.tar.zst": zbuf.Bytes()}) |
|
|
|
|
type nopCloser struct { |
|
|
|
|
io.Writer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
p, err := ParsePackage(data) |
|
|
|
|
assert.NotNil(t, p) |
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
assert.Equal(t, "gitea", p.Name) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
func (nopCloser) Close() error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestParseControlFile(t *testing.T) { |
|
|
|
|