Skip to content

Commit

Permalink
feature(kuma-cp) example in command, copied schema to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubdyszkiewicz committed Sep 17, 2019
1 parent f069ae0 commit 2a8cccf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
8 changes: 4 additions & 4 deletions app/kumactl/cmd/install/install_postgres_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

func newInstallPostgresSchemaCmd() *cobra.Command {
return &cobra.Command{
Use: "postgres-schema",
Short: "Install Kuma on Postgres DB.",
Long: `Install Kuma on Postgres DB. You can apply it with following command:
kumactl install postgres-schema | PGPASSWORD=mysecretpassword psql -h localhost -U postgres`,
Use: "postgres-schema",
Short: "Install Kuma on Postgres DB.",
Long: `Install Kuma on Postgres DB.`,
Example: "kumactl install postgres-schema | PGPASSWORD=mysecretpassword psql -h localhost -U postgres",
RunE: func(cmd *cobra.Command, _ []string) error {
file, err := data.ReadFile(postgres_schema.Schema, "resource.sql")
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions app/kumactl/cmd/install/install_postgres_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package install_test
import (
"bytes"
"github.com/Kong/kuma/app/kumactl/cmd"
"github.com/Kong/kuma/app/kumactl/pkg/install/data"
postgres_schema "github.com/Kong/kuma/app/kumactl/pkg/install/universal/control-plane/postgres"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"path/filepath"
)

var _ = Describe("kumactl install control-plane", func() {
var _ = Describe("kumactl install postgres-schema", func() {
It("should give the schema postgres", func() {
// given
stdout := bytes.Buffer{}
rootCmd := cmd.DefaultRootCmd()
rootCmd.SetOut(&stdout)
rootCmd.SetArgs([]string{"install", "postgres-schema"})

schemaFile, err := data.ReadFile(postgres_schema.Schema, "resource.sql")
bytes, err := ioutil.ReadFile(filepath.Join("testdata", "postgres_schema.sql"))
Expect(err).ToNot(HaveOccurred())

// when
err = rootCmd.Execute()

// then
Expect(err).ToNot(HaveOccurred())
Expect(string(stdout.Bytes())).To(Equal(string(schemaFile)))
Expect(string(stdout.Bytes())).To(Equal(string(bytes)))
})
})
9 changes: 9 additions & 0 deletions app/kumactl/cmd/install/testdata/postgres_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS resources (
name varchar(100) NOT NULL,
namespace varchar(100) NOT NULL,
mesh varchar(100) NOT NULL,
type varchar(100) NOT NULL,
version integer NOT NULL,
spec text,
PRIMARY KEY (name, namespace, mesh, type)
);
6 changes: 4 additions & 2 deletions docs/cmd/kumactl/HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,14 @@ Global Flags:
### kumactl install postgres-schema

```
Install Kuma on Postgres DB. You can apply it with following command:
kumactl install postgres-schema | PGPASSWORD=mysecretpassword psql -h localhost -U postgres
Install Kuma on Postgres DB.
Usage:
kumactl install postgres-schema [flags]
Examples:
kumactl install postgres-schema | PGPASSWORD=mysecretpassword psql -h localhost -U postgres
Flags:
-h, --help help for postgres-schema
Expand Down

0 comments on commit 2a8cccf

Please sign in to comment.