forked from Scalingo/scalingo-addon-api-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeprovision.go
43 lines (40 loc) · 977 Bytes
/
deprovision.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"github.com/codegangsta/cli"
)
var (
deprovisionCommand = cli.Command{
Name: "deprovision",
Usage: "Request addon deprovisioning",
Action: func(c *cli.Context) {
if len(c.Args()) != 1 {
log.Fatalln(os.Args, "<addon id>")
}
id := c.Args()[0]
res, err := doRequest("DELETE", manifest.Test.BaseURL+"/"+id, nil)
if err != nil {
log.Fatalln("Fail to delete resource:", err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln("Failed to read body from addon:", err)
}
if len(body) != 0 {
log.Fatalf("Expected empty body, got '%s'\n", string(body))
}
if res.StatusCode != 204 {
log.Fatalln("Addon returned bad status:", res.Status, "expected 204 - body:", string(body))
}
err = deleteAddonRef(id)
if err != nil {
log.Println("fail to delete addon reference:", err)
}
fmt.Println("→ OK")
},
}
)