-
Notifications
You must be signed in to change notification settings - Fork 38
/
paperwork_test.go
78 lines (64 loc) · 2.13 KB
/
paperwork_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package paperwork
import (
"io"
"log"
"os"
"path/filepath"
"testing"
"github.com/pkg/errors"
"github.com/spf13/afero"
"github.com/stretchr/testify/suite"
storageTest "github.com/transcom/mymove/pkg/storage/test"
"github.com/transcom/mymove/pkg/testingsuite"
"github.com/transcom/mymove/pkg/uploader"
)
type PaperworkSuite struct {
*testingsuite.PopTestSuite
userUploader *uploader.UserUploader
filesToClose []afero.File
}
func (suite *PaperworkSuite) AfterTest() {
for _, file := range suite.filesToClose {
//RA Summary: gosec - errcheck - Unchecked return value
//RA: Linter flags errcheck error: Ignoring a method's return value can cause the program to overlook unexpected states and conditions.
//RA: Functions with unchecked return values in the file are used to clean up file created for unit test
//RA: Given the functions causing the lint errors are used to clean up local storage space after a unit test, it does not present a risk
//RA Developer Status: Mitigated
//RA Validator Status: Mitigated
//RA Modified Severity: N/A
// nolint:errcheck
file.Close()
}
}
func (suite *PaperworkSuite) closeFile(file afero.File) {
suite.filesToClose = append(suite.filesToClose, file)
}
func (suite *PaperworkSuite) openLocalFile(path string, fs *afero.Afero) (afero.File, error) {
file, err := os.Open(filepath.Clean(path))
if err != nil {
return nil, errors.Wrap(err, "could not open file")
}
outputFile, err := fs.Create(path)
if err != nil {
return nil, errors.Wrap(err, "error creating afero file")
}
_, err = io.Copy(outputFile, file)
if err != nil {
return nil, errors.Wrap(err, "error copying over file contents")
}
suite.closeFile(outputFile)
return outputFile, nil
}
func TestPaperworkSuite(t *testing.T) {
storer := storageTest.NewFakeS3Storage(true)
newUploader, err := uploader.NewUserUploader(storer, uploader.MaxCustomerUserUploadFileSizeLimit)
if err != nil {
log.Panic(err)
}
hs := &PaperworkSuite{
PopTestSuite: testingsuite.NewPopTestSuite(testingsuite.CurrentPackage(), testingsuite.WithPerTestTransaction()),
userUploader: newUploader,
}
suite.Run(t, hs)
hs.PopTestSuite.TearDown()
}