From ff160a4d3291589c6a51842ecd634270c1bcbb36 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Thu, 17 Oct 2019 09:55:02 -0300 Subject: [PATCH] MM-19048: avoid error spam during CI builds (#12626) Detect the IS_CI flag and skip trying to rewrite subpaths that won't necessarily exist. --- utils/subpath.go | 6 ++++++ utils/subpath_test.go | 42 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/utils/subpath.go b/utils/subpath.go index 9bb75db3de..14c1ea6f69 100644 --- a/utils/subpath.go +++ b/utils/subpath.go @@ -148,6 +148,12 @@ func UpdateAssetsSubpathFromConfig(config *model.Config) error { return nil } + // Similarly, don't rewrite during a CI build, when the assets may not even be present. + if os.Getenv("IS_CI") == "true" { + mlog.Debug("Skipping update to assets subpath since CI build") + return nil + } + subpath, err := GetSubpathFromConfig(config) if err != nil { return err diff --git a/utils/subpath_test.go b/utils/subpath_test.go index aa6fbe7b98..0c76bd7368 100644 --- a/utils/subpath_test.go +++ b/utils/subpath_test.go @@ -14,6 +14,40 @@ import ( "github.com/mattermost/mattermost-server/utils" ) +func TestUpdateAssetsSubpathFromConfig(t *testing.T) { + t.Run("dev build", func(t *testing.T) { + var oldBuildNumber = model.BuildNumber + model.BuildNumber = "dev" + defer func() { + model.BuildNumber = oldBuildNumber + }() + + err := utils.UpdateAssetsSubpathFromConfig(nil) + require.NoError(t, err) + }) + + t.Run("IS_CI=true", func(t *testing.T) { + err := os.Setenv("IS_CI", "true") + require.NoError(t, err) + defer func() { + os.Unsetenv("IS_CI") + }() + + err = utils.UpdateAssetsSubpathFromConfig(nil) + require.NoError(t, err) + }) + + t.Run("no config", func(t *testing.T) { + tempDir, err := ioutil.TempDir("", "test_update_assets_subpath") + require.NoError(t, err) + defer os.RemoveAll(tempDir) + os.Chdir(tempDir) + + err = utils.UpdateAssetsSubpathFromConfig(nil) + require.Error(t, err) + }) +} + func TestUpdateAssetsSubpath(t *testing.T) { t.Run("no client dir", func(t *testing.T) { tempDir, err := ioutil.TempDir("", "test_update_assets_subpath") @@ -157,10 +191,6 @@ func TestUpdateAssetsSubpath(t *testing.T) { } func TestGetSubpathFromConfig(t *testing.T) { - sToP := func(s string) *string { - return &s - } - testCases := []struct { Description string SiteURL *string @@ -231,6 +261,10 @@ func TestGetSubpathFromConfig(t *testing.T) { } } +func sToP(s string) *string { + return &s +} + const contentSecurityPolicyNotFoundHtml = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


` const contentSecurityPolicyNotFound2Html = ` Mattermost

Cannot connect to Mattermost


We're having trouble connecting to Mattermost. If refreshing this page (Ctrl+R or Command+R) does not work, please verify that your computer is connected to the internet.


`