Exemple #1
0
func TestStepOutputsInTemplate(t *testing.T) {
	inventoryStr := `
envs:
- TEMPLATE_TEST0: "true"
`
	inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - TEMPLATE_TEST1: "true"

workflows:
  test:
    envs:
    - TEMPLATE_TEST2: "true"
    steps:
    - script:
        title: "Envman add"
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key TEMPLATE_TEST3 --value "true"
    - script:
        title: "TEMPLATE_TEST0"
        run_if: |-
          {{enveq "TEMPLATE_TEST0" "true"}}
    - script:
        title: "TEMPLATE_TEST1"
        run_if: |-
          {{enveq "TEMPLATE_TEST1" "true"}}
    - script:
        title: "TEMPLATE_TEST2"
        run_if: |-
          {{enveq "TEMPLATE_TEST2" "true"}}
    - script:
        title: "TEMPLATE_TEST3"
        run_if: |-
          {{enveq "TEMPLATE_TEST3" "true"}}
    - script:
        title: "TEMPLATE_TEST_NO_VALUE"
        run_if: |-
          {{enveq "TEMPLATE_TEST_NO_VALUE" "true"}}

`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	buildRunResults, err := runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)
	require.Equal(t, 5, len(buildRunResults.SuccessSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSteps))
	require.Equal(t, 0, len(buildRunResults.FailedSkippableSteps))
	require.Equal(t, 1, len(buildRunResults.SkippedSteps))
}
Exemple #2
0
// GetInventoryFromBase64Data ...
func GetInventoryFromBase64Data(inventoryBase64Str string) ([]envmanModels.EnvironmentItemModel, error) {
	inventoryBase64Bytes, err := base64.StdEncoding.DecodeString(inventoryBase64Str)
	if err != nil {
		return []envmanModels.EnvironmentItemModel{}, fmt.Errorf("Failed to decode base 64 string, error: %s", err)
	}

	inventory, err := bitrise.InventoryModelFromYAMLBytes(inventoryBase64Bytes)
	if err != nil {
		return []envmanModels.EnvironmentItemModel{}, err
	}

	return inventory.Envs, nil
}
Exemple #3
0
func TestIsCIMode(t *testing.T) {
	ciModeEnv := os.Getenv(configs.CIModeEnvKey)

	defer func() {
		require.NoError(t, os.Setenv(configs.CIModeEnvKey, ciModeEnv))
	}()

	t.Log("Should be false for: ciGlobalFlag: nil, ciModeEnv: 'false'")
	{
		require.NoError(t, os.Setenv(configs.CIModeEnvKey, "false"))

		ci, err := isCIMode(nil, []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, false, ci)
	}

	t.Log("Should be false for: ciGlobalFlag: false, ciModeEnv: 'false' secrets: false")
	{
		inventoryStr := `
envs:
- CI: "false"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.CIModeEnvKey, "false"))

		ci, err := isCIMode(pointers.NewBoolPtr(false), inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, false, ci)
	}

	t.Log("Should be true for: ciGlobalFlag: true, ciModeEnv: 'false'")
	{
		require.NoError(t, os.Setenv(configs.CIModeEnvKey, ""))

		ci, err := isCIMode(pointers.NewBoolPtr(true), []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, true, ci)
	}

	t.Log("Should be true for: ciGlobalFlag: true, ciModeEnv: '' secrets: false")
	{
		inventoryStr := `
envs:
- CI: "false"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.CIModeEnvKey, ""))

		ci, err := isCIMode(pointers.NewBoolPtr(true), inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, ci)
	}

	t.Log("Should be true for: ciGlobalFlag: nil, ciModeEnv: 'true' secrets: false")
	{
		inventoryStr := `
envs:
- CI: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.CIModeEnvKey, "true"))

		ci, err := isCIMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, ci)
	}

	t.Log("Should be true for: ciGlobalFlag: nil, ciModeEnv: '' secrets: true")
	{
		inventoryStr := `
envs:
- CI: "true"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.CIModeEnvKey, ""))

		ci, err := isCIMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, ci)
	}
}
Exemple #4
0
func TestIsPRMode(t *testing.T) {
	prModeEnv := os.Getenv(configs.PRModeEnvKey)
	prIDEnv := os.Getenv(configs.PullRequestIDEnvKey)

	// cleanup Envs after these tests
	defer func() {
		require.NoError(t, os.Setenv(configs.PRModeEnvKey, prModeEnv))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, prIDEnv))
	}()

	t.Log("Should be false for: prGlobalFlag: nil, prModeEnv: '', prIDEnv: ''")
	{
		require.NoError(t, os.Setenv(configs.PRModeEnvKey, ""))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, false, pr)
	}

	t.Log("Should be false for: prGlobalFlag: nil, prModeEnv: '', prIDEnv: '', secrets: false")
	{
		inventoryStr := `
envs:
- PR: "false"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, ""))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, false, pr)
	}

	t.Log("Should be false for: prGlobalFlag: nil, prModeEnv: 'false', prIDEnv: '', secrets: ''")
	{
		inventoryStr := `
envs:
- PR: ""
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "false"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, false, pr)
	}

	t.Log("Should be false for: prGlobalFlag: false, prModeEnv: 'true', prIDEnv: 'ID', secrets: 'true'")
	{
		inventoryStr := `
envs:
- PR: "true"
- PULL_REQUEST_ID: "ID"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "true"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, "ID"))

		pr, err := isPRMode(pointers.NewBoolPtr(false), inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, false, pr)
	}

	t.Log("Should be true for: prGlobalFlag: true, prModeEnv: '', prIDEnv: ''")
	{
		require.NoError(t, os.Setenv(configs.PRModeEnvKey, ""))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(pointers.NewBoolPtr(true), []envmanModels.EnvironmentItemModel{})
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: true, prModeEnv: '', prIDEnv: '', secrets: false")
	{
		inventoryStr := `
envs:
- PR: "false"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, ""))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(pointers.NewBoolPtr(true), inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: nil, prModeEnv: 'true', prIDEnv: '', secrets: false")
	{
		inventoryStr := `
envs:
- PR: "false"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "true"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: nil, prModeEnv: 'false', prIDEnv: 'some', secrets: false")
	{
		inventoryStr := `
envs:
- PR: "false"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "false"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, "some"))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: nil, prModeEnv: '', prIDEnv: '', secrets: true")
	{
		inventoryStr := `
envs:
- PR: "true"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, ""))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: nil, prModeEnv: 'false', prIDEnv: '', secrets: true")
	{
		inventoryStr := `
envs:
- PR: ""
- PULL_REQUEST_ID: "some"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "false"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(nil, inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}

	t.Log("Should be true for: prGlobalFlag: true, prModeEnv: 'false', prIDEnv: '', secrets: false")
	{
		inventoryStr := `
envs:
- PR: "false"
- PULL_REQUEST_ID: ""
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		require.NoError(t, os.Setenv(configs.PRModeEnvKey, "false"))
		require.NoError(t, os.Setenv(configs.PullRequestIDEnvKey, ""))

		pr, err := isPRMode(pointers.NewBoolPtr(true), inventory.Envs)
		require.NoError(t, err)
		require.Equal(t, true, pr)
	}
}
Exemple #5
0
func TestEnvOrders(t *testing.T) {
	t.Log("Only secret env - secret env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
            if [[ "$ENV_ORDER_TEST" != "should be the 1." ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env also defined - app env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - ENV_ORDER_TEST: "should be the 2."

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
            if [[ "$ENV_ORDER_TEST" != "should be the 2." ]] ; then
              exit 1
            fi

`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env && workflow env also defined - workflow env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - ENV_ORDER_TEST: "should be the 2."

workflows:
  test:
    envs:
    - ENV_ORDER_TEST: "should be the 3."
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
            if [[ "$ENV_ORDER_TEST" != "should be the 3." ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("Secret env & app env && workflow env && step output env also defined - step output env should be use")
	{
		inventoryStr := `
envs:
- ENV_ORDER_TEST: "should be the 1."
`

		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - ENV_ORDER_TEST: "should be the 2."

workflows:
  test:
    envs:
    - ENV_ORDER_TEST: "should be the 3."
    steps:
    - script:
        inputs:
        - content: envman add --key ENV_ORDER_TEST --value "should be the 4."
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "ENV_ORDER_TEST: $ENV_ORDER_TEST"
            if [[ "$ENV_ORDER_TEST" != "should be the 4." ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}
}
Exemple #6
0
func TestBitriseSourceDir(t *testing.T) {
	currPth, err := pathutil.NormalizedOSTempDirPath("bitrise_source_dir_test")
	require.NoError(t, err)

	testPths := []string{}
	for i := 0; i < 4; i++ {
		testPth := filepath.Join(currPth, fmt.Sprintf("_test%d", i))
		require.NoError(t, os.RemoveAll(testPth))
		require.NoError(t, os.Mkdir(testPth, 0777))

		// eval symlinks: the Go generated temp folder on OS X is a symlink
		//  from /var/ to /private/var/
		testPth, err = filepath.EvalSymlinks(testPth)
		require.NoError(t, err)

		defer func() { require.NoError(t, os.RemoveAll(testPth)) }()

		testPths = append(testPths, testPth)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              exit 1
            fi
`
		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret, and in App")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[1] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in Secret, App and Workflow")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[2] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}

	t.Log("BITRISE_SOURCE_DIR defined in secret, App, Workflow and Step")
	{
		inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
		inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
		require.NoError(t, err)

		configStr := `
format_version: 1.3.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key BITRISE_SOURCE_DIR --value ` + testPths[3] + `
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[3] + `" ]] ; then
              exit 1
            fi
`

		require.NoError(t, configs.InitPaths())

		config, warnings, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
		require.NoError(t, err)
		require.Equal(t, 0, len(warnings))

		_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
		require.NoError(t, err)
	}
}
Exemple #7
0
func TestBitriseSourceDir(t *testing.T) {
	currPth, err := pathutil.NormalizedOSTempDirPath("bitrise_source_dir_test")
	if err != nil {
		t.Fatal("Failed to get curr abs path: ", err)
	}

	testPths := []string{}
	for i := 0; i < 4; i++ {
		testPth := path.Join(currPth, fmt.Sprintf("_test%d", i))
		if err := os.RemoveAll(testPth); err != nil {
			t.Fatalf("Failed to remove %s, err: %s: ", testPth, err)
		}

		err := os.Mkdir(testPth, 0777)
		if err != nil {
			t.Fatalf("Failed to create %s, err: %s: ", testPth, err)
		}
		// eval symlinks: the Go generated temp folder on OS X is a symlink
		//  from /var/ to /private/var/
		testPth, err = filepath.EvalSymlinks(testPth)
		if err != nil {
			t.Fatalf("Failed to EvalSymlinks for (path:%s), err: %s", testPth, err)
		}

		defer func() {
			err := os.RemoveAll(testPth)
			if err != nil {
				t.Fatalf("Failed to remove %s, err: %s: ", testPth, err)
			}
		}()

		testPths = append(testPths, testPth)
	}

	//
	// BITRISE_SOURCE_DIR defined in Secret
	inventoryStr := `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err := bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr := `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              exit 1
            fi
`
	config, err := bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, and in App
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[1] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, App and Workflow
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[2] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in Secret, App and Workflow
	//  BUT the value is empty in Workflow and App Envs - Secrets should be used!
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR:

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: ""
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[0] + `" ]] ; then
              echo "-> BITRISE_SOURCE_DIR missmatch!"
              exit 1
            fi
            curr_pwd="$(pwd)"
            if [[ "${curr_pwd}" != "` + testPths[0] + `" ]] ; then
              echo "-> pwd missmatch! : curr_pwd : ${curr_pwd}"
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)

	//
	// BITRISE_SOURCE_DIR defined in secret, App, Workflow and Step
	inventoryStr = `
envs:
- BITRISE_SOURCE_DIR: "` + testPths[0] + `"
`
	inventory, err = bitrise.InventoryModelFromYAMLBytes([]byte(inventoryStr))
	require.Equal(t, nil, err)

	configStr = `
format_version: 1.0.0
default_step_lib_source: "https://github.com/bitrise-io/bitrise-steplib.git"

app:
  envs:
  - BITRISE_SOURCE_DIR: "` + testPths[1] + `"

workflows:
  test:
    envs:
    - BITRISE_SOURCE_DIR: "` + testPths[2] + `"
    steps:
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            envman add --key BITRISE_SOURCE_DIR --value ` + testPths[3] + `
    - script:
        inputs:
        - content: |
            #!/bin/bash
            set -v
            echo "BITRISE_SOURCE_DIR: $BITRISE_SOURCE_DIR"
            if [[ "$BITRISE_SOURCE_DIR" != "` + testPths[3] + `" ]] ; then
              exit 1
            fi
`
	config, err = bitrise.ConfigModelFromYAMLBytes([]byte(configStr))
	require.Equal(t, nil, err)

	_, err = runWorkflowWithConfiguration(time.Now(), "test", config, inventory.Envs)
	require.Equal(t, nil, err)
}