-
Notifications
You must be signed in to change notification settings - Fork 36
/
unarchive_test.go
57 lines (46 loc) · 1.37 KB
/
unarchive_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 main
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"io/ioutil"
"os"
"testing"
)
// Register the below test suite
func TestUnarchiveTestSuite(t *testing.T) {
suite.Run(t, new(UnarchiveTestSuite))
}
type UnarchiveTestSuite struct {
suite.Suite
tmpDir string
}
func (s *UnarchiveTestSuite) SetupTest() {
var err error
s.tmpDir, err = ioutil.TempDir("/tmp", "ansible_puller")
assert.Nil(s.T(), err)
}
func (s *UnarchiveTestSuite) TearDownTest() {
os.RemoveAll(s.tmpDir)
}
func (s *UnarchiveTestSuite) TestTarballExists() {
err := extractTgz("testdata/good.tgz", s.tmpDir)
assert.Nil(s.T(), err)
stats, err := os.Stat(s.tmpDir + "/foo.txt")
assert.Nil(s.T(), err)
assert.True(s.T(), stats.Mode().IsRegular(), "should create a regular foo file")
stats, err = os.Stat(s.tmpDir + "/bar.txt")
assert.Nil(s.T(), err)
assert.True(s.T(), stats.Mode().IsRegular(), "should create a regular bar file")
}
func (s *UnarchiveTestSuite) TestTarballDoesNotExist() {
err := extractTgz("testdata/somethingthatdoesnotexist.tgz", s.tmpDir)
assert.NotNil(s.T(), err)
}
func (s *UnarchiveTestSuite) TestTarballIsCorrupted() {
err := extractTgz("testdata/corrupt.tgz", s.tmpDir)
assert.NotNil(s.T(), err)
}
func (s *UnarchiveTestSuite) TestTarballHasInvalidBody() {
err := extractTgz("testdata/half.tgz", s.tmpDir)
assert.NotNil(s.T(), err)
}