forked from sassoftware/go-rpmutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uncompress_test.go
57 lines (53 loc) · 1.36 KB
/
uncompress_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package rpmutils
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func TestUncompress(t *testing.T) {
defer goleak.VerifyNone(t)
// built with e.g.: rpmbuild -bb payload-test.spec -D'_binary_payload w.ufdio'
payloadTypes := []string{"w3.zstdio", "w6.lzdio", "w6.xzdio", "w9.bzdio", "w9.gzdio", "w.ufdio"}
for _, payloadType := range payloadTypes {
t.Run(payloadType, func(t *testing.T) {
// open rpm
fp := filepath.Join("testdata", "payload-test-0.1-"+payloadType+".x86_64.rpm")
f, err := os.Open(fp)
require.NoError(t, err)
defer f.Close()
rpm, err := ReadRpm(f)
require.NoError(t, err)
// consume payload
var files int
payload, err := rpm.PayloadReaderExtended()
require.NoError(t, err)
for {
_, err := payload.Next()
if err == io.EOF {
break
}
require.NoError(t, err)
_, err = io.Copy(ioutil.Discard, payload)
require.NoError(t, err)
files++
}
assert.Equal(t, 1, files)
})
}
}
func TestUncompressEmpty(t *testing.T) {
f, err := os.Open("testdata/empty-0.1-1.x86_64.rpm")
require.NoError(t, err)
defer f.Close()
rpm, err := ReadRpm(f)
require.NoError(t, err)
payload, err := rpm.PayloadReaderExtended()
require.NoError(t, err)
_, err = payload.Next()
assert.ErrorIs(t, err, io.EOF)
}