-
Notifications
You must be signed in to change notification settings - Fork 0
/
output_test.go
38 lines (32 loc) · 943 Bytes
/
output_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
package diplomat
import (
"github.com/google/uuid"
"github.com/stretchr/testify/suite"
"io/ioutil"
"os"
"path/filepath"
"testing"
)
type OutputDirectoryTestSuite struct {
suite.Suite
}
func (o OutputDirectoryTestSuite) Cleanup(testDir string) {
o.Require().NoError(os.RemoveAll(testDir))
}
func (o OutputDirectoryTestSuite) TestWriteFile() {
testRoot := filepath.Join(os.TempDir(),uuid.New().String())
err := os.MkdirAll(testRoot, DefaultDirectoryPerm)
o.Require().NoError(err)
defer o.Cleanup(testRoot)
od := NewOutputDirectory(testRoot)
data := []byte("content of helloworld")
o.Require().NoError(od.WriteFile("helloworld", data))
expectedFilePath := filepath.Join(testRoot,"helloworld")
o.Require().FileExists(expectedFilePath)
content, err := ioutil.ReadFile(expectedFilePath)
o.Require().NoError(err)
o.Equal(content, data)
}
func TestOutputDirectory(t *testing.T) {
suite.Run(t, &OutputDirectoryTestSuite{})
}