Skip to content

Commit

Permalink
Add some more t.Parallel and t.Helper
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskuehl committed Sep 13, 2024
1 parent 2fac3c3 commit 93f9337
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/assets/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestDevStaticDev(t *testing.T) {
t.Parallel()
conf := testfunc.NewConfig()
conf.DevMode = true
ts := testfunc.RunningServer(t, conf)
Expand All @@ -29,6 +30,7 @@ func TestDevStaticDev(t *testing.T) {
}

func TestDevStaticProd(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down
1 change: 1 addition & 0 deletions server/security/csp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var cspRegexp = regexp.MustCompile(
)

func TestCSP(t *testing.T) {
t.Parallel()
conf := testfunc.NewConfig()
conf.ObjectURLPattern = &url.URL{Scheme: "https", Host: "fancy-cdn.com", Path: ":path:"}
ts := testfunc.RunningServer(t, conf)
Expand Down
2 changes: 2 additions & 0 deletions server/storage/dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestDevStorageDev(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
tmp := t.TempDir()

objectRoot := filepath.Join(tmp, "object")
Expand Down Expand Up @@ -93,6 +94,7 @@ func TestDevStorageProd(t *testing.T) {
}
for name, url := range urls {
t.Run(name, func(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down
1 change: 1 addition & 0 deletions server/uploads/uploads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func TestSanitizeUploadName(t *testing.T) {
}

func TestUploadObjects(t *testing.T) {
t.Parallel()
logger := testfunc.NewMemoryLogger()
storageBackend := testfunc.NewMemoryStorageBackend()

Expand Down
1 change: 1 addition & 0 deletions server/views/healthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func TestHealthz(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down
1 change: 1 addition & 0 deletions server/views/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestIndex(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down
1 change: 1 addition & 0 deletions server/views/upload_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

func TestUploadHistory(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down
4 changes: 4 additions & 0 deletions server/views/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func addFile(t *testing.T, writer *multipart.Writer, filename, content string) {
}

func TestUpload(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down Expand Up @@ -70,6 +71,7 @@ func TestUpload(t *testing.T) {
}

func TestUploadJSON(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand Down Expand Up @@ -120,6 +122,7 @@ func TestUploadJSON(t *testing.T) {
}

func TestUploadNoMultipart(t *testing.T) {
t.Parallel()
ts := testfunc.RunningServer(t, testfunc.NewConfig())
defer ts.Cleanup()

Expand All @@ -135,6 +138,7 @@ func TestUploadNoMultipart(t *testing.T) {
}

func TestUploadTooLarge(t *testing.T) {
t.Parallel()
conf := testfunc.NewConfig()
conf.MaxUploadBytes = 1
ts := testfunc.RunningServer(t, conf)
Expand Down
1 change: 1 addition & 0 deletions testfunc/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type TestServer struct {
}

func RunningServer(t *testing.T, config *config.Config) TestServer {
t.Helper()
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
port, done, err := run(t, ctx, config)
Expand Down
3 changes: 3 additions & 0 deletions testfunc/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ type StoredS3Object struct {

type FakeS3Client struct {
Objects map[string]StoredS3Object
mu sync.Mutex
}

func (f *FakeS3Client) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
f.mu.Lock()
defer f.mu.Unlock()
var buf bytes.Buffer
if _, err := io.Copy(&buf, params.Body); err != nil {
return nil, fmt.Errorf("copying object: %w", err)
Expand Down

0 comments on commit 93f9337

Please sign in to comment.