-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(controller): provision zfs volume if zfs volume already exists (#576
- Loading branch information
1 parent
fc826e1
commit 6c89f42
Showing
2 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package zfs | ||
|
||
import ( | ||
"testing" | ||
|
||
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1" | ||
) | ||
|
||
func TestIsVolumeReady(t *testing.T) { | ||
volGen := func(finalizer string, state string) *apis.ZFSVolume { | ||
vol := &apis.ZFSVolume{} | ||
if finalizer != "" { | ||
vol.Finalizers = append(vol.Finalizers, finalizer) | ||
} | ||
if state != "" { | ||
vol.Status.State = state | ||
} | ||
return vol | ||
} | ||
tests := []struct { | ||
name string | ||
volFinalizer string | ||
volState string | ||
want bool | ||
}{ | ||
{"Older volume is ready", ZFSFinalizer, "", true}, | ||
{"Older volume is not ready", "", "", false}, | ||
{"Newer volume is pending", "", ZFSStatusPending, false}, | ||
{"Newer volume is pending with finalizer", ZFSFinalizer, ZFSStatusPending, false}, | ||
{"Newer volume is ready with finalizer", ZFSFinalizer, ZFSStatusReady, true}, | ||
{"Newer volume is failed", "", ZFSStatusFailed, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsVolumeReady(volGen(tt.volFinalizer, tt.volState)); got != tt.want { | ||
t.Errorf("IsVolumeReady() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |