Skip to content

Commit 3a54741

Browse files
committed
Fix ci
Signed-off-by: SungJin1212 <[email protected]>
1 parent fb6f4c0 commit 3a54741

File tree

3 files changed

+56
-54
lines changed

3 files changed

+56
-54
lines changed

pkg/util/api/parse.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func ParseTime(s string) (time.Time, error) {
7979
func ParseTimeMillis(s string) (int64, error) {
8080
t, err := ParseTime(s)
8181
if err != nil {
82-
return 0, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
82+
return 0, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
8383
}
8484

8585
return util.TimeToMillis(t), nil
@@ -102,7 +102,7 @@ func ParseDuration(s string) (time.Duration, error) {
102102
func ParseDurationMillis(s string) (int64, error) {
103103
d, err := ParseDuration(s)
104104
if err != nil {
105-
return 0, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
105+
return 0, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
106106
}
107107

108108
return int64(d / (time.Millisecond / time.Nanosecond)), nil
@@ -123,7 +123,7 @@ func ParseTimeParam(r *http.Request, paramName string, defaultValue time.Time) (
123123
func ParseTimeParamMillis(r *http.Request, paramName string, defaultValue time.Time) (int64, error) {
124124
t, err := ParseTimeParam(r, paramName, defaultValue)
125125
if err != nil {
126-
return 0, httpgrpc.Errorf(http.StatusBadRequest, err.Error())
126+
return 0, httpgrpc.Errorf(http.StatusBadRequest, "%s", err.Error())
127127
}
128128

129129
return util.TimeToMillis(t), nil

pkg/util/api/parse_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99

1010
"github.com/prometheus/prometheus/promql/parser"
1111
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
13+
14+
"github.com/cortexproject/cortex/pkg/util"
1215
)
1316

1417
func TestFindMinMaxTime(t *testing.T) {
@@ -63,3 +66,53 @@ func TestFindMinMaxTime(t *testing.T) {
6366
})
6467
}
6568
}
69+
70+
func TestParseTime(t *testing.T) {
71+
var tests = []struct {
72+
input string
73+
fail bool
74+
result time.Time
75+
}{
76+
{
77+
input: "",
78+
fail: true,
79+
}, {
80+
input: "abc",
81+
fail: true,
82+
}, {
83+
input: "30s",
84+
fail: true,
85+
}, {
86+
input: "123",
87+
result: time.Unix(123, 0),
88+
}, {
89+
input: "123.123",
90+
result: time.Unix(123, 123000000),
91+
}, {
92+
input: "2015-06-03T13:21:58.555Z",
93+
result: time.Unix(1433337718, 555*time.Millisecond.Nanoseconds()),
94+
}, {
95+
input: "2015-06-03T14:21:58.555+01:00",
96+
result: time.Unix(1433337718, 555*time.Millisecond.Nanoseconds()),
97+
}, {
98+
// Test nanosecond rounding.
99+
input: "2015-06-03T13:21:58.56789Z",
100+
result: time.Unix(1433337718, 567*1e6),
101+
}, {
102+
// Test float rounding.
103+
input: "1543578564.705",
104+
result: time.Unix(1543578564, 705*1e6),
105+
},
106+
}
107+
108+
for _, test := range tests {
109+
ts, err := ParseTimeMillis(test.input)
110+
if test.fail {
111+
require.Error(t, err)
112+
continue
113+
}
114+
115+
require.NoError(t, err)
116+
assert.Equal(t, util.TimeToMillis(test.result), ts)
117+
}
118+
}

pkg/util/time_test.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/stretchr/testify/require"
1010
"go.uber.org/atomic"
1111

12-
"github.com/cortexproject/cortex/pkg/util/api"
1312
"github.com/cortexproject/cortex/pkg/util/test"
1413
)
1514

@@ -58,56 +57,6 @@ func TestDurationWithPositiveJitter_ZeroInputDuration(t *testing.T) {
5857
assert.Equal(t, time.Duration(0), DurationWithPositiveJitter(time.Duration(0), 0.5))
5958
}
6059

61-
func TestParseTime(t *testing.T) {
62-
var tests = []struct {
63-
input string
64-
fail bool
65-
result time.Time
66-
}{
67-
{
68-
input: "",
69-
fail: true,
70-
}, {
71-
input: "abc",
72-
fail: true,
73-
}, {
74-
input: "30s",
75-
fail: true,
76-
}, {
77-
input: "123",
78-
result: time.Unix(123, 0),
79-
}, {
80-
input: "123.123",
81-
result: time.Unix(123, 123000000),
82-
}, {
83-
input: "2015-06-03T13:21:58.555Z",
84-
result: time.Unix(1433337718, 555*time.Millisecond.Nanoseconds()),
85-
}, {
86-
input: "2015-06-03T14:21:58.555+01:00",
87-
result: time.Unix(1433337718, 555*time.Millisecond.Nanoseconds()),
88-
}, {
89-
// Test nanosecond rounding.
90-
input: "2015-06-03T13:21:58.56789Z",
91-
result: time.Unix(1433337718, 567*1e6),
92-
}, {
93-
// Test float rounding.
94-
input: "1543578564.705",
95-
result: time.Unix(1543578564, 705*1e6),
96-
},
97-
}
98-
99-
for _, test := range tests {
100-
ts, err := api.ParseTime(test.input)
101-
if test.fail {
102-
require.Error(t, err)
103-
continue
104-
}
105-
106-
require.NoError(t, err)
107-
assert.Equal(t, TimeToMillis(test.result), ts)
108-
}
109-
}
110-
11160
func TestNewDisableableTicker_Enabled(t *testing.T) {
11261
stop, ch := NewDisableableTicker(10 * time.Millisecond)
11362
defer stop()

0 commit comments

Comments
 (0)