-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vicente Zepeda Mas <[email protected]>
- Loading branch information
Showing
3 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package elastic | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_extractENVContent(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
envs map[string]string | ||
want map[string]string | ||
}{ | ||
{"manual_run", map[string]string{}, map[string]string{"buildUrl": "Manual run", "CiSystem": "Local"}}, | ||
{"has_build_url", map[string]string{"BUILD_URL": "https://test.com"}, map[string]string{"buildUrl": "https://test.com", "CiSystem": "Local"}}, | ||
{"jenkins_run", map[string]string{"BUILD_URL": "https://test.com", "JENKINS_URL": "http://jenkins.dev"}, map[string]string{"buildUrl": "https://test.com", "CiSystem": "Jenkins"}}, | ||
{"airflow_run", map[string]string{"BUILD_URL": "https://test.com", "AIRFLOW_CTX_DAG_ID": "ocm-dag"}, map[string]string{"buildUrl": "https://test.com", "CiSystem": "Airflow"}}, | ||
{"jenkins_run", map[string]string{"BUILD_URL": "https://test.com", "JENKINS_URL": "http://jenkins.dev", "AIRFLOW_CTX_DAG_ID": "ocm-dag"}, map[string]string{"buildUrl": "https://test.com", "CiSystem": "Jenkins"}}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
for key, v := range tt.envs { | ||
os.Setenv(key, v) | ||
} | ||
if got := extractENVContent(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("extractENVContent() = %v, want %v", got, tt.want) | ||
} | ||
for key := range tt.envs { | ||
os.Unsetenv(key) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// buildURL := os.Getenv("BUILD_URL") | ||
// if buildURL != "" { | ||
// result["buildUrl"] = buildURL | ||
// } else { | ||
// result["buildUrl"] = "Manual run" | ||
// } | ||
// dagID := os.Getenv("AIRFLOW_CTX_DAG_ID") | ||
// jenkinsURL := os.Getenv("JENKINS_URL") |