Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create html_reports directory [CI-2177] #889

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions configs/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const (
BitrisePerStepTestResultDirEnvKey = "BITRISE_TEST_RESULT_DIR"
// BitriseTmpDirEnvKey ...
BitriseTmpDirEnvKey = "BITRISE_TMP_DIR"
// BitriseHtmlReportDirEnvKey ...
BitriseHtmlReportDirEnvKey = "BITRISE_HTML_REPORT_DIR"
)

// GetBitriseHomeDirPath ...
Expand Down Expand Up @@ -173,22 +175,34 @@ func InitPaths() error {
}

if err := os.Setenv(BitriseDeployDirEnvKey, deployDir); err != nil {
return fmt.Errorf("Failed to set BITRISE_DEPLOY_DIR, error: %s", err)
return fmt.Errorf("Failed to set %s, error: %s", BitriseDeployDirEnvKey, err)
}
}

// BITRISE_TEST_RESULTS_DIR
if os.Getenv(BitriseTestDeployDirEnvKey) == "" {
testsDir, err := pathutil.NormalizedOSTempDirPath("test_results")
if err != nil {
return fmt.Errorf("Failed to set deploy dir, error: %s", err)
return fmt.Errorf("Failed to set test_results dir, error: %s", err)
}

if err := os.Setenv(BitriseTestDeployDirEnvKey, testsDir); err != nil {
return fmt.Errorf("Failed to set %s, error: %s", BitriseTestDeployDirEnvKey, err)
}
}

// BITRISE_HTML_REPORT_DIR
if os.Getenv(BitriseHtmlReportDirEnvKey) == "" {
htmlReportDir, err := pathutil.NormalizedOSTempDirPath("html_reports")
if err != nil {
return fmt.Errorf("Failed to set html_reports dir, error: %s", err)
}

if err := os.Setenv(BitriseHtmlReportDirEnvKey, htmlReportDir); err != nil {
return fmt.Errorf("Failed to set %s, error: %s", BitriseHtmlReportDirEnvKey, err)
}
}

//BITRISE_TMP_DIR
if os.Getenv(BitriseTmpDirEnvKey) == "" {
tmpDir, err := pathutil.NormalizedOSTempDirPath("tmp")
Expand Down
60 changes: 18 additions & 42 deletions configs/paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,56 +49,32 @@ func TestInitPaths(t *testing.T) {
if os.Getenv(BitriseSourceDirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(BitriseSourceDirEnvKey))
}
require.Equal(t, nil, InitPaths())
require.NoError(t, InitPaths())
require.Equal(t, CurrentDir, os.Getenv(BitriseSourceDirEnvKey))

// Set BITRISE_SOURCE_DIR -> after InitPaths BITRISE_SOURCE_DIR should keep content
t.Setenv(BitriseSourceDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseSourceDirEnvKey))

//
// BITRISE_DEPLOY_DIR
testTempDirectoryWithEnvVar(t, BitriseDeployDirEnvKey)

// Unset BITRISE_DEPLOY_DIR -> after InitPaths BITRISE_DEPLOY_DIR should be temp dir
if os.Getenv(BitriseDeployDirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(BitriseDeployDirEnvKey))
}
require.Equal(t, nil, InitPaths())
require.NotEqual(t, "", os.Getenv(BitriseDeployDirEnvKey))

// Set BITRISE_DEPLOY_DIR -> after InitPaths BITRISE_DEPLOY_DIR should keep content
t.Setenv(BitriseDeployDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseDeployDirEnvKey))

//
// BITRISE_TEST_DEPLOY_DIR
testTempDirectoryWithEnvVar(t, BitriseTestDeployDirEnvKey)

// Unset BITRISE_TEST_DEPLOY_DIR -> after InitPaths BITRISE_TEST_DEPLOY_DIR should be temp dir
if os.Getenv(BitriseTestDeployDirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(BitriseTestDeployDirEnvKey))
}
require.Equal(t, nil, InitPaths())
require.NotEqual(t, "", os.Getenv(BitriseTestDeployDirEnvKey))

// Set BITRISE_TEST_DEPLOY_DIR -> after InitPaths BITRISE_TEST_DEPLOY_DIR should keep content
t.Setenv(BitriseTestDeployDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseTestDeployDirEnvKey))

//
// BITRISE_TMP_DIR
testTempDirectoryWithEnvVar(t, BitriseTmpDirEnvKey)

// BITRISE_HTML_REPORT_DIR
testTempDirectoryWithEnvVar(t, BitriseHtmlReportDirEnvKey)
}

// Unset BITRISE_TMP_DIR -> after InitPaths BITRISE_TMP_DIR should be temp dir
if os.Getenv(BitriseTmpDirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(BitriseTmpDirEnvKey))
func testTempDirectoryWithEnvVar(t *testing.T, dirEnvKey string) {
// Unset env var -> after InitPaths env var should be a temp dir
if os.Getenv(dirEnvKey) != "" {
require.Equal(t, nil, os.Unsetenv(dirEnvKey))
}
require.Equal(t, nil, InitPaths())
require.NotEqual(t, "", os.Getenv(BitriseTmpDirEnvKey))
require.NoError(t, InitPaths())
require.NotEqual(t, "", os.Getenv(dirEnvKey))

// Set BITRISE_TMP_DIR -> after InitPaths BITRISE_TMP_DIR should keep content
t.Setenv(BitriseTmpDirEnvKey, "$HOME/test")
require.Equal(t, nil, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(BitriseTmpDirEnvKey))
// Set dirEnvKey -> after InitPaths dirEnvKey should keep content
t.Setenv(dirEnvKey, "$HOME/test")
require.NoError(t, InitPaths())
require.Equal(t, "$HOME/test", os.Getenv(dirEnvKey))
}