Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: client/internal/common/utils_test.go

Issue 1135173003: Create packages client/internal/ retry and lhttp. (Closed) Base URL: git@github.com:luci/luci-go@3_UI
Patch Set: Create lhttp.Retriable interface Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/internal/common/utils.go ('k') | client/internal/lhttp/client.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package common 5 package common
6 6
7 import ( 7 import (
8 "errors"
9 "testing" 8 "testing"
10 "time" 9 "time"
11 10
12 "github.com/maruel/ut" 11 "github.com/maruel/ut"
13 ) 12 )
14 13
15 func TestSizeToString(t *testing.T) { 14 func TestSizeToString(t *testing.T) {
16 data := []struct { 15 data := []struct {
17 in int64 16 in int64
18 expected string 17 expected string
19 }{ 18 }{
20 {0, "0b"}, 19 {0, "0b"},
21 {1, "1b"}, 20 {1, "1b"},
22 {1000, "1000b"}, 21 {1000, "1000b"},
23 {1023, "1023b"}, 22 {1023, "1023b"},
24 {1024, "1.00Kib"}, 23 {1024, "1.00Kib"},
25 {1029, "1.00Kib"}, 24 {1029, "1.00Kib"},
26 {1030, "1.01Kib"}, 25 {1030, "1.01Kib"},
27 {10234, "9.99Kib"}, 26 {10234, "9.99Kib"},
28 {10239, "10.00Kib"}, 27 {10239, "10.00Kib"},
29 {10240, "10.0Kib"}, 28 {10240, "10.0Kib"},
30 {1048575, "1024.0Kib"}, 29 {1048575, "1024.0Kib"},
31 {1048576, "1.00Mib"}, 30 {1048576, "1.00Mib"},
32 } 31 }
33 for i, line := range data { 32 for i, line := range data {
34 ut.AssertEqualIndex(t, i, line.expected, SizeToString(line.in)) 33 ut.AssertEqualIndex(t, i, line.expected, SizeToString(line.in))
35 } 34 }
36 } 35 }
37 36
38 func TestURLToHTTPS(t *testing.T) {
39 data := []struct {
40 in string
41 expected string
42 err error
43 }{
44 {"foo", "https://foo", nil},
45 {"https://foo", "https://foo", nil},
46 {"http://foo", "", errors.New("Only https:// scheme is accepted. It can be omitted.")},
47 }
48 for i, line := range data {
49 out, err := URLToHTTPS(line.in)
50 ut.AssertEqualIndex(t, i, line.expected, out)
51 ut.AssertEqualIndex(t, i, line.err, err)
52 }
53 }
54
55 func TestRound(t *testing.T) { 37 func TestRound(t *testing.T) {
56 data := []struct { 38 data := []struct {
57 in time.Duration 39 in time.Duration
58 round time.Duration 40 round time.Duration
59 expected time.Duration 41 expected time.Duration
60 }{ 42 }{
61 {-time.Second, time.Second, -time.Second}, 43 {-time.Second, time.Second, -time.Second},
62 {-500 * time.Millisecond, time.Second, -time.Second}, 44 {-500 * time.Millisecond, time.Second, -time.Second},
63 {-499 * time.Millisecond, time.Second, 0}, 45 {-499 * time.Millisecond, time.Second, 0},
64 {0, time.Second, 0}, 46 {0, time.Second, 0},
65 {499 * time.Millisecond, time.Second, 0}, 47 {499 * time.Millisecond, time.Second, 0},
66 {500 * time.Millisecond, time.Second, time.Second}, 48 {500 * time.Millisecond, time.Second, time.Second},
67 {time.Second, time.Second, time.Second}, 49 {time.Second, time.Second, time.Second},
68 } 50 }
69 for i, line := range data { 51 for i, line := range data {
70 ut.AssertEqualIndex(t, i, line.expected, Round(line.in, line.rou nd)) 52 ut.AssertEqualIndex(t, i, line.expected, Round(line.in, line.rou nd))
71 } 53 }
72 } 54 }
OLDNEW
« no previous file with comments | « client/internal/common/utils.go ('k') | client/internal/lhttp/client.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698