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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
package flymachines
import (
"context"
"net/http"
"os"
"testing"
_ "github.com/joho/godotenv/autoload"
"within.website/x/misc/namegen"
)
func TestAppLifecycle(t *testing.T) {
token, ok := os.LookupEnv("FLY_API_TOKEN")
if !ok {
t.Skip("no FLY_API_TOKEN")
}
cli := New(token, http.DefaultClient)
ctx := context.Background()
name := namegen.Next()
t.Logf("creating app %s", name)
_, err := cli.CreateApp(ctx, CreateAppArgs{
AppName: name,
Network: "xtest",
OrgSlug: "personal",
})
if err != nil {
t.Fatal(err)
}
t.Logf("created app %s", name)
t.Logf("getting app %s", name)
app, err := cli.GetApp(ctx, name)
if err != nil {
t.Fatal(err)
}
t.Logf("got app %s: %s", app.Name, app.Status)
t.Log("listing all apps")
apps, err := cli.GetApps(ctx, "personal")
if err != nil {
t.Fatal(err)
}
for _, app := range apps {
t.Logf("app: %s", app.Name)
}
t.Logf("deleting app %s", name)
if err := cli.DeleteApp(ctx, name); err != nil {
t.Fatal(err)
}
}
|