diff --git a/server/playbooks/server/api_actions_test.go b/server/playbooks/server/api_actions_test.go index 26ba51d31b..10672f9308 100644 --- a/server/playbooks/server/api_actions_test.go +++ b/server/playbooks/server/api_actions_test.go @@ -15,7 +15,8 @@ import ( ) func TestActionCreation(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createNewChannel := func(t *testing.T, name string) *model.Channel { @@ -200,7 +201,8 @@ func TestActionCreation(t *testing.T) { } func TestActionList(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() // Create three valid actions @@ -292,7 +294,8 @@ func TestActionList(t *testing.T) { } func TestActionUpdate(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() // Create a valid action diff --git a/server/playbooks/server/api_bot_test.go b/server/playbooks/server/api_bot_test.go index 403d5ad932..1a9f8d946b 100644 --- a/server/playbooks/server/api_bot_test.go +++ b/server/playbooks/server/api_bot_test.go @@ -13,7 +13,8 @@ import ( ) func TestTrialLicences(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("request trial license without permissions", func(t *testing.T) { diff --git a/server/playbooks/server/api_general_test.go b/server/playbooks/server/api_general_test.go index b3052eb649..380959325e 100644 --- a/server/playbooks/server/api_general_test.go +++ b/server/playbooks/server/api_general_test.go @@ -11,7 +11,8 @@ import ( ) func TestAPI(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() t.Run("404", func(t *testing.T) { diff --git a/server/playbooks/server/api_graphql_playbooks_test.go b/server/playbooks/server/api_graphql_playbooks_test.go index bcb78c08a3..8212c3dd8b 100644 --- a/server/playbooks/server/api_graphql_playbooks_test.go +++ b/server/playbooks/server/api_graphql_playbooks_test.go @@ -21,7 +21,8 @@ import ( ) func TestGraphQLPlaybooks(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("basic get", func(t *testing.T) { @@ -205,7 +206,8 @@ func TestGraphQLPlaybooks(t *testing.T) { } func TestGraphQLUpdatePlaybookFails(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("update playbook fails because size constraints.", func(t *testing.T) { @@ -368,7 +370,8 @@ func TestGraphQLUpdatePlaybookFails(t *testing.T) { } func TestUpdatePlaybookFavorite(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("favorite", func(t *testing.T) { @@ -490,7 +493,8 @@ func gqlTestPlaybookUpdate(e *TestEnvironment, t *testing.T, playbookID string, } func TestGraphQLPlaybooksMetrics(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("metrics get", func(t *testing.T) { diff --git a/server/playbooks/server/api_graphql_runs_test.go b/server/playbooks/server/api_graphql_runs_test.go index 9cbc0629e9..114706c80f 100644 --- a/server/playbooks/server/api_graphql_runs_test.go +++ b/server/playbooks/server/api_graphql_runs_test.go @@ -19,7 +19,8 @@ import ( ) func TestGraphQLRunList(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("list by participantOrFollower", func(t *testing.T) { @@ -204,7 +205,8 @@ func TestGraphQLRunList(t *testing.T) { } func TestGraphQLChangeRunParticipants(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() user3, _, err := e.ServerAdminClient.CreateUser(&model.User{ @@ -656,7 +658,8 @@ func TestGraphQLChangeRunParticipants(t *testing.T) { } func TestGraphQLChangeRunOwner(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() // create a third user to test change owner @@ -699,7 +702,8 @@ func TestGraphQLChangeRunOwner(t *testing.T) { } func TestSetRunFavorite(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createRun := func() *client.PlaybookRun { @@ -785,7 +789,8 @@ func TestSetRunFavorite(t *testing.T) { } func TestResolverFavorites(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createRun := func() *client.PlaybookRun { @@ -817,7 +822,8 @@ func TestResolverFavorites(t *testing.T) { } func TestResolverPlaybooks(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createRun := func() *client.PlaybookRun { @@ -843,7 +849,8 @@ func TestResolverPlaybooks(t *testing.T) { } func TestUpdateRun(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createRun := func() *client.PlaybookRun { @@ -959,7 +966,8 @@ func TestUpdateRun(t *testing.T) { } func TestUpdateRunTaskActions(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("task actions mutation create and update", func(t *testing.T) { @@ -1052,7 +1060,8 @@ func TestUpdateRunTaskActions(t *testing.T) { } func TestBadGraphQLRequest(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() testRunsQuery := ` diff --git a/server/playbooks/server/api_playbooks_test.go b/server/playbooks/server/api_playbooks_test.go index 957e565c0c..5752dd54cf 100644 --- a/server/playbooks/server/api_playbooks_test.go +++ b/server/playbooks/server/api_playbooks_test.go @@ -21,7 +21,8 @@ import ( ) func TestPlaybooks(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() @@ -265,7 +266,8 @@ func TestPlaybooks(t *testing.T) { } func TestCreateInvalidPlaybook(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() @@ -366,7 +368,8 @@ func TestCreateInvalidPlaybook(t *testing.T) { } func TestPlaybooksRetrieval(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("get playbook", func(t *testing.T) { @@ -383,7 +386,8 @@ func TestPlaybooksRetrieval(t *testing.T) { } func TestPlaybookUpdate(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("update playbook properties", func(t *testing.T) { @@ -516,7 +520,8 @@ func TestPlaybookUpdate(t *testing.T) { } func TestPlaybookUpdateCrossTeam(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("update playbook properties not in team public playbook", func(t *testing.T) { @@ -546,7 +551,8 @@ func TestPlaybookUpdateCrossTeam(t *testing.T) { } func TestPlaybooksSort(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() e.SetE20Licence() @@ -788,7 +794,8 @@ func TestPlaybooksSort(t *testing.T) { } func TestPlaybooksPaging(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() e.SetE20Licence() @@ -927,7 +934,8 @@ func getPlaybookIDsList(playbooks []client.Playbook) []string { } func TestPlaybooksPermissions(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("test no permissions to create", func(t *testing.T) { @@ -1139,7 +1147,8 @@ func TestPlaybooksPermissions(t *testing.T) { } func TestPlaybooksConversions(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("public to private conversion", func(t *testing.T) { @@ -1198,7 +1207,8 @@ func TestPlaybooksConversions(t *testing.T) { } func TestPlaybooksImportExport(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() e.CreateBasicPublicPlaybook() @@ -1226,7 +1236,8 @@ func TestPlaybooksImportExport(t *testing.T) { } func TestPlaybooksDuplicate(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() e.SetE20Licence() @@ -1247,7 +1258,8 @@ func TestPlaybooksDuplicate(t *testing.T) { } func TestAddPostToTimeline(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() dialogRequest := model.SubmitDialogRequest{ @@ -1294,7 +1306,8 @@ func TestAddPostToTimeline(t *testing.T) { } func TestPlaybookStats(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateClients() e.CreateBasicServer() e.SetE20Licence() @@ -1329,7 +1342,8 @@ func TestPlaybookStats(t *testing.T) { } func TestPlaybookGetAutoFollows(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() p1ID, err := e.PlaybooksAdminClient.Playbooks.Create(context.Background(), client.PlaybookCreateOptions{ @@ -1432,7 +1446,8 @@ func TestPlaybookGetAutoFollows(t *testing.T) { } func TestPlaybookChecklistCleanup(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("update playbook", func(t *testing.T) { diff --git a/server/playbooks/server/api_runs_test.go b/server/playbooks/server/api_runs_test.go index 2cac09e2b3..780c0f8bb8 100644 --- a/server/playbooks/server/api_runs_test.go +++ b/server/playbooks/server/api_runs_test.go @@ -19,7 +19,8 @@ import ( ) func TestRunCreation(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() incompletePlaybookID, err := e.PlaybooksAdminClient.Playbooks.Create(context.Background(), client.PlaybookCreateOptions{ @@ -313,7 +314,8 @@ func TestRunCreation(t *testing.T) { } func TestCreateRunInExistingChannel(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() // create playbook @@ -408,7 +410,8 @@ func TestCreateRunInExistingChannel(t *testing.T) { } func TestCreateInvalidRuns(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("fails if description is longer than 4096", func(t *testing.T) { @@ -425,7 +428,8 @@ func TestCreateInvalidRuns(t *testing.T) { } func TestRunRetrieval(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("by channel id", func(t *testing.T) { @@ -506,7 +510,8 @@ func TestRunRetrieval(t *testing.T) { } func TestRunPostStatusUpdate(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("post an update", func(t *testing.T) { @@ -566,7 +571,8 @@ func TestRunPostStatusUpdate(t *testing.T) { } func TestChecklistManagement(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() createNewRunWithNoChecklists := func(t *testing.T) *client.PlaybookRun { @@ -1182,7 +1188,8 @@ func TestChecklistManagement(t *testing.T) { } func TestChecklisFailTooLarge(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("checklist creation - failure: too large checklist", func(t *testing.T) { @@ -1206,7 +1213,8 @@ func TestChecklisFailTooLarge(t *testing.T) { } func TestRunGetStatusUpdates(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("public - get no updates", func(t *testing.T) { @@ -1335,7 +1343,8 @@ func TestRunGetStatusUpdates(t *testing.T) { } func TestRequestUpdate(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("private - no viewer access ", func(t *testing.T) { @@ -1428,7 +1437,8 @@ func TestRequestUpdate(t *testing.T) { } func TestReminderReset(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("reminder reset - timeline event created", func(t *testing.T) { @@ -1475,7 +1485,8 @@ func TestReminderReset(t *testing.T) { } func TestChecklisItem_SetAssignee(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() addSimpleChecklistToTun := func(t *testing.T, runID string) *client.PlaybookRun { @@ -1586,7 +1597,8 @@ func TestChecklisItem_SetAssignee(t *testing.T) { } func TestChecklisItem_SetCommand(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() run, err := e.PlaybooksClient.PlaybookRuns.Create(context.Background(), client.PlaybookRunCreateOptions{ @@ -1687,7 +1699,8 @@ func TestChecklisItem_SetCommand(t *testing.T) { } func TestGetOwners(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() ownerFromUser := func(u *model.User) client.OwnerInfo { diff --git a/server/playbooks/server/api_settings_test.go b/server/playbooks/server/api_settings_test.go index 4ef06b42c4..c768866469 100644 --- a/server/playbooks/server/api_settings_test.go +++ b/server/playbooks/server/api_settings_test.go @@ -14,7 +14,8 @@ import ( ) func TestSettings(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("get settings", func(t *testing.T) { diff --git a/server/playbooks/server/api_stats_test.go b/server/playbooks/server/api_stats_test.go index a005ca7212..068c8979a6 100644 --- a/server/playbooks/server/api_stats_test.go +++ b/server/playbooks/server/api_stats_test.go @@ -16,7 +16,8 @@ import ( ) func TestGetSiteStats(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("get sites stats", func(t *testing.T) { @@ -49,7 +50,8 @@ func TestGetSiteStats(t *testing.T) { } func TestPlaybookKeyMetricsStats(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("3 runs with published metrics, 2 runs without publishing", func(t *testing.T) { diff --git a/server/playbooks/server/api_telemetry_test.go b/server/playbooks/server/api_telemetry_test.go index 7a3c9ab10f..ad7cfb11e9 100644 --- a/server/playbooks/server/api_telemetry_test.go +++ b/server/playbooks/server/api_telemetry_test.go @@ -11,7 +11,8 @@ import ( ) func TestCreateEvent(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() t.Run("create an event with bad type fails", func(t *testing.T) { diff --git a/server/playbooks/server/main_test.go b/server/playbooks/server/main_test.go index 3b49bc6653..c0202a5c3e 100644 --- a/server/playbooks/server/main_test.go +++ b/server/playbooks/server/main_test.go @@ -97,7 +97,7 @@ func getEnvWithDefault(name, defaultValue string) string { return defaultValue } -func Setup(t *testing.T) *TestEnvironment { +func Setup(t *testing.T) (*TestEnvironment, func()) { // Ignore any locally defined SiteURL as we intend to host our own. os.Unsetenv("MM_SERVICESETTINGS_SITEURL") os.Unsetenv("MM_SERVICESETTINGS_LISTENADDRESS") @@ -121,6 +121,7 @@ func Setup(t *testing.T) *TestEnvironment { config.LogSettings.ConsoleLevel = model.NewString("INFO") // disable Boards through the feature flag + boardsProductEnvValue := os.Getenv("MM_FEATUREFLAGS_BoardsProduct") os.Unsetenv("MM_FEATUREFLAGS_BoardsProduct") config.FeatureFlags.BoardsProduct = false @@ -162,6 +163,10 @@ func Setup(t *testing.T) *TestEnvironment { ap := sapp.New(sapp.ServerConnector(server.Channels())) + teardown := func() { + os.Setenv("MM_FEATUREFLAGS_BoardsProduct", boardsProductEnvValue) + } + return &TestEnvironment{ T: t, Srv: server, @@ -173,7 +178,7 @@ func Setup(t *testing.T) *TestEnvironment { }, }, logger: testLogger, - } + }, teardown } func (e *TestEnvironment) CreateClients() { @@ -467,7 +472,8 @@ func (e *TestEnvironment) CreateBasic() { // TestTestFramework If this is failing you know the break is not exclusively in your test. func TestTestFramework(t *testing.T) { - e := Setup(t) + e, teardown := Setup(t) + defer teardown() e.CreateBasic() }