Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add initial e2e test #380

Merged
merged 5 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:
image: circleci/golang:1.15
environment:
TEST_DATABASE_POSTGRESQL: postgres://test:test@localhost:5432/keto?sslmode=disable
TEST_DATABASE_MYSQL: root:test@(localhost:3306)/mysql?parseTime=true
TEST_DATABASE_MYSQL: mysql://root:test@(localhost:3306)/mysql?parseTime=true&multiStatements=true
TEST_DATABASE_COCKROACHDB: cockroach://root@localhost:26257/defaultdb?sslmode=disable
-
image: postgres:9.5
image: postgres:11.8
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
Expand All @@ -27,6 +28,9 @@ jobs:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: test
-
image: cockroachdb/cockroach:v20.1.0
command: start --insecure
working_directory: /go/src/github.com/ory/keto
steps:
- checkout
Expand All @@ -41,7 +45,7 @@ jobs:

# Tests
-
run: go test -tags sqlite -race -short -v $(go list ./... | grep -v cmd)
run: go test -tags sqlite -race -short -v ./...
-
run: go-acc -o coverage.txt ./... -- -v -tags sqlite

Expand Down
79 changes: 53 additions & 26 deletions .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,35 +197,62 @@
},
"serve": {
"type": "object",
"title": "HTTP REST API",
"additionalProperties": false,
"properties": {
"port": {
"type": "integer",
"default": 4456,
"title": "Port",
"description": "The port to listen on.",
"minimum": 1,
"maximum": 65535,
"examples": [
4456
]
},
"host": {
"type": "string",
"default": "",
"examples": [
"localhost",
"127.0.0.1"
],
"title": "Host",
"description": "The network interface to listen on."
},
"cors": {
"$ref": "#/definitions/cors"
"rest": {
"type": "object",
"title": "HTTP REST API",
"additionalProperties": false,
"properties": {
"port": {
"type": "integer",
"default": 4466,
"title": "Port",
"description": "The port to listen on.",
"minimum": 1,
"maximum": 65535
},
"host": {
"type": "string",
"default": "",
"examples": [
"localhost",
"127.0.0.1"
],
"title": "Host",
"description": "The network interface to listen on."
},
"cors": {
"$ref": "#/definitions/cors"
},
"tls": {
"$ref": "#/definitions/tlsx"
}
}
},
"tls": {
"$ref": "#/definitions/tlsx"
"grpc": {
"type": "object",
"additionalProperties": false,
"properties": {
"port": {
"type": "integer",
"default": 4467,
"title": "Port",
"description": "The port to listen on.",
"minimum": 1,
"maximum": 65535
},
"host": {
"type": "string",
"default": "",
"examples": [
"localhost",
"127.0.0.1"
],
"title": "Host",
"description": "The network interface to listen on."
}
}
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,11 @@ buf-lint: deps
#
.PHONY: buf
buf: buf-lint buf-gen

.PHONY: reset-testdb
reset-testdb:
source scripts/test-resetdb.sh

.PHONY: e2e-test
e2e-test:
go test -tags sqlite -failfast -v ./internal/e2e
10 changes: 7 additions & 3 deletions cmd/migrate/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package migrate

import "github.com/spf13/cobra"

var migrateCmd = &cobra.Command{
Use: "migrate",
func newMigrateCmd() *cobra.Command {
return &cobra.Command{
Use: "migrate",
}
}

func RegisterCommandRecursive(parent *cobra.Command) {
func RegisterCommandsRecursive(parent *cobra.Command) {
migrateCmd := newMigrateCmd()

migrateCmd.AddCommand(newStatusCmd(), newUpCmd())

parent.AddCommand(migrateCmd)
Expand Down
10 changes: 5 additions & 5 deletions cmd/migrate/status.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package migrate

import (
"context"
"fmt"

"github.com/ory/x/cmdx"
"github.com/ory/x/logrusx"
"github.com/spf13/cobra"

"github.com/ory/keto/internal/driver"
Expand All @@ -15,10 +13,12 @@ func newStatusCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "status",
RunE: func(cmd *cobra.Command, _ []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := cmd.Context()

reg := driver.NewDefaultRegistry(ctx, logrusx.New("keto", "test"), cmd.Flags(), "test", "adf", "today")
reg, err := driver.NewDefaultRegistry(ctx, cmd.Flags())
if err != nil {
return err
}
if err := reg.Migrator().MigrationStatus(ctx, cmd.OutOrStdout()); err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Could not get migration status: %+v\n", err)
return cmdx.FailSilently(cmd)
Expand Down
26 changes: 21 additions & 5 deletions cmd/migrate/up.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
package migrate

import (
"context"
"fmt"

"github.com/ory/x/cmdx"
"github.com/ory/x/logrusx"
"github.com/ory/x/flagx"
"github.com/spf13/cobra"

"github.com/ory/keto/internal/driver"
)

const FlagYes = "yes"

func newUpCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "up",
RunE: func(cmd *cobra.Command, _ []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := cmd.Context()

reg, err := driver.NewDefaultRegistry(ctx, cmd.Flags())
if err != nil {
return err
}
if err := reg.Migrator().MigrationStatus(ctx, cmd.OutOrStdout()); err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Could not get migration status: %+v\n", err)
return cmdx.FailSilently(cmd)
}

if !flagx.MustGetBool(cmd, FlagYes) && !cmdx.AskForConfirmation("Do you want to apply above planned migrations?", cmd.InOrStdin(), cmd.OutOrStdout()) {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "Aborting")
return nil
}

reg := driver.NewDefaultRegistry(ctx, logrusx.New("keto", "test"), cmd.Flags(), "test", "adf", "today")
if err := reg.Migrator().MigrateUp(ctx); err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Could not apply migrations: %+v\n", err)
return cmdx.FailSilently(cmd)
}
return nil
},
}

cmd.Flags().BoolP(FlagYes, "y", false, "yes to all questions, no user input required")

return cmd
}
23 changes: 15 additions & 8 deletions cmd/namespace/migrate.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package namespace

import (
"context"
"errors"
"fmt"

"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/ory/x/logrusx"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

Expand All @@ -17,20 +15,29 @@ import (

func NewMigrateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate <namespaces.yml>",
Use: "migrate <namespace-name>",
Short: "Migrate a namespace up.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := cmd.Context()

reg := driver.NewDefaultRegistry(ctx, logrusx.New("keto", "master"), cmd.Flags(), "master", "local", "today")

n, err := validateNamespaceFile(cmd, args[0])
reg, err := driver.NewDefaultRegistry(ctx, cmd.Flags())
if err != nil {
return err
}

nm, err := reg.Config().NamespaceManager()
if err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Could not initialize the namespace manager: %+v\n", err)
return cmdx.FailSilently(cmd)
}

n, err := nm.GetNamespace(ctx, args[0])
if err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Could not find the namespace with name \"%s\": %+v\n", args[0], err)
return cmdx.FailSilently(cmd)
}

status, err := reg.NamespaceMigrator().NamespaceStatus(ctx, n.ID)
if err != nil {
if !errors.Is(err, persistence.ErrNamespaceUnknown) {
Expand Down
10 changes: 7 additions & 3 deletions cmd/relationtuple/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import (
"github.com/ory/keto/cmd/client"
)

var relationCmd = &cobra.Command{
Use: "relation-tuple",
func newRelationCmd() *cobra.Command {
return &cobra.Command{
Use: "relation-tuple",
}
}

var packageFlags = pflag.NewFlagSet("relation package flags", pflag.ContinueOnError)

func RegisterCommandRecursive(parent *cobra.Command) {
func RegisterCommandsRecursive(parent *cobra.Command) {
relationCmd := newRelationCmd()

parent.AddCommand(relationCmd)

relationCmd.AddCommand(newGetCmd())
Expand Down
Loading