Skip to content

Commit

Permalink
\o/ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
halkeye committed Feb 22, 2024
1 parent 4edfd16 commit 57d73ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion controllers/credentials_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package controllers

import (
"fmt"
"net/url"

"github.com/digitalocean/godo"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/url"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down
6 changes: 6 additions & 0 deletions controllers/databaseuser_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controllers

import (
"fmt"

"github.com/digitalocean/do-operator/api/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -89,6 +91,8 @@ var _ = Describe("DatabaseUser controller", func() {
Expect(secret.OwnerReferences).To(ContainElement(dbUserOwnerReference))
Expect(string(secret.Data["username"])).To(Equal(userName))
Expect(secret.Data["password"]).NotTo(BeEmpty())
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
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"])))
})

By("deleting the DatabaseUser object", func() {
Expand Down Expand Up @@ -184,6 +188,8 @@ var _ = Describe("DatabaseUser controller", func() {
Expect(secret.OwnerReferences).To(ContainElement(dbUserOwnerReference))
Expect(string(secret.Data["username"])).To(Equal(userName))
Expect(secret.Data["password"]).NotTo(BeEmpty())
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
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"])))
})

By("deleting the DatabaseUser object", func() {
Expand Down
6 changes: 6 additions & 0 deletions controllers/databaseuserreference_controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controllers

import (
"fmt"

"github.com/digitalocean/do-operator/api/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -83,6 +85,8 @@ var _ = Describe("DatabaseUserReference controller", func() {
Expect(secret.OwnerReferences).To(ContainElement(dbUserRefOwnerReference))
Expect(string(secret.Data["username"])).To(Equal(userName))
Expect(secret.Data["password"]).NotTo(BeEmpty())
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
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"])))
})

By("deleting the DatabaseUserReference object", func() {
Expand Down Expand Up @@ -172,6 +176,8 @@ var _ = Describe("DatabaseUserReference controller", func() {
Expect(secret.OwnerReferences).To(ContainElement(dbUserRefOwnerReference))
Expect(string(secret.Data["username"])).To(Equal(userName))
Expect(secret.Data["password"]).NotTo(BeEmpty())
Expect(string(secret.Data["uri"])).To(Equal(fmt.Sprintf("postgresql://%s:%s@host:12345/database?sslmode=require", secret.Data["username"], secret.Data["password"])))
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"])))
})

By("deleting the DatabaseUserReference object", func() {
Expand Down
4 changes: 2 additions & 2 deletions fakegodo/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (f *FakeDatabasesService) Create(_ context.Context, req *godo.DatabaseCreat
RegionSlug: req.Region,
CreatedAt: time.Now(),
Connection: &godo.DatabaseConnection{
URI: "uri",
URI: "postgresql://user:password@host:12345/database?sslmode=require",
Database: "database",
Host: "host",
Port: 12345,
Expand All @@ -99,7 +99,7 @@ func (f *FakeDatabasesService) Create(_ context.Context, req *godo.DatabaseCreat
SSL: true,
},
PrivateConnection: &godo.DatabaseConnection{
URI: "private-uri",
URI: "postgresql://private-user:private-password@private-host:12345/private-database?sslmode=require",
Database: "private-database",
Host: "private_host",
Port: 12345,
Expand Down

0 comments on commit 57d73ee

Please sign in to comment.