mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Actually wait for the project to be deleted.. (#2397)
Actually wait.. Signed-off-by: Charlie Drage <charlie@charliedrage.com>
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"github.com/openshift/odo/pkg/machineoutput"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/openshift/odo/pkg/log"
|
||||
"github.com/openshift/odo/pkg/occlient"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -45,18 +44,16 @@ func Create(client *occlient.Client, projectName string, wait bool) error {
|
||||
}
|
||||
|
||||
// Delete deletes the project with name projectName and returns errors if any
|
||||
func Delete(client *occlient.Client, projectName string) error {
|
||||
// Loading spinner
|
||||
s := log.Spinnerf("Deleting project %s", projectName)
|
||||
defer s.End(false)
|
||||
func Delete(client *occlient.Client, projectName string, wait bool) error {
|
||||
if projectName == "" {
|
||||
return errors.Errorf("no project name given")
|
||||
}
|
||||
|
||||
// Delete the requested project
|
||||
err := client.DeleteProject(projectName)
|
||||
err := client.DeleteProject(projectName, wait)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to delete project")
|
||||
}
|
||||
|
||||
s.End(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
projectv1 "github.com/openshift/api/project/v1"
|
||||
v1 "github.com/openshift/api/project/v1"
|
||||
|
||||
"github.com/openshift/odo/pkg/occlient"
|
||||
@@ -108,16 +109,19 @@ func TestDelete(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
wantErr bool
|
||||
wait bool
|
||||
projectName string
|
||||
}{
|
||||
{
|
||||
name: "Test project delete for multiple projects",
|
||||
name: "Case 1: Test project delete for multiple projects",
|
||||
wantErr: false,
|
||||
wait: false,
|
||||
projectName: "prj2",
|
||||
},
|
||||
{
|
||||
name: "Test delete the only remaining project",
|
||||
name: "Case 2: Test delete the only remaining project",
|
||||
wantErr: false,
|
||||
wait: false,
|
||||
projectName: "testing",
|
||||
},
|
||||
}
|
||||
@@ -162,19 +166,22 @@ func TestDelete(t *testing.T) {
|
||||
return true, nil, nil
|
||||
})
|
||||
|
||||
go func() {
|
||||
fkWatch.Delete(testingutil.FakeProjectStatus(corev1.NamespacePhase(""), tt.projectName))
|
||||
}()
|
||||
// We pass in the fakeProject in order to avoid race conditions with multiple go routines
|
||||
fakeProject := testingutil.FakeProjectStatus(corev1.NamespacePhase(""), tt.projectName)
|
||||
go func(project *projectv1.Project) {
|
||||
fkWatch.Delete(project)
|
||||
}(fakeProject)
|
||||
|
||||
fakeClientSet.ProjClientset.PrependWatchReactor("projects", func(action ktesting.Action) (handled bool, ret watch.Interface, err error) {
|
||||
return true, fkWatch, nil
|
||||
})
|
||||
|
||||
// The function we are testing
|
||||
err := Delete(client, tt.projectName)
|
||||
err := Delete(client, tt.projectName, tt.wait)
|
||||
|
||||
if err == nil && !tt.wantErr {
|
||||
if len(fakeClientSet.ProjClientset.Actions()) != 2 {
|
||||
t.Errorf("expected 2 ProjClientSet.Actions() in Project Delete, got: %v", len(fakeClientSet.ProjClientset.Actions()))
|
||||
if len(fakeClientSet.ProjClientset.Actions()) != 1 {
|
||||
t.Errorf("expected 1 ProjClientSet.Actions() in Project Delete, got: %v", len(fakeClientSet.ProjClientset.Actions()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user