feat: update
This commit is contained in:
@@ -58,7 +58,11 @@ func (c *Client) CreateVolume(ctx context.Context, req provisioner.CreateVolumeR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) DeleteVolume(ctx context.Context, volumeID string) error {
|
func (c *Client) DeleteVolume(ctx context.Context, volumeID string) error {
|
||||||
return c.doJSON(ctx, http.MethodDelete, "/v1/volumes/"+escapePath(volumeID), nil, nil)
|
err := c.doJSON(ctx, http.MethodDelete, "/v1/volumes/"+escapePath(volumeID), nil, nil)
|
||||||
|
if isNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) VolumeExists(ctx context.Context, volumeID string) (bool, error) {
|
func (c *Client) VolumeExists(ctx context.Context, volumeID string) (bool, error) {
|
||||||
|
|||||||
@@ -60,3 +60,34 @@ func TestClientCreateVolume(t *testing.T) {
|
|||||||
t.Fatalf("unexpected volume: %#v", vol)
|
t.Fatalf("unexpected volume: %#v", vol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClientDeleteVolume(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const volumeID = "abc123/pvc-1"
|
||||||
|
deleted := false
|
||||||
|
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch {
|
||||||
|
case r.Method == http.MethodDelete && r.URL.Path == "/v1/volumes/abc123/pvc-1":
|
||||||
|
deleted = true
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
case r.Method == http.MethodDelete && r.URL.Path == "/v1/volumes/missing/pvc-1":
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
default:
|
||||||
|
t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
t.Cleanup(srv.Close)
|
||||||
|
|
||||||
|
client := NewClient(ClientConfig{BaseURL: srv.URL})
|
||||||
|
if err := client.DeleteVolume(context.Background(), volumeID); err != nil {
|
||||||
|
t.Fatalf("DeleteVolume failed: %v", err)
|
||||||
|
}
|
||||||
|
if !deleted {
|
||||||
|
t.Fatal("expected delete request to reach backend")
|
||||||
|
}
|
||||||
|
if err := client.DeleteVolume(context.Background(), "missing/pvc-1"); err != nil {
|
||||||
|
t.Fatalf("DeleteVolume should treat 404 as success: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,14 @@ func bindMount(source, target string) error {
|
|||||||
return m.Mount(source, target, "", []string{"bind"})
|
return m.Mount(source, target, "", []string{"bind"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isHostMounted(path string) bool {
|
||||||
|
return isMounted(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmountHost(path string) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func isMounted(path string) bool {
|
func isMounted(path string) bool {
|
||||||
m := newMounter()
|
m := newMounter()
|
||||||
notMnt, err := m.IsLikelyNotMountPoint(path)
|
notMnt, err := m.IsLikelyNotMountPoint(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user