put mock methods to k8sutil to avoid cycling imports

This commit is contained in:
Felix Kunde
2019-04-18 18:04:37 +02:00
parent 2ad951e172
commit 9e7760d80a
4 changed files with 96 additions and 92 deletions
+1
View File
@@ -148,6 +148,7 @@ func (c *Cluster) setProcessName(procName string, args ...interface{}) {
}
}
// SetStatus of Postgres cluster
func (c *Cluster) SetStatus(status string) {
// TODO: eventually switch to updateStatus() for kubernetes 1.11 and above
patch, err := json.Marshal(acidv1.PostgresStatus{PostgresClusterStatus: status})
+29 -1
View File
@@ -30,7 +30,7 @@ var cl = New(
},
},
},
k8sutil.KubernetesClient{},
k8sutil.NewMockKubernetesClient(),
acidv1.Postgresql{},
logger,
)
@@ -328,3 +328,31 @@ func TestShouldDeleteSecret(t *testing.T) {
}
}
}
func TestSetStatus(t *testing.T) {
tests := []struct {
status acidv1.PostgresStatus
outcome bool
}{
{
status: acidv1.PostgresStatus{PostgresClusterStatus: acidv1.ClusterStatusCreating},
outcome: cl.Status.Creating(),
},
{
status: acidv1.PostgresStatus{PostgresClusterStatus: acidv1.ClusterStatusRunning},
outcome: cl.Status.Running(),
},
{
status: acidv1.PostgresStatus{PostgresClusterStatus: acidv1.ClusterStatusInvalid},
outcome: !cl.Status.Success(),
},
}
for _, tt := range tests {
cl.SetStatus(tt.status.PostgresClusterStatus)
if tt.outcome {
t.Errorf("Wrong status: %s", cl.Status.String())
}
}
}