Skip to content

Commit

Permalink
Merge pull request #5 from opendevstack/task/expose-postgres-envs-in-…
Browse files Browse the repository at this point in the history
…step

Expose Postgres env vars to step as well
  • Loading branch information
michaelsauter committed Oct 11, 2023
2 parents 2992891 + c5d8e8b commit 92385f4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
8 changes: 8 additions & 0 deletions build/tasks/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ spec:
secretKeyRef:
key: password
name: ods-nexus-auth
{{- if .PostgresSidecar }}
- name: POSTGRES_PASSWORD
value: $(params.postgres-password)
- name: POSTGRES_USER
value: $(params.postgres-user)
- name: POSTGRES_DB
value: $(params.postgres-db)
{{- end }}
resources:
{}
script: |
Expand Down
6 changes: 6 additions & 0 deletions tasks/build-with-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ spec:
secretKeyRef:
key: password
name: ods-nexus-auth
- name: POSTGRES_PASSWORD
value: $(params.postgres-password)
- name: POSTGRES_USER
value: $(params.postgres-user)
- name: POSTGRES_DB
value: $(params.postgres-db)
resources:
{}
script: |
Expand Down
18 changes: 17 additions & 1 deletion test/e2e/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
)

func TestBuildGradleTask(t *testing.T) {
if err := runTask(
if err := ttr.RunTask(
ttr.InNamespace(namespaceConfig.Name),
ttr.UsingTask("ods-pipeline-gradle-build"),
ttr.WithStringParams(map[string]string{
"cache-build": "false",
}),
Expand Down Expand Up @@ -43,6 +45,20 @@ func TestBuildGradleTask(t *testing.T) {
}
}

func TestBuildGradleWithPostgresTask(t *testing.T) {
if err := ttr.RunTask(
ttr.InNamespace(namespaceConfig.Name),
ttr.UsingTask("ods-pipeline-gradle-build-with-postgres"),
ttr.WithStringParams(map[string]string{
"cache-build": "false",
"postgres-password": "s3cr3t",
}),
ott.WithGitSourceWorkspace(t, "../testdata/workspaces/gradle-sample-app", namespaceConfig.Name),
); err != nil {
t.Fatal(err)
}
}

func logContains(t *testing.T, logs bytes.Buffer, wantLogMsgs ...string) {
t.Helper()
for _, msg := range wantLogMsgs {
Expand Down
14 changes: 6 additions & 8 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
var (
namespaceConfig *ttr.NamespaceConfig
rootPath = "../.."
taskName = "ods-pipeline-gradle-build"
)

func TestMain(m *testing.M) {
Expand All @@ -38,6 +37,12 @@ func testMain(m *testing.M) int {
filepath.Join(rootPath, "build/tasks/build.yaml"),
nil,
),
ttr.InstallTaskFromPath(
filepath.Join(rootPath, "build/tasks/build.yaml"),
map[string]string{
"PostgresSidecar": "true",
},
),
)
if err != nil {
log.Fatal("Could not setup temporary namespace: ", err)
Expand All @@ -46,10 +51,3 @@ func testMain(m *testing.M) int {
namespaceConfig = nc
return m.Run()
}

func runTask(opts ...ttr.TaskRunOpt) error {
return ttr.RunTask(append([]ttr.TaskRunOpt{
ttr.InNamespace(namespaceConfig.Name),
ttr.UsingTask(taskName),
}, opts...)...)
}

0 comments on commit 92385f4

Please sign in to comment.