Commit 1698c74e by Arve Knudsen Committed by GitHub

Chore: Fix tests for Go 1.15 (#26957)

* Chore: Fix tests for Go 1.15
parent a8f57b2f
...@@ -828,7 +828,7 @@ func TestDashboardApiEndpoint(t *testing.T) { ...@@ -828,7 +828,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error { bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
query.Result = &models.DashboardVersion{ query.Result = &models.DashboardVersion{
Data: simplejson.NewFromAny(map[string]interface{}{ Data: simplejson.NewFromAny(map[string]interface{}{
"title": "Dash" + string(query.DashboardId), "title": fmt.Sprintf("Dash%d", query.DashboardId),
}), }),
} }
return nil return nil
......
...@@ -2,6 +2,7 @@ package gtime ...@@ -2,6 +2,7 @@ package gtime
import ( import (
"fmt" "fmt"
"regexp"
"testing" "testing"
"time" "time"
...@@ -14,7 +15,7 @@ func TestParseInterval(t *testing.T) { ...@@ -14,7 +15,7 @@ func TestParseInterval(t *testing.T) {
tcs := []struct { tcs := []struct {
interval string interval string
duration time.Duration duration time.Duration
err string err *regexp.Regexp
}{ }{
{interval: "1d", duration: now.Sub(now.AddDate(0, 0, -1))}, {interval: "1d", duration: now.Sub(now.AddDate(0, 0, -1))},
{interval: "1w", duration: now.Sub(now.AddDate(0, 0, -7))}, {interval: "1w", duration: now.Sub(now.AddDate(0, 0, -7))},
...@@ -22,17 +23,18 @@ func TestParseInterval(t *testing.T) { ...@@ -22,17 +23,18 @@ func TestParseInterval(t *testing.T) {
{interval: "1M", duration: now.Sub(now.AddDate(0, -1, 0))}, {interval: "1M", duration: now.Sub(now.AddDate(0, -1, 0))},
{interval: "1y", duration: now.Sub(now.AddDate(-1, 0, 0))}, {interval: "1y", duration: now.Sub(now.AddDate(-1, 0, 0))},
{interval: "5y", duration: now.Sub(now.AddDate(-5, 0, 0))}, {interval: "5y", duration: now.Sub(now.AddDate(-5, 0, 0))},
{interval: "invalid-duration", err: "time: invalid duration invalid-duration"}, {interval: "invalid-duration", err: regexp.MustCompile(`^time: invalid duration "?invalid-duration"?$`)},
} }
for i, tc := range tcs { for i, tc := range tcs {
t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) { t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) {
res, err := ParseInterval(tc.interval) res, err := ParseInterval(tc.interval)
if tc.err == "" { if tc.err == nil {
require.NoError(t, err, "interval %q", tc.interval) require.NoError(t, err, "interval %q", tc.interval)
require.Equal(t, tc.duration, res, "interval %q", tc.interval) require.Equal(t, tc.duration, res, "interval %q", tc.interval)
} else { } else {
require.EqualError(t, err, tc.err, "interval %q", tc.interval) require.Error(t, err, "interval %q", tc.interval)
require.Regexp(t, tc.err, err.Error())
} }
}) })
} }
......
...@@ -2,6 +2,7 @@ package sqlstore ...@@ -2,6 +2,7 @@ package sqlstore
import ( import (
"context" "context"
"regexp"
"testing" "testing"
"time" "time"
...@@ -168,7 +169,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) { ...@@ -168,7 +169,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
cmd.Frequency = "invalid duration" cmd.Frequency = "invalid duration"
err := CreateAlertNotificationCommand(cmd) err := CreateAlertNotificationCommand(cmd)
So(err.Error(), ShouldEqual, "time: invalid duration invalid duration") So(regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
err.Error()), ShouldBeTrue)
}) })
}) })
...@@ -199,7 +201,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) { ...@@ -199,7 +201,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
err := UpdateAlertNotification(updateCmd) err := UpdateAlertNotification(updateCmd)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "time: invalid duration invalid duration") So(regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
err.Error()), ShouldBeTrue)
}) })
}) })
......
...@@ -3,6 +3,7 @@ package sqlstore ...@@ -3,6 +3,7 @@ package sqlstore
import ( import (
"context" "context"
"math/rand" "math/rand"
"strconv"
"testing" "testing"
"time" "time"
...@@ -191,14 +192,14 @@ func test(t *testing.T, dashboardProps DashboardProps, dashboardPermission *Dash ...@@ -191,14 +192,14 @@ func test(t *testing.T, dashboardProps DashboardProps, dashboardPermission *Dash
} }
func createDummyUser() (*models.User, error) { func createDummyUser() (*models.User, error) {
uid := rand.Intn(9999999) uid := strconv.Itoa(rand.Intn(9999999))
createUserCmd := &models.CreateUserCommand{ createUserCmd := &models.CreateUserCommand{
Email: string(uid) + "@example.com", Email: uid + "@example.com",
Login: string(uid), Login: uid,
Name: string(uid), Name: uid,
Company: "", Company: "",
OrgName: "", OrgName: "",
Password: string(uid), Password: uid,
EmailVerified: true, EmailVerified: true,
IsAdmin: false, IsAdmin: false,
SkipOrgSetup: false, SkipOrgSetup: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment