github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/plugin/plugins_command_test.go (about) 1 package plugin 2 3 import ( 4 "os" 5 "path/filepath" 6 7 "github.com/liamawhite/cli-with-i18n/integration/helpers" 8 "github.com/liamawhite/cli-with-i18n/util/generic" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gbytes" 12 . "github.com/onsi/gomega/gexec" 13 . "github.com/onsi/gomega/ghttp" 14 ) 15 16 var _ = Describe("plugins command", func() { 17 Describe("help", func() { 18 Context("when --help flag is provided", func() { 19 It("displays command usage to output", func() { 20 session := helpers.CF("plugins", "--help") 21 Eventually(session).Should(Say("NAME:")) 22 Eventually(session).Should(Say("plugins - List commands of installed plugins")) 23 Eventually(session).Should(Say("USAGE:")) 24 Eventually(session).Should(Say("cf plugins [--checksum | --outdated]")) 25 Eventually(session).Should(Say("OPTIONS:")) 26 Eventually(session).Should(Say("--checksum\\s+Compute and show the sha1 value of the plugin binary file")) 27 Eventually(session).Should(Say("--outdated\\s+Search the plugin repositories for new versions of installed plugins")) 28 Eventually(session).Should(Say("SEE ALSO:")) 29 Eventually(session).Should(Say("install-plugin, repo-plugins, uninstall-plugin")) 30 Eventually(session).Should(Exit(0)) 31 }) 32 }) 33 }) 34 35 Context("when no plugins are installed", func() { 36 It("displays an empty table", func() { 37 session := helpers.CF("plugins") 38 Eventually(session.Out).Should(Say("Listing installed plugins...")) 39 Eventually(session.Out).Should(Say("")) 40 Eventually(session.Out).Should(Say("plugin\\s+version\\s+command name\\s+command help")) 41 Eventually(session.Out).Should(Say("")) 42 Eventually(session.Out).Should(Say("Use 'cf repo-plugins' to list plugins in registered repos available to install\\.")) 43 Consistently(session.Out).ShouldNot(Say("[a-za-z0-9]+")) 44 Eventually(session).Should(Exit(0)) 45 }) 46 47 Context("when the --checksum flag is provided", func() { 48 It("displays an empty checksum table", func() { 49 session := helpers.CF("plugins", "--checksum") 50 Eventually(session.Out).Should(Say("Computing sha1 for installed plugins, this may take a while...")) 51 Eventually(session.Out).Should(Say("")) 52 Eventually(session.Out).Should(Say("plugin\\s+version\\s+sha1")) 53 Consistently(session.Out).ShouldNot(Say("[a-za-z0-9]+")) 54 Eventually(session).Should(Exit(0)) 55 }) 56 }) 57 58 Context("when the --outdated flag is provided", func() { 59 It("errors with no repositories", func() { 60 session := helpers.CF("plugins", "--outdated") 61 Eventually(session).Should(Say("FAILED")) 62 Eventually(session.Err).Should(Say("No plugin repositories registered to search for plugin updates.")) 63 64 Eventually(session).Should(Exit(1)) 65 }) 66 }) 67 }) 68 69 Context("when plugins are installed", func() { 70 Context("when there are multiple plugins", func() { 71 BeforeEach(func() { 72 helpers.InstallConfigurablePlugin("I-should-be-sorted-first", "1.2.0", []helpers.PluginCommand{ 73 {Name: "command-1", Help: "some-command-1"}, 74 {Name: "Better-command", Help: "some-better-command"}, 75 {Name: "command-2", Help: "some-command-2"}, 76 }) 77 helpers.InstallConfigurablePlugin("sorted-third", "2.0.1", []helpers.PluginCommand{ 78 {Name: "banana-command", Help: "banana-command"}, 79 }) 80 helpers.InstallConfigurablePlugin("i-should-be-sorted-second", "1.0.0", []helpers.PluginCommand{ 81 {Name: "some-command", Help: "some-command"}, 82 {Name: "Some-other-command", Help: "some-other-command"}, 83 }) 84 }) 85 86 It("displays the installed plugins in alphabetical order", func() { 87 session := helpers.CF("plugins") 88 Eventually(session).Should(Say("Listing installed plugins...")) 89 Eventually(session).Should(Say("")) 90 Eventually(session).Should(Say("plugin\\s+version\\s+command name\\s+command help")) 91 Eventually(session).Should(Say("I-should-be-sorted-first\\s+1\\.2\\.0\\s+Better-command\\s+some-better-command")) 92 Eventually(session).Should(Say("I-should-be-sorted-first\\s+1\\.2\\.0\\s+command-1\\s+some-command-1")) 93 Eventually(session).Should(Say("I-should-be-sorted-first\\s+1\\.2\\.0\\s+command-2\\s+some-command-2")) 94 Eventually(session).Should(Say("i-should-be-sorted-second\\s+1\\.0\\.0\\s+some-command\\s+some-command")) 95 Eventually(session).Should(Say("i-should-be-sorted-second\\s+1\\.0\\.0\\s+Some-other-command\\s+some-other-command")) 96 Eventually(session).Should(Say("sorted-third\\s+2\\.0\\.1\\s+banana-command\\s+banana-command")) 97 Eventually(session.Out).Should(Say("")) 98 Eventually(session.Out).Should(Say("Use 'cf repo-plugins' to list plugins in registered repos available to install\\.")) 99 Eventually(session).Should(Exit(0)) 100 }) 101 }) 102 103 Context("when plugin version information is 0.0.0", func() { 104 BeforeEach(func() { 105 helpers.InstallConfigurablePlugin("some-plugin", "0.0.0", []helpers.PluginCommand{ 106 {Name: "banana-command", Help: "banana-command"}, 107 }) 108 }) 109 110 It("displays N/A for the plugin's version", func() { 111 session := helpers.CF("plugins") 112 Eventually(session.Out).Should(Say("some-plugin\\s+N/A")) 113 Eventually(session).Should(Exit(0)) 114 }) 115 }) 116 117 Context("when a plugin command has an alias", func() { 118 BeforeEach(func() { 119 helpers.InstallConfigurablePlugin("some-plugin", "1.0.0", []helpers.PluginCommand{ 120 {Name: "banana-command", Alias: "bc", Help: "banana-command"}, 121 }) 122 }) 123 124 It("displays the command name and it's alias", func() { 125 session := helpers.CF("plugins") 126 Eventually(session.Out).Should(Say("some-plugin\\s+1\\.0\\.0\\s+banana-command, bc")) 127 Eventually(session).Should(Exit(0)) 128 }) 129 }) 130 131 Context("when the --checksum flag is provided", func() { 132 var installedPluginPath string 133 134 BeforeEach(func() { 135 helpers.InstallConfigurablePlugin("some-plugin", "1.0.0", []helpers.PluginCommand{ 136 {Name: "banana-command", Help: "banana-command"}, 137 }) 138 installedPluginPath = generic.ExecutableFilename(filepath.Join(homeDir, ".cf", "plugins", "some-plugin")) 139 }) 140 141 It("displays the sha1 value for each installed plugin", func() { 142 calculatedSha := helpers.Sha1Sum(installedPluginPath) 143 session := helpers.CF("plugins", "--checksum") 144 Eventually(session.Out).Should(Say("Computing sha1 for installed plugins, this may take a while...")) 145 Eventually(session.Out).Should(Say("")) 146 Eventually(session.Out).Should(Say("plugin\\s+version\\s+sha1")) 147 Eventually(session.Out).Should(Say("some-plugin\\s+1\\.0\\.0\\s+%s", calculatedSha)) 148 Eventually(session).Should(Exit(0)) 149 }) 150 151 Context("when an error is encountered calculating the sha1 value", func() { 152 It("displays N/A for the plugin's sha1", func() { 153 err := os.Remove(installedPluginPath) 154 Expect(err).NotTo(HaveOccurred()) 155 156 session := helpers.CF("plugins", "--checksum") 157 Eventually(session.Out).Should(Say("some-plugin\\s+1\\.0\\.0\\s+N/A")) 158 Eventually(session).Should(Exit(0)) 159 }) 160 }) 161 }) 162 163 Context("when the --outdated flag is provided", func() { 164 Context("when there are no repos", func() { 165 BeforeEach(func() { 166 helpers.InstallConfigurablePlugin("some-plugin", "1.0.0", []helpers.PluginCommand{ 167 {Name: "banana-command", Alias: "bc", Help: "banana-command"}, 168 }) 169 }) 170 171 It("aborts with error 'No plugin repositories added' and exit code 1", func() { 172 session := helpers.CF("plugins", "--outdated") 173 Eventually(session).Should(Say("FAILED")) 174 Eventually(session.Err).Should(Say("No plugin repositories registered to search for plugin updates.")) 175 Eventually(session).Should(Exit(1)) 176 }) 177 }) 178 179 Context("when there is 1 repository", func() { 180 var ( 181 server1 *Server 182 ) 183 184 BeforeEach(func() { 185 server1 = helpers.NewPluginRepositoryTLSServer(helpers.PluginRepository{ 186 Plugins: []helpers.Plugin{ 187 {Name: "plugin-1", Version: "1.0.0"}, 188 {Name: "plugin-2", Version: "2.0.0"}, 189 }, 190 }) 191 192 Eventually(helpers.CF("add-plugin-repo", "repo1", server1.URL(), "-k")).Should(Exit(0)) 193 // TODO: re-add when refactor repo-plugins 194 // session := helpers.CF("repo-plugins") 195 // Eventually(session).Should(Say("plugin-1\\s+1\\.0\\.0")) 196 // Eventually(session).Should(Say("plugin-2\\s+2\\.0\\.0")) 197 // Eventually(session).Should(Exit(0)) 198 }) 199 200 AfterEach(func() { 201 server1.Close() 202 }) 203 204 Context("when nothing is outdated", func() { 205 BeforeEach(func() { 206 helpers.InstallConfigurablePlugin("plugin-1", "1.0.0", []helpers.PluginCommand{ 207 {Name: "banana-command-1", Help: "banana-command"}, 208 }) 209 helpers.InstallConfigurablePlugin("plugin-2", "2.0.0", []helpers.PluginCommand{ 210 {Name: "banana-command-2", Help: "banana-command"}, 211 }) 212 }) 213 214 AfterEach(func() { 215 Eventually(helpers.CF("uninstall-plugin", "plugin-1")).Should(Exit(0)) 216 Eventually(helpers.CF("uninstall-plugin", "plugin-2")).Should(Exit(0)) 217 }) 218 219 It("displays an empty table", func() { 220 session := helpers.CF("plugins", "--outdated", "-k") 221 Eventually(session).Should(Say("Searching repo1 for newer versions of installed plugins...")) 222 Eventually(session).Should(Say("")) 223 Eventually(session).Should(Say("plugin\\s+version\\s+latest version\\n\\nUse 'cf install-plugin' to update a plugin to the latest version\\.")) 224 Eventually(session).Should(Exit(0)) 225 }) 226 }) 227 228 Context("when the plugins are outdated", func() { 229 BeforeEach(func() { 230 helpers.InstallConfigurablePlugin("plugin-1", "0.9.0", []helpers.PluginCommand{ 231 {Name: "banana-command-1", Help: "banana-command"}, 232 }) 233 helpers.InstallConfigurablePlugin("plugin-2", "1.9.0", []helpers.PluginCommand{ 234 {Name: "banana-command-2", Help: "banana-command"}, 235 }) 236 }) 237 238 AfterEach(func() { 239 Eventually(helpers.CF("uninstall-plugin", "plugin-1")).Should(Exit(0)) 240 Eventually(helpers.CF("uninstall-plugin", "plugin-2")).Should(Exit(0)) 241 }) 242 243 It("displays the table with outdated plugin and new version", func() { 244 session := helpers.CF("plugins", "--outdated", "-k") 245 Eventually(session).Should(Say("Searching repo1 for newer versions of installed plugins...")) 246 Eventually(session).Should(Say("")) 247 Eventually(session).Should(Say("plugin\\s+version\\s+latest version")) 248 Eventually(session).Should(Say("plugin-1\\s+0\\.9\\.0\\s+1\\.0\\.0")) 249 Eventually(session).Should(Say("plugin-2\\s+1\\.9\\.0\\s+2\\.0\\.0")) 250 Eventually(session).Should(Say("")) 251 Eventually(session).Should(Say("Use 'cf install-plugin' to update a plugin to the latest version\\.")) 252 Eventually(session).Should(Exit(0)) 253 }) 254 }) 255 }) 256 257 Context("when multiple repositories are registered", func() { 258 var ( 259 server1 *Server 260 server2 *Server 261 ) 262 263 BeforeEach(func() { 264 server1 = helpers.NewPluginRepositoryTLSServer(helpers.PluginRepository{ 265 Plugins: []helpers.Plugin{ 266 {Name: "plugin-1", Version: "1.0.0"}, 267 {Name: "plugin-3", Version: "3.5.0"}, 268 }, 269 }) 270 271 server2 = helpers.NewPluginRepositoryTLSServer(helpers.PluginRepository{ 272 Plugins: []helpers.Plugin{ 273 {Name: "plugin-2", Version: "2.0.0"}, 274 {Name: "plugin-3", Version: "3.0.0"}, 275 }, 276 }) 277 278 Eventually(helpers.CF("add-plugin-repo", "repo1", server1.URL(), "-k")).Should(Exit(0)) 279 Eventually(helpers.CF("add-plugin-repo", "repo2", server2.URL(), "-k")).Should(Exit(0)) 280 }) 281 282 AfterEach(func() { 283 server1.Close() 284 server2.Close() 285 }) 286 287 Context("when plugins are outdated", func() { 288 BeforeEach(func() { 289 helpers.InstallConfigurablePlugin("plugin-1", "0.9.0", []helpers.PluginCommand{ 290 {Name: "banana-command-1", Help: "banana-command"}, 291 }) 292 helpers.InstallConfigurablePlugin("plugin-2", "1.9.0", []helpers.PluginCommand{ 293 {Name: "banana-command-2", Help: "banana-command"}, 294 }) 295 }) 296 297 It("displays the table with outdated plugin and new version", func() { 298 session := helpers.CF("plugins", "--outdated", "-k") 299 Eventually(session).Should(Say("Searching repo1, repo2 for newer versions of installed plugins...")) 300 Eventually(session).Should(Say("plugin\\s+version\\s+latest version")) 301 Eventually(session).Should(Say("plugin-1\\s+0\\.9\\.0\\s+1\\.0\\.0")) 302 Eventually(session).Should(Say("plugin-2\\s+1\\.9\\.0\\s+2\\.0\\.0")) 303 Eventually(session).Should(Say("")) 304 Eventually(session).Should(Say("Use 'cf install-plugin' to update a plugin to the latest version\\.")) 305 Eventually(session).Should(Exit(0)) 306 }) 307 }) 308 309 Context("when the same plugin is outdated from multiple repositories", func() { 310 BeforeEach(func() { 311 helpers.InstallConfigurablePlugin("plugin-1", "0.9.0", []helpers.PluginCommand{ 312 {Name: "banana-command-1", Help: "banana-command"}, 313 }) 314 helpers.InstallConfigurablePlugin("plugin-2", "1.9.0", []helpers.PluginCommand{ 315 {Name: "banana-command-2", Help: "banana-command"}, 316 }) 317 helpers.InstallConfigurablePlugin("plugin-3", "2.9.0", []helpers.PluginCommand{ 318 {Name: "banana-command-3", Help: "banana-command"}, 319 }) 320 }) 321 322 It("only displays the newest version of the plugin found in the repositories", func() { 323 session := helpers.CF("plugins", "--outdated", "-k") 324 Eventually(session).Should(Say("Searching repo1, repo2 for newer versions of installed plugins...")) 325 Eventually(session).Should(Say("")) 326 Eventually(session).Should(Say("plugin\\s+version\\s+latest version")) 327 Eventually(session).Should(Say("plugin-1\\s+0\\.9\\.0\\s+1\\.0\\.0")) 328 Eventually(session).Should(Say("plugin-2\\s+1\\.9\\.0\\s+2\\.0\\.0")) 329 Eventually(session).Should(Say("plugin-3\\s+2\\.9\\.0\\s+3\\.5\\.0")) 330 Eventually(session).Should(Say("")) 331 Eventually(session).Should(Say("Use 'cf install-plugin' to update a plugin to the latest version\\.")) 332 Eventually(session).Should(Exit(0)) 333 }) 334 }) 335 }) 336 }) 337 }) 338 })