|
1 | 1 | package commands |
2 | 2 |
|
3 | | -// import ( |
4 | | -// "errors" |
5 | | -// "kool-dev/kool/core/environment" |
6 | | -// "kool-dev/kool/core/shell" |
7 | | -// "kool-dev/kool/services/cloud/api" |
8 | | -// "strings" |
9 | | -// "testing" |
10 | | -// ) |
11 | | - |
12 | | -// func TestNewDeployDestroyCommand(t *testing.T) { |
13 | | -// destroy := NewKoolDeployDestroy() |
14 | | -// cmd := NewDeployDestroyCommand(destroy) |
15 | | -// if cmd.Use != "destroy" { |
16 | | -// t.Errorf("bad command use: %s", cmd.Use) |
17 | | -// } |
18 | | - |
19 | | -// if _, ok := destroy.env.(*environment.DefaultEnvStorage); !ok { |
20 | | -// t.Error("unexpected default env on destroy") |
21 | | -// } |
22 | | -// } |
23 | | - |
24 | | -// type fakeDestroyCall struct { |
25 | | -// api.DefaultEndpoint |
26 | | - |
27 | | -// err error |
28 | | -// resp *api.DestroyResponse |
29 | | -// } |
30 | | - |
31 | | -// func (d *fakeDestroyCall) Call() (*api.DestroyResponse, error) { |
32 | | -// return d.resp, d.err |
33 | | -// } |
34 | | - |
35 | | -// func TestDeployDestroyExec(t *testing.T) { |
36 | | -// destroy := &KoolDeployDestroy{ |
37 | | -// *(newDefaultKoolService().Fake()), |
38 | | -// environment.NewFakeEnvStorage(), |
39 | | -// &fakeDestroyCall{ |
40 | | -// DefaultEndpoint: *api.NewDefaultEndpoint(""), |
41 | | -// }, |
42 | | -// } |
43 | | - |
44 | | -// destroy.env.Set("KOOL_API_TOKEN", "fake token") |
45 | | -// destroy.env.Set("KOOL_API_URL", "fake-url") |
46 | | - |
47 | | -// args := []string{} |
48 | | - |
49 | | -// if err := destroy.Execute(args); !strings.Contains(err.Error(), "missing deploy domain") { |
50 | | -// t.Errorf("unexpected error - expected missing deploy domain, got: %v", err) |
51 | | -// } |
52 | | - |
53 | | -// destroy.env.Set("KOOL_DEPLOY_DOMAIN", "domain.com") |
54 | | - |
55 | | -// destroy.apiDestroy.(*fakeDestroyCall).err = errors.New("failed call") |
56 | | - |
57 | | -// if err := destroy.Execute(args); !strings.Contains(err.Error(), "failed call") { |
58 | | -// t.Errorf("unexpected error - expected failed call, got: %v", err) |
59 | | -// } |
60 | | - |
61 | | -// destroy.apiDestroy.(*fakeDestroyCall).err = nil |
62 | | -// resp := new(api.DestroyResponse) |
63 | | -// resp.Environment.ID = 100 |
64 | | -// destroy.apiDestroy.(*fakeDestroyCall).resp = resp |
65 | | - |
66 | | -// if err := destroy.Execute(args); err != nil { |
67 | | -// t.Errorf("unexpected error, got: %v", err) |
68 | | -// } |
69 | | - |
70 | | -// if !strings.Contains(destroy.shell.(*shell.FakeShell).SuccessOutput[0].(string), "ID: 100") { |
71 | | -// t.Errorf("did not get success message") |
72 | | -// } |
73 | | -// } |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "kool-dev/kool/core/environment" |
| 6 | + "kool-dev/kool/core/shell" |
| 7 | + "kool-dev/kool/services/cloud/api" |
| 8 | + "strings" |
| 9 | + "testing" |
| 10 | +) |
| 11 | + |
| 12 | +func TestNewDeployDestroyCommand(t *testing.T) { |
| 13 | + destroy := NewKoolDeployDestroy() |
| 14 | + cmd := NewDeployDestroyCommand(destroy) |
| 15 | + if cmd.Use != "destroy" { |
| 16 | + t.Errorf("bad command use: %s", cmd.Use) |
| 17 | + } |
| 18 | + |
| 19 | + if _, ok := destroy.env.(*environment.DefaultEnvStorage); !ok { |
| 20 | + t.Error("unexpected default env on destroy") |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +func TestDeployDestroyExec(t *testing.T) { |
| 25 | + destroy := &KoolDeployDestroy{ |
| 26 | + *(newDefaultKoolService().Fake()), |
| 27 | + environment.NewFakeEnvStorage(), |
| 28 | + *api.NewDeployDestroy(), |
| 29 | + } |
| 30 | + |
| 31 | + destroy.env.Set("KOOL_API_TOKEN", "fake token") |
| 32 | + destroy.env.Set("KOOL_API_URL", "fake-url") |
| 33 | + |
| 34 | + args := []string{} |
| 35 | + |
| 36 | + if err := destroy.Execute(args); !strings.Contains(err.Error(), "missing deploy domain") { |
| 37 | + t.Errorf("unexpected error - expected missing deploy domain, got: %v", err) |
| 38 | + } |
| 39 | + |
| 40 | + destroy.env.Set("KOOL_DEPLOY_DOMAIN", "domain.com") |
| 41 | + |
| 42 | + destroy.apiDestroy.Endpoint.(*api.DefaultEndpoint).Fake() |
| 43 | + destroy.apiDestroy.Endpoint.(*api.DefaultEndpoint).MockErr(errors.New("failed call")) |
| 44 | + |
| 45 | + if err := destroy.Execute(args); !strings.Contains(err.Error(), "failed call") { |
| 46 | + t.Errorf("unexpected error - expected failed call, got: %v", err) |
| 47 | + } |
| 48 | + |
| 49 | + destroy.apiDestroy.Endpoint.(*api.DefaultEndpoint).MockErr(nil) |
| 50 | + destroy.apiDestroy.Endpoint.(*api.DefaultEndpoint).MockResp(&api.DeployDestroyResponse{ |
| 51 | + Environment: struct { |
| 52 | + ID int `json:"id"` |
| 53 | + }{ |
| 54 | + ID: 100, |
| 55 | + }, |
| 56 | + }) |
| 57 | + |
| 58 | + if err := destroy.Execute(args); err != nil { |
| 59 | + t.Errorf("unexpected error, got: %v", err) |
| 60 | + } |
| 61 | + |
| 62 | + if !strings.Contains(destroy.shell.(*shell.FakeShell).SuccessOutput[0].(string), "ID: 100") { |
| 63 | + t.Errorf("did not get success message") |
| 64 | + } |
| 65 | +} |
0 commit comments