Skip to content

Commit

Permalink
Merge branch 'products-command' of https://github.com/iplay88keys/om
Browse files Browse the repository at this point in the history
…into main
  • Loading branch information
kcboyle committed Oct 16, 2020
2 parents 30dafdc + 8056b29 commit e78c22f
Show file tree
Hide file tree
Showing 24 changed files with 1,320 additions and 16 deletions.
314 changes: 314 additions & 0 deletions acceptance/products_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,314 @@
package acceptance

import (
"github.com/onsi/gomega/ghttp"
"net/http"
"os/exec"

"github.com/onsi/gomega/gexec"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("products command", func() {
const defaultTableOutput = `+----------------+-----------+--------+----------+
| NAME | AVAILABLE | STAGED | DEPLOYED |
+----------------+-----------+--------+----------+
| acme-product-1 | 1.13.1 | 1.13.2 | 1.13.3 |
| | 1.13.2 | | |
| acme-product-2 | 1.8.0 | 1.8.1 | |
| p-bosh | | 1.9.1 | 1.9.1 |
+----------------+-----------+--------+----------+
`

const availableTableOutput = `+----------------+-----------+
| NAME | AVAILABLE |
+----------------+-----------+
| acme-product-1 | 1.13.1 |
| | 1.13.2 |
| acme-product-2 | 1.8.0 |
+----------------+-----------+
`

const stagedTableOutput = `+----------------+--------+
| NAME | STAGED |
+----------------+--------+
| acme-product-1 | 1.13.2 |
| acme-product-2 | 1.8.1 |
| p-bosh | 1.9.1 |
+----------------+--------+
`

const deployedTableOutput = `+----------------+----------+
| NAME | DEPLOYED |
+----------------+----------+
| acme-product-1 | 1.13.3 |
| p-bosh | 1.9.1 |
+----------------+----------+
`

const defaultJsonOutput = `[
{"name":"acme-product-1","available":["1.13.1","1.13.2"],"staged":"1.13.2","deployed":"1.13.3"},
{"name":"acme-product-2","available":["1.8.0"],"staged":"1.8.1"},
{"name":"p-bosh","staged":"1.9.1","deployed":"1.9.1"}
]`

const availableJsonOutput = `[
{"name":"acme-product-1","available":["1.13.1","1.13.2"]},
{"name":"acme-product-2","available":["1.8.0"]}
]`

const stagedJsonOutput = `[
{"name":"acme-product-1","staged":"1.13.2"},
{"name":"acme-product-2","staged":"1.8.1"},
{"name":"p-bosh","staged":"1.9.1"}
]`

const deployedJsonOutput = `[
{"name":"acme-product-1","deployed":"1.13.3"},
{"name":"p-bosh","deployed":"1.9.1"}
]`

const diagnosticReport = `{
"added_products": {
"staged": [
{"name":"acme-product-1","version":"1.13.2"},
{"name":"acme-product-2","version":"1.8.1"},
{"name":"p-bosh","version":"1.9.1"}
],
"deployed": [
{"name":"acme-product-1","version":"1.13.3"},
{"name":"p-bosh","version":"1.9.1"}
]
}
}`

const availableProducts = `[{
"name": "acme-product-1",
"product_version": "1.13.1"
}, {
"name": "acme-product-1",
"product_version": "1.13.2"
}, {
"name":"acme-product-2",
"product_version":"1.8.0"
}]`

var (
server *ghttp.Server
)

BeforeEach(func() {
server = createTLSServer()
server.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v0/diagnostic_report"),
ghttp.RespondWith(http.StatusOK, diagnosticReport),
),
ghttp.CombineHandlers(
ghttp.VerifyRequest("GET", "/api/v0/available_products"),
ghttp.RespondWith(http.StatusOK, availableProducts),
),
)
})

AfterEach(func() {
server.Close()
})

It("lists all products on the Ops Manager as well as their available, staged, and deployed versions", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(defaultTableOutput))
})

When("json format is requested", func() {
It("lists the available, staged, and deployed products on Ops Manager", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--format", "json",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(MatchJSON(defaultJsonOutput))
})
})

When("--available flag is passed", func() {
It("lists all available products on the Ops Manager as well as their versions", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--available",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(availableTableOutput))
})

When("json format is requested", func() {
It("lists the available products on Ops Manager", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--available",
"--format", "json",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(MatchJSON(availableJsonOutput))
})
})
})

When("--staged flag is passed", func() {
It("lists all staged products on the Ops Manager as well as their versions", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--staged",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(stagedTableOutput))
})

When("json format is requested", func() {
It("lists the staged products on Ops Manager", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--staged",
"--format", "json",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(MatchJSON(stagedJsonOutput))
})
})
})

When("--deployed flag is passed", func() {
It("lists all deployed products on the Ops Manager as well as their versions", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--deployed",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(deployedTableOutput))
})

When("json format is requested", func() {
It("lists the deployed products on Ops Manager", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--deployed",
"--format", "json",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(MatchJSON(deployedJsonOutput))
})
})
})

When("--available, --staged, and --deployed flags are passed", func() {
It("lists all products on the Ops Manager as well as their available, staged, and deployed versions", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--available",
"--staged",
"--deployed",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(Equal(defaultTableOutput))
})

When("json format is requested", func() {
It("lists the staged products on Ops Manager", func() {
command := exec.Command(pathToMain,
"--target", server.URL(),
"--username", "some-username",
"--password", "some-password",
"--skip-ssl-validation",
"products",
"--available",
"--staged",
"--deployed",
"--format", "json",
)

session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())

Eventually(session).Should(gexec.Exit(0))
Expect(string(session.Out.Contents())).To(MatchJSON(defaultJsonOutput))
})
})
})
})
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func Main(sout io.Writer, serr io.Writer, version string, applySleepDurationStri
commandSet["pending-changes"] = commands.NewPendingChanges(presenter, api, stderr)
commandSet["pre-deploy-check"] = commands.NewPreDeployCheck(presenter, api, stdout)
commandSet["product-metadata"] = commands.NewProductMetadata(stdout)
commandSet["products"] = commands.NewProducts(presenter, api)
commandSet["regenerate-certificates"] = commands.NewRegenerateCertificates(api, stdout)
commandSet["revert-staged-changes"] = commands.NewRevertStagedChanges(api, stdout)
commandSet["ssl-certificate"] = commands.NewSSLCertificate(api, presenter)
Expand Down
4 changes: 2 additions & 2 deletions commands/available_products.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (ap AvailableProducts) Execute(args []string) error {

func (ap AvailableProducts) Usage() jhanda.Usage {
return jhanda.Usage{
Description: "This authenticated command lists all available products.",
ShortDescription: "list available products",
Description: "**DEPRECATED** This authenticated command lists all available products. Use 'products --available' instead.",
ShortDescription: "**DEPRECATED** lists available products. Use 'products --available' instead.",
Flags: ap.Options,
}
}
4 changes: 2 additions & 2 deletions commands/deployed_products.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (dp DeployedProducts) Execute(args []string) error {

func (dp DeployedProducts) Usage() jhanda.Usage {
return jhanda.Usage{
Description: "This authenticated command lists all deployed products.",
ShortDescription: "lists deployed products",
Description: "**DEPRECATED** This authenticated command lists all deployed products. Use 'products --deployed' instead.",
ShortDescription: "**DEPRECATED** lists deployed products. Use 'products --deployed' instead.",
Flags: dp.Options,
}
}
Loading

0 comments on commit e78c22f

Please sign in to comment.