yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/cloudprovider/objectstore_test.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cloudprovider 16 17 import "testing" 18 19 func TestParseRange(t *testing.T) { 20 cases := []struct { 21 in string 22 start int64 23 end int64 24 }{ 25 { 26 in: "bytes=0-200", 27 start: 0, 28 end: 200, 29 }, 30 { 31 in: "200-3232300", 32 start: 200, 33 end: 3232300, 34 }, 35 { 36 in: "200-", 37 start: 200, 38 end: 0, 39 }, 40 { 41 in: "-232323", 42 start: 0, 43 end: 232323, 44 }, 45 } 46 for _, c := range cases { 47 got := ParseRange(c.in) 48 if got.Start != c.start || got.End != c.end { 49 t.Fatalf("got.start(%d) != want.start(%d) or got.end(%d) != want.end(%d)", got.Start, c.start, got.End, c.end) 50 } 51 } 52 }