File: headers_test.go

package info (click to toggle)
rclone 1.69.3%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 45,712 kB
  • sloc: sh: 1,115; xml: 857; python: 754; javascript: 612; makefile: 299; ansic: 101; php: 74
file content (41 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
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
package rest

import (
	"net/http"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestParseSizeFromHeaders(t *testing.T) {
	testCases := []struct {
		ContentLength, ContentRange string
		Size                        int64
	}{{
		"", "", -1,
	}, {
		"42", "", 42,
	}, {
		"42", "invalid", -1,
	}, {
		"", "bytes 22-33/42", 42,
	}, {
		"12", "bytes 22-33/42", 42,
	}, {
		"12", "otherUnit 22-33/42", -1,
	}, {
		"12", "bytes 22-33/*", -1,
	}, {
		"0", "bytes */42", 42,
	}}
	for _, testCase := range testCases {
		headers := make(http.Header, 2)
		if len(testCase.ContentLength) > 0 {
			headers.Set("Content-Length", testCase.ContentLength)
		}
		if len(testCase.ContentRange) > 0 {
			headers.Set("Content-Range", testCase.ContentRange)
		}
		assert.Equalf(t, testCase.Size, ParseSizeFromHeaders(headers), "%+v", testCase)
	}
}