-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transfer - Send chunks if they are bigger than GiB
- Loading branch information
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAppendUploadCandidateIfNeeded(t *testing.T) { | ||
uploadChunk := &UploadChunk{} | ||
|
||
// Regular file | ||
uploadChunk.AppendUploadCandidateIfNeeded(FileRepresentation{Name: "regular-file"}, false) | ||
assert.Len(t, uploadChunk.UploadCandidates, 1) | ||
|
||
// Build info | ||
uploadChunk.AppendUploadCandidateIfNeeded(FileRepresentation{Name: "build-info.json"}, true) | ||
assert.Len(t, uploadChunk.UploadCandidates, 2) | ||
|
||
// Directory in build info - should be skipped | ||
uploadChunk.AppendUploadCandidateIfNeeded(FileRepresentation{}, true) | ||
assert.Len(t, uploadChunk.UploadCandidates, 2) | ||
} | ||
|
||
var isChunkFullCases = []struct { | ||
files []FileRepresentation | ||
isFull bool | ||
}{ | ||
{[]FileRepresentation{}, false}, | ||
{[]FileRepresentation{{Name: "fat-jim", Size: 10737418}}, false}, | ||
{[]FileRepresentation{{Name: "fat-vinny", Size: 1073741825}}, true}, | ||
} | ||
|
||
func TestIsChunkFull(t *testing.T) { | ||
for _, testCase := range isChunkFullCases { | ||
t.Run("", func(t *testing.T) { | ||
uploadChunk := &UploadChunk{UploadCandidates: testCase.files} | ||
assert.Equal(t, testCase.isFull, uploadChunk.IsChunkFull()) | ||
}) | ||
} | ||
t.Run("", func(t *testing.T) { | ||
uploadChunk := &UploadChunk{} | ||
for i := 0; i < 17; i++ { | ||
uploadChunk.AppendUploadCandidateIfNeeded(FileRepresentation{Name: fmt.Sprintf("%d", i)}, false) | ||
} | ||
assert.True(t, uploadChunk.IsChunkFull()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters