Chore: Fix tests for Go 1.15 (#26957)

* Chore: Fix tests for Go 1.15
This commit is contained in:
Arve Knudsen 2020-08-12 17:45:03 +02:00 committed by GitHub
parent a8f57b2ffd
commit 1698c74ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 12 deletions

View File

@ -828,7 +828,7 @@ func TestDashboardApiEndpoint(t *testing.T) {
bus.AddHandler("test", func(query *models.GetDashboardVersionQuery) error {
query.Result = &models.DashboardVersion{
Data: simplejson.NewFromAny(map[string]interface{}{
"title": "Dash" + string(query.DashboardId),
"title": fmt.Sprintf("Dash%d", query.DashboardId),
}),
}
return nil

View File

@ -2,6 +2,7 @@ package gtime
import (
"fmt"
"regexp"
"testing"
"time"
@ -14,7 +15,7 @@ func TestParseInterval(t *testing.T) {
tcs := []struct {
interval string
duration time.Duration
err string
err *regexp.Regexp
}{
{interval: "1d", duration: now.Sub(now.AddDate(0, 0, -1))},
{interval: "1w", duration: now.Sub(now.AddDate(0, 0, -7))},
@ -22,17 +23,18 @@ func TestParseInterval(t *testing.T) {
{interval: "1M", duration: now.Sub(now.AddDate(0, -1, 0))},
{interval: "1y", duration: now.Sub(now.AddDate(-1, 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 {
t.Run(fmt.Sprintf("testcase %d", i), func(t *testing.T) {
res, err := ParseInterval(tc.interval)
if tc.err == "" {
if tc.err == nil {
require.NoError(t, err, "interval %q", tc.interval)
require.Equal(t, tc.duration, res, "interval %q", tc.interval)
} 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())
}
})
}

View File

@ -2,6 +2,7 @@ package sqlstore
import (
"context"
"regexp"
"testing"
"time"
@ -168,7 +169,8 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
cmd.Frequency = "invalid duration"
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) {
err := UpdateAlertNotification(updateCmd)
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "time: invalid duration invalid duration")
So(regexp.MustCompile(`^time: invalid duration "?invalid duration"?$`).MatchString(
err.Error()), ShouldBeTrue)
})
})

View File

@ -3,6 +3,7 @@ package sqlstore
import (
"context"
"math/rand"
"strconv"
"testing"
"time"
@ -191,14 +192,14 @@ func test(t *testing.T, dashboardProps DashboardProps, dashboardPermission *Dash
}
func createDummyUser() (*models.User, error) {
uid := rand.Intn(9999999)
uid := strconv.Itoa(rand.Intn(9999999))
createUserCmd := &models.CreateUserCommand{
Email: string(uid) + "@example.com",
Login: string(uid),
Name: string(uid),
Email: uid + "@example.com",
Login: uid,
Name: uid,
Company: "",
OrgName: "",
Password: string(uid),
Password: uid,
EmailVerified: true,
IsAdmin: false,
SkipOrgSetup: false,