Skip to content

Commit

Permalink
update test for Remove. Uncommenting the remove request in between th…
Browse files Browse the repository at this point in the history
…e mount and unmount requests currently causes test to fail - see issue #30
  • Loading branch information
Cesar Gonzalez committed Apr 27, 2017
1 parent 900cb18 commit 88ecafa
Showing 1 changed file with 155 additions and 10 deletions.
165 changes: 155 additions & 10 deletions main_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestCreate(t *testing.T) {
t.Logf("POST /VolumeDriver.Create")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.Request{Name: \"\", Options: map[string]string{}})")
t.Logf("json.Marshal(volume.Request{Name: , Options: map[string]string{}})")
jsn, err := json.Marshal(volume.Request{
Name: "",
Options: map[string]string{},
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestGet(t *testing.T) {
t.Logf("POST /VolumeDriver.Get")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.Request{Name: \"\", Options: map[string]string{}})")
t.Logf("json.Marshal(volume.Request{Name: , Options: map[string]string{}})")
jsn, err := json.Marshal(volume.Request{
Name: "",
Options: map[string]string{},
Expand Down Expand Up @@ -861,7 +861,7 @@ func TestRemove(t *testing.T) {
t.Logf("POST /VolumeDriver.Remove")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.Request{Name: \"\", Options: map[string]string{}})")
t.Logf("json.Marshal(volume.Request{Name: , Options: map[string]string{}})")
jsn, err := json.Marshal(volume.Request{
Name: "",
Options: map[string]string{},
Expand Down Expand Up @@ -1008,8 +1008,7 @@ func TestRemove(t *testing.T) {
resp.Body.Close()

/**************************REMOVE********************************/
// Get a Docker approved random name
volumeName2 := namesgenerator.GetRandomName(2)
volumeName2 := "nonexistent_volume"

// Remove (Delete) a paricular volume.
t.Logf("POST /VolumeDriver.Remove")
Expand Down Expand Up @@ -1051,7 +1050,153 @@ func TestRemove(t *testing.T) {
}

if r.Err == "" {
t.Fatal("Error should occur when removing a nonexistant volume")
t.Fatal("Error should occur when removing a nonexistent volume")
}

resp.Body.Close()

/**************************MOUNT********************************/
// Mount a paricular volume to the host.
t.Logf("POST /VolumeDriver.Mount")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.MountRequest{Name: %s, ID: 42})", volumeName0)
jsn, err = json.Marshal(volume.MountRequest{
Name: volumeName0,
ID: "42",
})

if err != nil {
t.Fatal(err)
}

// Create request to server
body = bytes.NewBuffer(jsn)
client = &http.Client{}
req, err = http.NewRequest("POST", "http://plugin:8080/VolumeDriver.Mount", body)
if err != nil {
t.Fatal(err)
}

// Fetch request
req.Header.Add("Content-Type", "application/json")
resp, err = client.Do(req)
if err != nil {
t.Fatal("Failed to connect to server! ", err)
}

if resp == nil {
t.Fatal("resp is nil!")
}
if resp.Body == nil {
t.Fatal("resp.Body is nil!")
}

err = json.NewDecoder(resp.Body).Decode(&r)
if err != nil {
t.Fatal(err)
}

if r.Err != "" {
t.Fatal("Error occured while mounting:", volumeName0, r.Err)
}

if r.Mountpoint != "/etc/docker/mounts/"+volumeName0 {
t.Fatal("Expected Mountpoint: /etc/docker/mounts/" + volumeName0 + " Actual: " + r.Mountpoint)
}

resp.Body.Close()

// /**************************REMOVE********************************/
// // Remove (Delete) a paricular volume.
// t.Logf("POST /VolumeDriver.Remove")
//
// // Create json for request - local variable json masks the global symbol json referring to the JSON module
// t.Logf("json.Marshal(volume.Request{Name: %s})", volumeName0)
// jsn, err = json.Marshal(volume.Request{
// Name: volumeName0,
// })
// if err != nil {
// t.Fatal(err)
// }
//
// // Create request for server
// body = bytes.NewBuffer(jsn)
// client = &http.Client{}
// req, err = http.NewRequest("POST", "http://plugin:8080/VolumeDriver.Remove", body)
// if err != nil {
// t.Fatal(err)
// }
//
// // Fetch request
// req.Header.Add("Content-Type", "application/json")
// resp, err = client.Do(req)
// if err != nil {
// t.Fatal(err)
// }
//
// if resp == nil {
// t.Fatal("resp is nil!")
// }
// if resp.Body == nil {
// t.Fatal("resp.Body is nil!")
// }
//
// err = json.NewDecoder(resp.Body).Decode(&r)
// if err != nil {
// t.Fatal(err)
// }
//
// if r.Err == "" {
// t.Fatal("Error should occur when attempting to remove a mounted volume", r.Err)
// }
//
// resp.Body.Close()

/**************************UNMOUNT********************************/
// Unmount a paricular volume from host (if no other mount requests active).
t.Logf("POST /VolumeDriver.Unmount")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.UnmountRequest{Name: %s, ID: 42})", volumeName0)
jsn, err = json.Marshal(volume.UnmountRequest{
Name: volumeName0,
ID: "42",
})

if err != nil {
t.Fatal(err)
}

// Create request to server
body = bytes.NewBuffer(jsn)
client = &http.Client{}
req, err = http.NewRequest("POST", "http://plugin:8080/VolumeDriver.Unmount", body)
if err != nil {
t.Fatal(err)
}

// Fetch request
req.Header.Add("Content-Type", "application/json")
resp, err = client.Do(req)
if err != nil {
t.Fatal("Failed to connect to server! ", err)
}

if resp == nil {
t.Fatal("resp is nil!")
}
if resp.Body == nil {
t.Fatal("resp.Body is nil!")
}

err = json.NewDecoder(resp.Body).Decode(&r)
if err != nil {
t.Fatal(err)
}

if r.Err != "" {
t.Fatal("Error occured while unmounting:", volumeName0, r.Err)
}

resp.Body.Close()
Expand Down Expand Up @@ -1149,7 +1294,7 @@ func TestRemove(t *testing.T) {

resp.Body.Close()

/**************************GET volumeName1********************************/
/**************************GET********************************/
// Get info relating to a paricular volume.
t.Logf("POST /VolumeDriver.Get")

Expand Down Expand Up @@ -1393,7 +1538,7 @@ func TestPath(t *testing.T) {
}

if r.Mountpoint != "" {
t.Fatal("Mountpoint should be: \"\" since volume hasn't been mounted")
t.Fatal("Mountpoint should not exist since volume has not been mounted")
}

resp.Body.Close()
Expand All @@ -1403,7 +1548,7 @@ func TestPath(t *testing.T) {
t.Logf("POST /VolumeDriver.Mount")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.MountRequest{Name: %s, ID: \"42\"})", volumeName)
t.Logf("json.Marshal(volume.MountRequest{Name: %s, ID: 42})", volumeName)
jsn, err = json.Marshal(volume.MountRequest{
Name: volumeName,
ID: "42",
Expand Down Expand Up @@ -1506,7 +1651,7 @@ func TestPath(t *testing.T) {
t.Logf("POST /VolumeDriver.Unmount")

// Create json for request - local variable json masks the global symbol json referring to the JSON module
t.Logf("json.Marshal(volume.UnmountRequest{Name: %s, ID: \"42\"})", volumeName)
t.Logf("json.Marshal(volume.UnmountRequest{Name: %s, ID: 42})", volumeName)
jsn, err = json.Marshal(volume.UnmountRequest{
Name: volumeName,
ID: "42",
Expand Down

0 comments on commit 88ecafa

Please sign in to comment.