[9.4.x] Correlations: Fix flaky integration tests (#64004) (#64139)

Correlations: Fix flaky integration tests (#64004)

* Correlations: Fix flaky integration tests

* set explore-squad as correlations tests code owners

(cherry picked from commit 4a7fbea7a4)
This commit is contained in:
Giordano Ricci
2023-03-03 14:06:59 +00:00
committed by GitHub
parent 9ef2e8d7da
commit bdf8b7531b
6 changed files with 57 additions and 79 deletions
+10 -5
View File
@@ -43,7 +43,7 @@ func NewTestEnv(t *testing.T) TestContext {
}
type User struct {
username string
User user.User
password string
}
@@ -121,8 +121,8 @@ func (c TestContext) getURL(url string, user User) string {
c.t.Helper()
baseUrl := fmt.Sprintf("http://%s", c.env.Server.HTTPServer.Listener.Addr())
if user.username != "" && user.password != "" {
baseUrl = fmt.Sprintf("http://%s:%s@%s", user.username, user.password, c.env.Server.HTTPServer.Listener.Addr())
if user.User.Login != "" && user.password != "" {
baseUrl = fmt.Sprintf("http://%s:%s@%s", user.User.Login, user.password, c.env.Server.HTTPServer.Listener.Addr())
}
return fmt.Sprintf(
@@ -132,7 +132,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()
store := c.env.SQLStore
store.Cfg.AutoAssignOrg = true
@@ -144,8 +144,13 @@ func (c TestContext) createUser(cmd user.CreateUserCommand) {
usrSvc, err := userimpl.ProvideService(store, orgService, store.Cfg, nil, nil, quotaService)
require.NoError(c.t, err)
_, err = usrSvc.CreateUserForTests(context.Background(), &cmd)
user, err := usrSvc.CreateUserForTests(context.Background(), &cmd)
require.NoError(c.t, err)
return User{
User: *user,
password: cmd.Password,
}
}
func (c TestContext) createDs(cmd *datasources.AddDataSourceCommand) {
@@ -21,31 +21,24 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
}
ctx := NewTestEnv(t)
adminUser := User{
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{
adminUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: adminUser.password,
Login: adminUser.username,
Password: "admin",
Login: "admin",
})
editorUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleEditor),
Password: "editor",
Login: "editor",
OrgID: adminUser.User.OrgID,
})
createDsCommand := &datasources.AddDataSourceCommand{
Name: "read-only",
Type: "loki",
ReadOnly: true,
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
readOnlyDS := createDsCommand.Result.Uid
@@ -53,7 +46,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
createDsCommand = &datasources.AddDataSourceCommand{
Name: "writable",
Type: "loki",
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
writableDs := createDsCommand.Result.Uid
@@ -21,31 +21,24 @@ func TestIntegrationDeleteCorrelation(t *testing.T) {
}
ctx := NewTestEnv(t)
adminUser := User{
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{
adminUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: adminUser.password,
Login: adminUser.username,
Password: "admin",
Login: "admin",
})
editorUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleEditor),
Password: "editor",
Login: "editor",
OrgID: adminUser.User.OrgID,
})
createDsCommand := &datasources.AddDataSourceCommand{
Name: "read-only",
Type: "loki",
ReadOnly: true,
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
readOnlyDS := createDsCommand.Result.Uid
@@ -53,7 +46,7 @@ func TestIntegrationDeleteCorrelation(t *testing.T) {
createDsCommand = &datasources.AddDataSourceCommand{
Name: "writable",
Type: "loki",
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
writableDs := createDsCommand.Result.Uid
@@ -23,24 +23,17 @@ func TestIntegrationReadCorrelation(t *testing.T) {
}
ctx := NewTestEnv(t)
adminUser := User{
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{
adminUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: adminUser.password,
Login: adminUser.username,
Password: "admin",
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) {
@@ -21,31 +21,24 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
}
ctx := NewTestEnv(t)
adminUser := User{
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{
adminUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleAdmin),
Password: adminUser.password,
Login: adminUser.username,
Password: "admin",
Login: "admin",
})
editorUser := ctx.createUser(user.CreateUserCommand{
DefaultOrgRole: string(org.RoleEditor),
Password: "editor",
Login: "editor",
OrgID: adminUser.User.OrgID,
})
createDsCommand := &datasources.AddDataSourceCommand{
Name: "read-only",
Type: "loki",
ReadOnly: true,
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
readOnlyDS := createDsCommand.Result.Uid
@@ -53,7 +46,7 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
createDsCommand = &datasources.AddDataSourceCommand{
Name: "writable",
Type: "loki",
OrgId: 1,
OrgId: adminUser.User.OrgID,
}
ctx.createDs(createDsCommand)
writableDs := createDsCommand.Result.Uid