Skip to content

Commit 57d73ee

Browse files
committed
\o/ tests
1 parent 4edfd16 commit 57d73ee

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

controllers/credentials_secret.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package controllers
22

33
import (
44
"fmt"
5+
"net/url"
6+
57
"github.com/digitalocean/godo"
68
corev1 "k8s.io/api/core/v1"
79
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8-
"net/url"
910
"sigs.k8s.io/controller-runtime/pkg/client"
1011
)
1112

controllers/databaseuser_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"fmt"
5+
46
"github.com/digitalocean/do-operator/api/v1alpha1"
57
. "github.com/onsi/ginkgo"
68
. "github.com/onsi/gomega"
@@ -89,6 +91,8 @@ var _ = Describe("DatabaseUser controller", func() {
8991
Expect(secret.OwnerReferences).To(ContainElement(dbUserOwnerReference))
9092
Expect(string(secret.Data["username"])).To(Equal(userName))
9193
Expect(secret.Data["password"]).NotTo(BeEmpty())
94+
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
95+
Expect(string(secret.Data["private_uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@private-host:12345/private-database?sslmode=require", secret.Data["username"], secret.Data["password"])))
9296
})
9397

9498
By("deleting the DatabaseUser object", func() {
@@ -184,6 +188,8 @@ var _ = Describe("DatabaseUser controller", func() {
184188
Expect(secret.OwnerReferences).To(ContainElement(dbUserOwnerReference))
185189
Expect(string(secret.Data["username"])).To(Equal(userName))
186190
Expect(secret.Data["password"]).NotTo(BeEmpty())
191+
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
192+
Expect(string(secret.Data["private_uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@private-host:12345/private-database?sslmode=require", secret.Data["username"], secret.Data["password"])))
187193
})
188194

189195
By("deleting the DatabaseUser object", func() {

controllers/databaseuserreference_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package controllers
22

33
import (
4+
"fmt"
5+
46
"github.com/digitalocean/do-operator/api/v1alpha1"
57
. "github.com/onsi/ginkgo"
68
. "github.com/onsi/gomega"
@@ -83,6 +85,8 @@ var _ = Describe("DatabaseUserReference controller", func() {
8385
Expect(secret.OwnerReferences).To(ContainElement(dbUserRefOwnerReference))
8486
Expect(string(secret.Data["username"])).To(Equal(userName))
8587
Expect(secret.Data["password"]).NotTo(BeEmpty())
88+
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
89+
Expect(string(secret.Data["private_uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@private-host:12345/private-database?sslmode=require", secret.Data["username"], secret.Data["password"])))
8690
})
8791

8892
By("deleting the DatabaseUserReference object", func() {
@@ -172,6 +176,8 @@ var _ = Describe("DatabaseUserReference controller", func() {
172176
Expect(secret.OwnerReferences).To(ContainElement(dbUserRefOwnerReference))
173177
Expect(string(secret.Data["username"])).To(Equal(userName))
174178
Expect(secret.Data["password"]).NotTo(BeEmpty())
179+
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
180+
Expect(string(secret.Data["private_uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@private-host:12345/private-database?sslmode=require", secret.Data["username"], secret.Data["password"])))
175181
})
176182

177183
By("deleting the DatabaseUserReference object", func() {

fakegodo/databases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (f *FakeDatabasesService) Create(_ context.Context, req *godo.DatabaseCreat
9090
RegionSlug: req.Region,
9191
CreatedAt: time.Now(),
9292
Connection: &godo.DatabaseConnection{
93-
URI: "uri",
93+
URI: "postgresql://user:password@host:12345/database?sslmode=require",
9494
Database: "database",
9595
Host: "host",
9696
Port: 12345,
@@ -99,7 +99,7 @@ func (f *FakeDatabasesService) Create(_ context.Context, req *godo.DatabaseCreat
9999
SSL: true,
100100
},
101101
PrivateConnection: &godo.DatabaseConnection{
102-
URI: "private-uri",
102+
URI: "postgresql://private-user:private-password@private-host:12345/private-database?sslmode=require",
103103
Database: "private-database",
104104
Host: "private_host",
105105
Port: 12345,

0 commit comments

Comments
 (0)