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

[A0-CLI 17] feat: actions test #28

Merged
merged 11 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ require (
)

// replace gopkg.in/auth0.v5 => ../auth0
replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87

replace gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210126021204-5c077900678a
7 changes: 2 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87 h1:u6DcEF5H9NkexI/ebnZkXj6ZtBJcnQBiOPZG0y0Frao=
github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
github.com/go-auth0/auth0 v1.3.1-0.20210126021204-5c077900678a h1:/BRLQXAgdGtIho5nZdeHcoo1LdAlmeJDubyK4MCeK34=
github.com/go-auth0/auth0 v1.3.1-0.20210126021204-5c077900678a/go.mod h1:pbIRmwBulkHNKKsUGGvhyIOI2itMhz2OfwtPaFXBSSQ=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -196,9 +196,7 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down Expand Up @@ -354,7 +352,6 @@ golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fq
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
57 changes: 57 additions & 0 deletions internal/cli/actions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package cli

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/validators"
"github.com/spf13/cobra"
Expand All @@ -16,6 +21,7 @@ func actionsCmd(cli *cli) *cobra.Command {

cmd.SetUsageTemplate(resourceUsageTemplate())
cmd.AddCommand(listActionsCmd(cli))
cmd.AddCommand(testActionCmd(cli))
cmd.AddCommand(createActionCmd(cli))

return cmd
Expand Down Expand Up @@ -44,6 +50,57 @@ Lists your existing actions. To create one try:
return cmd
}

func testActionCmd(cli *cli) *cobra.Command {
var actionId string
var versionId string
var payloadFile string
var payload = make(management.Object)

cmd := &cobra.Command{
Use: "test",
Short: "Test an action draft against a payload",
Long: `$ auth0 actions test --name <actionid> --file <payload.json>`,
RunE: func(cmd *cobra.Command, args []string) error {
// Open our jsonFile
jsonFile, err := os.Open(payloadFile)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()

byteValue, _ := ioutil.ReadAll(jsonFile)
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved

err = json.Unmarshal([]byte(byteValue), &payload)
if err != nil {
return err
}
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved

var result management.Object
err = ansi.Spinner(fmt.Sprintf("Testing action: %s, version: %s", actionId, versionId), func() error {
result, err = cli.api.ActionVersion.Test(actionId, "draft", payload)
return err
})

if err != nil {
return err
}

cli.renderer.ActionTest(result)
return nil
},
}

cmd.Flags().StringVar(&actionId, "name", "", "Action ID to to test")
cmd.Flags().StringVarP(&payloadFile, "file", "f", "", "File containing the payload for the test")
cmd.Flags().StringVarP(&versionId, "version", "v", "draft", "Version ID of the action to test")

mustRequireFlags(cmd, "name", "file")

return cmd
}

func createActionCmd(cli *cli) *cobra.Command {
cmd := &cobra.Command{
Use: "create",
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cli

import (
"fmt"
"github.com/spf13/cobra"
"gopkg.in/auth0.v5/management"
"sort"
"time"

"github.com/spf13/cobra"
"gopkg.in/auth0.v5/management"
)

func getLatestLogs(cli *cli, n int) (result []*management.Log, err error) {
Expand Down
5 changes: 5 additions & 0 deletions internal/display/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func (r *Renderer) ActionList(actions []*management.Action) {
r.Results(res)
}

func (r *Renderer) ActionTest(payload management.Object) {
r.Heading(ansi.Bold(r.Tenant), "Actions test result\n")
r.JSONResult(payload)
}

func (r *Renderer) ActionCreate(action *management.Action) {
r.Heading(ansi.Bold(r.Tenant), "action created\n")

Expand Down
16 changes: 10 additions & 6 deletions internal/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,20 @@ type View interface {
AsTableRow() []string
}

func (r *Renderer) JSONResult(data interface{}) {
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
r.Errorf("couldn't marshal results as JSON: %v", err)
return
}
fmt.Fprint(r.ResultWriter, string(b))
}
turcottedanny marked this conversation as resolved.
Show resolved Hide resolved

func (r *Renderer) Results(data []View) {
if len(data) > 0 {
switch r.Format {
case OutputFormatJSON:
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
r.Errorf("couldn't marshal results as JSON: %v", err)
return
}
fmt.Fprint(r.ResultWriter, string(b))
r.JSONResult(data)

default:
rows := make([][]string, len(data))
Expand Down
4 changes: 4 additions & 0 deletions vendor/gopkg.in/auth0.v5/management/actions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions vendor/gopkg.in/auth0.v5/management/management.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ google.golang.org/protobuf/reflect/protoreflect
google.golang.org/protobuf/reflect/protoregistry
google.golang.org/protobuf/runtime/protoiface
google.golang.org/protobuf/runtime/protoimpl
# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87
# gopkg.in/auth0.v5 v5.8.0 => github.com/go-auth0/auth0 v1.3.1-0.20210126021204-5c077900678a
## explicit
gopkg.in/auth0.v5
gopkg.in/auth0.v5/internal/client
Expand All @@ -102,4 +102,4 @@ gopkg.in/auth0.v5/management
# gopkg.in/yaml.v2 v2.2.8
## explicit
gopkg.in/yaml.v2
# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210125203113-388ed60f4d87
# gopkg.in/auth0.v5 => github.com/go-auth0/auth0 v1.3.1-0.20210126021204-5c077900678a