-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathdelete_env_test.go
More file actions
158 lines (141 loc) · 4.84 KB
/
Copy pathdelete_env_test.go
File metadata and controls
158 lines (141 loc) · 4.84 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package cmd_test
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
fakesys "github.com/cloudfoundry/bosh-utils/system/fakes"
"github.com/cppforlife/go-patch/patch"
"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/cloudfoundry/bosh-cli/v7/cmd"
mockcmd "github.com/cloudfoundry/bosh-cli/v7/cmd/mocks"
"github.com/cloudfoundry/bosh-cli/v7/cmd/opts"
boshtpl "github.com/cloudfoundry/bosh-cli/v7/director/template"
fakeui "github.com/cloudfoundry/bosh-cli/v7/ui/fakes"
)
var _ = Describe("DeleteEnvCmd", func() {
var mockCtrl *gomock.Controller
BeforeEach(func() {
mockCtrl = gomock.NewController(GinkgoT())
})
AfterEach(func() {
mockCtrl.Finish()
})
Describe("Run", func() {
var (
mockDeploymentDeleter *mockcmd.MockDeploymentDeleter
fs *fakesys.FakeFileSystem
fakeUI *fakeui.FakeUI
fakeStage *fakeui.FakeStage
deploymentManifestPath = "/deployment-dir/fake-deployment-manifest.yml"
statePath string
skipDrain bool
)
var newDeleteEnvCmd = func() *cmd.DeleteEnvCmd {
doGetFunc := func(manifestPath string, statePath_ string, vars boshtpl.Variables, op patch.Op) cmd.DeploymentDeleter {
Expect(manifestPath).To(Equal(deploymentManifestPath))
Expect(vars).To(Equal(boshtpl.NewMultiVars([]boshtpl.Variables{boshtpl.StaticVariables{"key": "value"}})))
Expect(op).To(Equal(patch.Ops{patch.ErrOp{}}))
statePath = statePath_
return mockDeploymentDeleter
}
return cmd.NewDeleteEnvCmd(fakeUI, doGetFunc)
}
var writeDeploymentManifest = func() {
err := fs.WriteFileString(deploymentManifestPath, `---manifest-content`)
Expect(err).ToNot(HaveOccurred())
}
BeforeEach(func() {
mockDeploymentDeleter = mockcmd.NewMockDeploymentDeleter(mockCtrl)
fs = fakesys.NewFakeFileSystem()
fs.EnableStrictTempRootBehavior()
fakeUI = &fakeui.FakeUI{}
writeDeploymentManifest()
skipDrain = false
})
Context("when skip drain is specified", func() {
It("gets passed to DeleteDeployment", func() {
skipDrain = true
mockDeploymentDeleter.EXPECT().DeleteDeployment(skipDrain, fakeStage).Return(nil)
err := newDeleteEnvCmd().Run(fakeStage, opts.DeleteEnvOpts{
Args: opts.DeleteEnvArgs{
Manifest: opts.FileBytesWithPathArg{Path: deploymentManifestPath},
},
SkipDrain: skipDrain,
VarFlags: opts.VarFlags{
VarKVs: []boshtpl.VarKV{{Name: "key", Value: "value"}},
},
OpsFlags: opts.OpsFlags{
OpsFiles: []opts.OpsFileArg{
{Ops: []patch.Op{patch.ErrOp{}}},
},
},
})
Expect(err).ToNot(HaveOccurred())
})
})
Context("state path is NOT specified", func() {
It("sends the manifest on to the deleter", func() {
mockDeploymentDeleter.EXPECT().DeleteDeployment(skipDrain, fakeStage).Return(nil)
err := newDeleteEnvCmd().Run(fakeStage, opts.DeleteEnvOpts{
Args: opts.DeleteEnvArgs{
Manifest: opts.FileBytesWithPathArg{Path: deploymentManifestPath},
},
SkipDrain: skipDrain,
VarFlags: opts.VarFlags{
VarKVs: []boshtpl.VarKV{{Name: "key", Value: "value"}},
},
OpsFlags: opts.OpsFlags{
OpsFiles: []opts.OpsFileArg{
{Ops: []patch.Op{patch.ErrOp{}}},
},
},
})
Expect(err).ToNot(HaveOccurred())
Expect(statePath).To(Equal(""))
})
})
Context("state path is specified", func() {
It("sends the manifest on to the deleter", func() {
mockDeploymentDeleter.EXPECT().DeleteDeployment(skipDrain, fakeStage).Return(nil)
err := newDeleteEnvCmd().Run(fakeStage, opts.DeleteEnvOpts{
StatePath: "/new/state/file/path/state.json",
SkipDrain: skipDrain,
Args: opts.DeleteEnvArgs{
Manifest: opts.FileBytesWithPathArg{Path: deploymentManifestPath},
},
VarFlags: opts.VarFlags{
VarKVs: []boshtpl.VarKV{{Name: "key", Value: "value"}},
},
OpsFlags: opts.OpsFlags{
OpsFiles: []opts.OpsFileArg{
{Ops: []patch.Op{patch.ErrOp{}}},
},
},
})
Expect(err).ToNot(HaveOccurred())
Expect(statePath).To(Equal("/new/state/file/path/state.json"))
})
})
Context("when the deployment deleter returns an error", func() {
It("sends the manifest on to the deleter", func() {
err := bosherr.Error("boom")
mockDeploymentDeleter.EXPECT().DeleteDeployment(skipDrain, fakeStage).Return(err)
returnedErr := newDeleteEnvCmd().Run(fakeStage, opts.DeleteEnvOpts{
Args: opts.DeleteEnvArgs{
Manifest: opts.FileBytesWithPathArg{Path: deploymentManifestPath},
},
SkipDrain: skipDrain,
VarFlags: opts.VarFlags{
VarKVs: []boshtpl.VarKV{{Name: "key", Value: "value"}},
},
OpsFlags: opts.OpsFlags{
OpsFiles: []opts.OpsFileArg{
{Ops: []patch.Op{patch.ErrOp{}}},
},
},
})
Expect(returnedErr).To(Equal(err))
})
})
})
})