Correlations: Fix flaky integration tests (#64004)
* Correlations: Fix flaky integration tests * set explore-squad as correlations tests code owners
This commit is contained in:
@@ -135,6 +135,7 @@
|
|||||||
/pkg/services/validations/ @grafana/backend-platform
|
/pkg/services/validations/ @grafana/backend-platform
|
||||||
/pkg/setting/ @grafana/backend-platform
|
/pkg/setting/ @grafana/backend-platform
|
||||||
/pkg/tests/ @grafana/backend-platform
|
/pkg/tests/ @grafana/backend-platform
|
||||||
|
/pkg/tests/api/correlations/ @grafana/explore-squad
|
||||||
/pkg/tsdb/grafanads/ @grafana/backend-platform
|
/pkg/tsdb/grafanads/ @grafana/backend-platform
|
||||||
/pkg/tsdb/intervalv2/ @grafana/backend-platform
|
/pkg/tsdb/intervalv2/ @grafana/backend-platform
|
||||||
/pkg/tsdb/legacydata/ @grafana/backend-platform
|
/pkg/tsdb/legacydata/ @grafana/backend-platform
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func NewTestEnv(t *testing.T) TestContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
username string
|
User user.User
|
||||||
password string
|
password string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +122,8 @@ func (c TestContext) getURL(url string, user User) string {
|
|||||||
c.t.Helper()
|
c.t.Helper()
|
||||||
|
|
||||||
baseUrl := fmt.Sprintf("http://%s", c.env.Server.HTTPServer.Listener.Addr())
|
baseUrl := fmt.Sprintf("http://%s", c.env.Server.HTTPServer.Listener.Addr())
|
||||||
if user.username != "" && user.password != "" {
|
if user.User.Login != "" && user.password != "" {
|
||||||
baseUrl = fmt.Sprintf("http://%s:%s@%s", user.username, user.password, c.env.Server.HTTPServer.Listener.Addr())
|
baseUrl = fmt.Sprintf("http://%s:%s@%s", user.User.Login, user.password, c.env.Server.HTTPServer.Listener.Addr())
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
@@ -133,7 +133,7 @@ func (c TestContext) getURL(url string, user User) string {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TestContext) createUser(cmd user.CreateUserCommand) {
|
func (c TestContext) createUser(cmd user.CreateUserCommand) User {
|
||||||
c.t.Helper()
|
c.t.Helper()
|
||||||
store := c.env.SQLStore
|
store := c.env.SQLStore
|
||||||
store.Cfg.AutoAssignOrg = true
|
store.Cfg.AutoAssignOrg = true
|
||||||
@@ -145,8 +145,13 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) {
|
|||||||
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService, supportbundlestest.NewFakeBundleService())
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
_, err = usrSvc.CreateUserForTests(context.Background(), &cmd)
|
user, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
|
||||||
require.NoError(c.t, err)
|
require.NoError(c.t, err)
|
||||||
|
|
||||||
|
return User{
|
||||||
|
User: *user,
|
||||||
|
password: cmd.Password,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c TestContext) createDs(cmd *datasources.AddDataSourceCommand) *datasources.DataSource {
|
func (c TestContext) createDs(cmd *datasources.AddDataSourceCommand) *datasources.DataSource {
|
||||||
|
|||||||
@@ -21,31 +21,24 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := NewTestEnv(t)
|
ctx := NewTestEnv(t)
|
||||||
|
|
||||||
adminUser := User{
|
adminUser := ctx.createUser(user.CreateUserCommand{
|
||||||
username: "admin",
|
|
||||||
password: "admin",
|
|
||||||
}
|
|
||||||
editorUser := User{
|
|
||||||
username: "editor",
|
|
||||||
password: "editor",
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
|
||||||
Password: editorUser.password,
|
|
||||||
Login: editorUser.username,
|
|
||||||
})
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: adminUser.password,
|
Password: "admin",
|
||||||
Login: adminUser.username,
|
Login: "admin",
|
||||||
|
})
|
||||||
|
|
||||||
|
editorUser := ctx.createUser(user.CreateUserCommand{
|
||||||
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
|
Password: "editor",
|
||||||
|
Login: "editor",
|
||||||
|
OrgID: adminUser.User.OrgID,
|
||||||
})
|
})
|
||||||
|
|
||||||
createDsCommand := &datasources.AddDataSourceCommand{
|
createDsCommand := &datasources.AddDataSourceCommand{
|
||||||
Name: "read-only",
|
Name: "read-only",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource := ctx.createDs(createDsCommand)
|
dataSource := ctx.createDs(createDsCommand)
|
||||||
readOnlyDS := dataSource.UID
|
readOnlyDS := dataSource.UID
|
||||||
@@ -53,7 +46,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
|||||||
createDsCommand = &datasources.AddDataSourceCommand{
|
createDsCommand = &datasources.AddDataSourceCommand{
|
||||||
Name: "writable",
|
Name: "writable",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource = ctx.createDs(createDsCommand)
|
dataSource = ctx.createDs(createDsCommand)
|
||||||
writableDs := dataSource.UID
|
writableDs := dataSource.UID
|
||||||
|
|||||||
@@ -21,31 +21,24 @@ func TestIntegrationDeleteCorrelation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := NewTestEnv(t)
|
ctx := NewTestEnv(t)
|
||||||
|
|
||||||
adminUser := User{
|
adminUser := ctx.createUser(user.CreateUserCommand{
|
||||||
username: "admin",
|
|
||||||
password: "admin",
|
|
||||||
}
|
|
||||||
editorUser := User{
|
|
||||||
username: "editor",
|
|
||||||
password: "editor",
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
|
||||||
Password: editorUser.password,
|
|
||||||
Login: editorUser.username,
|
|
||||||
})
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: adminUser.password,
|
Password: "admin",
|
||||||
Login: adminUser.username,
|
Login: "admin",
|
||||||
|
})
|
||||||
|
|
||||||
|
editorUser := ctx.createUser(user.CreateUserCommand{
|
||||||
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
|
Password: "editor",
|
||||||
|
Login: "editor",
|
||||||
|
OrgID: adminUser.User.OrgID,
|
||||||
})
|
})
|
||||||
|
|
||||||
createDsCommand := &datasources.AddDataSourceCommand{
|
createDsCommand := &datasources.AddDataSourceCommand{
|
||||||
Name: "read-only",
|
Name: "read-only",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource := ctx.createDs(createDsCommand)
|
dataSource := ctx.createDs(createDsCommand)
|
||||||
readOnlyDS := dataSource.UID
|
readOnlyDS := dataSource.UID
|
||||||
@@ -53,7 +46,7 @@ func TestIntegrationDeleteCorrelation(t *testing.T) {
|
|||||||
createDsCommand = &datasources.AddDataSourceCommand{
|
createDsCommand = &datasources.AddDataSourceCommand{
|
||||||
Name: "writable",
|
Name: "writable",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource = ctx.createDs(createDsCommand)
|
dataSource = ctx.createDs(createDsCommand)
|
||||||
writableDs := dataSource.UID
|
writableDs := dataSource.UID
|
||||||
|
|||||||
@@ -23,24 +23,17 @@ func TestIntegrationReadCorrelation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := NewTestEnv(t)
|
ctx := NewTestEnv(t)
|
||||||
|
|
||||||
adminUser := User{
|
adminUser := ctx.createUser(user.CreateUserCommand{
|
||||||
username: "admin",
|
|
||||||
password: "admin",
|
|
||||||
}
|
|
||||||
viewerUser := User{
|
|
||||||
username: "viewer",
|
|
||||||
password: "viewer",
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleViewer),
|
|
||||||
Password: viewerUser.password,
|
|
||||||
Login: viewerUser.username,
|
|
||||||
})
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: adminUser.password,
|
Password: "admin",
|
||||||
Login: adminUser.username,
|
Login: "admin",
|
||||||
|
})
|
||||||
|
|
||||||
|
viewerUser := ctx.createUser(user.CreateUserCommand{
|
||||||
|
DefaultOrgRole: string(org.RoleViewer),
|
||||||
|
Password: "viewer",
|
||||||
|
Login: "viewer",
|
||||||
|
OrgID: adminUser.User.OrgID,
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Get all correlations", func(t *testing.T) {
|
t.Run("Get all correlations", func(t *testing.T) {
|
||||||
|
|||||||
@@ -21,31 +21,24 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx := NewTestEnv(t)
|
ctx := NewTestEnv(t)
|
||||||
|
|
||||||
adminUser := User{
|
adminUser := ctx.createUser(user.CreateUserCommand{
|
||||||
username: "admin",
|
|
||||||
password: "admin",
|
|
||||||
}
|
|
||||||
editorUser := User{
|
|
||||||
username: "editor",
|
|
||||||
password: "editor",
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleEditor),
|
|
||||||
Password: editorUser.password,
|
|
||||||
Login: editorUser.username,
|
|
||||||
})
|
|
||||||
ctx.createUser(user.CreateUserCommand{
|
|
||||||
DefaultOrgRole: string(org.RoleAdmin),
|
DefaultOrgRole: string(org.RoleAdmin),
|
||||||
Password: adminUser.password,
|
Password: "admin",
|
||||||
Login: adminUser.username,
|
Login: "admin",
|
||||||
|
})
|
||||||
|
|
||||||
|
editorUser := ctx.createUser(user.CreateUserCommand{
|
||||||
|
DefaultOrgRole: string(org.RoleEditor),
|
||||||
|
Password: "editor",
|
||||||
|
Login: "editor",
|
||||||
|
OrgID: adminUser.User.OrgID,
|
||||||
})
|
})
|
||||||
|
|
||||||
createDsCommand := &datasources.AddDataSourceCommand{
|
createDsCommand := &datasources.AddDataSourceCommand{
|
||||||
Name: "read-only",
|
Name: "read-only",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
ReadOnly: true,
|
ReadOnly: true,
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource := ctx.createDs(createDsCommand)
|
dataSource := ctx.createDs(createDsCommand)
|
||||||
readOnlyDS := dataSource.UID
|
readOnlyDS := dataSource.UID
|
||||||
@@ -53,7 +46,7 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
|
|||||||
createDsCommand = &datasources.AddDataSourceCommand{
|
createDsCommand = &datasources.AddDataSourceCommand{
|
||||||
Name: "writable",
|
Name: "writable",
|
||||||
Type: "loki",
|
Type: "loki",
|
||||||
OrgID: 1,
|
OrgID: adminUser.User.OrgID,
|
||||||
}
|
}
|
||||||
dataSource = ctx.createDs(createDsCommand)
|
dataSource = ctx.createDs(createDsCommand)
|
||||||
writableDs := dataSource.UID
|
writableDs := dataSource.UID
|
||||||
|
|||||||
Reference in New Issue
Block a user