From f6d521184b0df3c0c6e65174aface9934e8971c2 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Fri, 14 Jul 2023 18:27:53 -0300 Subject: [PATCH] feat(cli): add `required-gates` flag (#2944) --- cli/cmd/resource_run_cmd.go | 30 +++- cli/go.mod | 17 ++- cli/go.sum | 35 ++--- cli/openapi/model_required_gates_result.go | 169 +++++++++++++++++++++ cli/openapi/model_run_information.go | 37 +++++ cli/openapi/model_supported_gates.go | 112 ++++++++++++++ cli/openapi/model_test_run.go | 36 +++++ cli/openapi/model_transaction_run.go | 56 +++++-- cli/runner/orchestrator.go | 18 +++ go.work.sum | 8 +- 10 files changed, 479 insertions(+), 39 deletions(-) create mode 100644 cli/openapi/model_required_gates_result.go create mode 100644 cli/openapi/model_supported_gates.go diff --git a/cli/cmd/resource_run_cmd.go b/cli/cmd/resource_run_cmd.go index 759e4ac595..3304028b33 100644 --- a/cli/cmd/resource_run_cmd.go +++ b/cli/cmd/resource_run_cmd.go @@ -3,7 +3,9 @@ package cmd import ( "context" "fmt" + "strings" + "github.com/kubeshop/tracetest/cli/openapi" "github.com/kubeshop/tracetest/cli/runner" "github.com/kubeshop/tracetest/cli/utils" "github.com/spf13/cobra" @@ -42,6 +44,7 @@ func init() { EnvID: runParams.EnvID, SkipResultWait: runParams.SkipResultWait, JUnitOuptutFile: runParams.JUnitOuptutFile, + RequiredGates: runParams.RequriedGates, } exitCode, err := orchestrator.Run(ctx, r, runParams, output) @@ -60,18 +63,29 @@ func init() { runCmd.Flags().StringVarP(&runParams.DefinitionFile, "file", "f", "", "path to the definition file") runCmd.Flags().StringVar(&runParams.ID, "id", "", "id of the resource to run") - runCmd.PersistentFlags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used") - runCmd.PersistentFlags().BoolVarP(&runParams.SkipResultWait, "skip-result-wait", "W", false, "do not wait for results. exit immediately after test run started") - runCmd.PersistentFlags().StringVarP(&runParams.JUnitOuptutFile, "junit", "j", "", "file path to save test results in junit format") + runCmd.Flags().StringVarP(&runParams.EnvID, "environment", "e", "", "environment file or ID to be used") + runCmd.Flags().BoolVarP(&runParams.SkipResultWait, "skip-result-wait", "W", false, "do not wait for results. exit immediately after test run started") + runCmd.Flags().StringVarP(&runParams.JUnitOuptutFile, "junit", "j", "", "file path to save test results in junit format") + runCmd.Flags().StringSliceVar(&runParams.RequriedGates, "required-gates", []string{}, "override default required gate. "+validRequiredGatesMsg()) rootCmd.AddCommand(runCmd) } +func validRequiredGatesMsg() string { + opts := make([]string, 0, len(openapi.AllowedSupportedGatesEnumValues)) + for _, v := range openapi.AllowedSupportedGatesEnumValues { + opts = append(opts, string(v)) + } + + return "valid options: " + strings.Join(opts, ", ") +} + type runParameters struct { ID string DefinitionFile string EnvID string SkipResultWait bool JUnitOuptutFile string + RequriedGates []string } func (p runParameters) Validate(cmd *cobra.Command, args []string) []error { @@ -97,5 +111,15 @@ func (p runParameters) Validate(cmd *cobra.Command, args []string) []error { }) } + for _, rg := range p.RequriedGates { + _, err := openapi.NewSupportedGatesFromValue(rg) + if err != nil { + errs = append(errs, paramError{ + Parameter: "required-gates", + Message: fmt.Sprintf("invalid option '%s'. "+validRequiredGatesMsg(), rg), + }) + } + } + return errs } diff --git a/cli/go.mod b/cli/go.mod index 2b379c615d..286346f290 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -12,13 +12,13 @@ require ( github.com/goccy/go-yaml v1.11.0 github.com/kubeshop/tracetest/server v0.0.0-20230512142545-cb5e526e06f9 github.com/pterm/pterm v0.12.55 - github.com/spf13/cobra v1.6.1 + github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.15.0 github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.23.0 - golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 - golang.org/x/text v0.8.0 + golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 + golang.org/x/text v0.9.0 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -36,14 +36,14 @@ require ( github.com/felixge/httpsnoop v1.0.3 // indirect github.com/fluidtruck/deepcopy v1.0.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.2.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gookit/color v1.5.2 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.13 // indirect - github.com/inconshreveable/mousetrap v1.0.1 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/klauspost/compress v1.15.10 // indirect github.com/lithammer/fuzzysearch v1.1.5 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -59,7 +59,7 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/segmentio/backo-go v1.0.1 // indirect - github.com/sirupsen/logrus v1.9.0 // indirect + github.com/sirupsen/logrus v1.9.2 // indirect github.com/spf13/afero v1.9.3 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect @@ -78,9 +78,10 @@ require ( go.opentelemetry.io/otel/trace v1.10.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect + golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect - golang.org/x/sys v0.6.0 // indirect - golang.org/x/term v0.5.0 // indirect + golang.org/x/sys v0.8.0 // indirect + golang.org/x/term v0.8.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/grpc v1.53.0 // indirect google.golang.org/protobuf v1.28.1 // indirect diff --git a/cli/go.sum b/cli/go.sum index 51df86e8f7..91b2ff6e5a 100644 --- a/cli/go.sum +++ b/cli/go.sum @@ -117,8 +117,8 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9 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= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= @@ -210,8 +210,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= -github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= -github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/j2gg0s/otsql v0.14.0 h1:keAORDX9RoQcc47KPE/wAyHZPCA7eI8uhXafpVcrWZ8= github.com/jhump/protoreflect v1.12.0 h1:1NQ4FpWMgn3by/n1X0fbeKEUxP1wBt7+Oitpv01HR10= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= @@ -296,14 +296,14 @@ github.com/segmentio/backo-go v1.0.1 h1:68RQccglxZeyURy93ASB/2kc9QudzgIDexJ927N+ github.com/segmentio/backo-go v1.0.1/go.mod h1:9/Rh6yILuLysoQnZ2oNooD2g7aBnvM7r/fNVxRNWfBc= github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= -github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= -github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y= +github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk= github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= -github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= -github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= +github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= +github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -399,8 +399,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 h1:5oN1Pz/eDhCpbMbLstvIPa0b/BEQo6g6nwV3pLjfM6w= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= +golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -455,7 +455,8 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -520,14 +521,14 @@ golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 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= @@ -535,8 +536,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= -golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 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= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/cli/openapi/model_required_gates_result.go b/cli/openapi/model_required_gates_result.go new file mode 100644 index 0000000000..a21fb51ad7 --- /dev/null +++ b/cli/openapi/model_required_gates_result.go @@ -0,0 +1,169 @@ +/* +TraceTest + +OpenAPI definition for TraceTest endpoint and resources + +API version: 0.2.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package openapi + +import ( + "encoding/json" +) + +// checks if the RequiredGatesResult type satisfies the MappedNullable interface at compile time +var _ MappedNullable = &RequiredGatesResult{} + +// RequiredGatesResult struct for RequiredGatesResult +type RequiredGatesResult struct { + Required []SupportedGates `json:"required"` + Failed []SupportedGates `json:"failed"` + Passed bool `json:"passed"` +} + +// NewRequiredGatesResult instantiates a new RequiredGatesResult object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewRequiredGatesResult(required []SupportedGates, failed []SupportedGates, passed bool) *RequiredGatesResult { + this := RequiredGatesResult{} + this.Required = required + this.Failed = failed + this.Passed = passed + return &this +} + +// NewRequiredGatesResultWithDefaults instantiates a new RequiredGatesResult object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewRequiredGatesResultWithDefaults() *RequiredGatesResult { + this := RequiredGatesResult{} + return &this +} + +// GetRequired returns the Required field value +func (o *RequiredGatesResult) GetRequired() []SupportedGates { + if o == nil { + var ret []SupportedGates + return ret + } + + return o.Required +} + +// GetRequiredOk returns a tuple with the Required field value +// and a boolean to check if the value has been set. +func (o *RequiredGatesResult) GetRequiredOk() ([]SupportedGates, bool) { + if o == nil { + return nil, false + } + return o.Required, true +} + +// SetRequired sets field value +func (o *RequiredGatesResult) SetRequired(v []SupportedGates) { + o.Required = v +} + +// GetFailed returns the Failed field value +func (o *RequiredGatesResult) GetFailed() []SupportedGates { + if o == nil { + var ret []SupportedGates + return ret + } + + return o.Failed +} + +// GetFailedOk returns a tuple with the Failed field value +// and a boolean to check if the value has been set. +func (o *RequiredGatesResult) GetFailedOk() ([]SupportedGates, bool) { + if o == nil { + return nil, false + } + return o.Failed, true +} + +// SetFailed sets field value +func (o *RequiredGatesResult) SetFailed(v []SupportedGates) { + o.Failed = v +} + +// GetPassed returns the Passed field value +func (o *RequiredGatesResult) GetPassed() bool { + if o == nil { + var ret bool + return ret + } + + return o.Passed +} + +// GetPassedOk returns a tuple with the Passed field value +// and a boolean to check if the value has been set. +func (o *RequiredGatesResult) GetPassedOk() (*bool, bool) { + if o == nil { + return nil, false + } + return &o.Passed, true +} + +// SetPassed sets field value +func (o *RequiredGatesResult) SetPassed(v bool) { + o.Passed = v +} + +func (o RequiredGatesResult) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o RequiredGatesResult) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + toSerialize["required"] = o.Required + toSerialize["failed"] = o.Failed + toSerialize["passed"] = o.Passed + return toSerialize, nil +} + +type NullableRequiredGatesResult struct { + value *RequiredGatesResult + isSet bool +} + +func (v NullableRequiredGatesResult) Get() *RequiredGatesResult { + return v.value +} + +func (v *NullableRequiredGatesResult) Set(val *RequiredGatesResult) { + v.value = val + v.isSet = true +} + +func (v NullableRequiredGatesResult) IsSet() bool { + return v.isSet +} + +func (v *NullableRequiredGatesResult) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableRequiredGatesResult(val *RequiredGatesResult) *NullableRequiredGatesResult { + return &NullableRequiredGatesResult{value: val, isSet: true} +} + +func (v NullableRequiredGatesResult) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableRequiredGatesResult) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/cli/openapi/model_run_information.go b/cli/openapi/model_run_information.go index 4fc35351f3..a9e37349a3 100644 --- a/cli/openapi/model_run_information.go +++ b/cli/openapi/model_run_information.go @@ -22,6 +22,7 @@ type RunInformation struct { Metadata map[string]string `json:"metadata,omitempty"` EnvironmentId *string `json:"environmentId,omitempty"` Variables []EnvironmentValue `json:"variables,omitempty"` + RequiredGates []SupportedGates `json:"requiredGates,omitempty"` } // NewRunInformation instantiates a new RunInformation object @@ -138,6 +139,39 @@ func (o *RunInformation) SetVariables(v []EnvironmentValue) { o.Variables = v } +// GetRequiredGates returns the RequiredGates field value if set, zero value otherwise (both if not set or set to explicit null). +func (o *RunInformation) GetRequiredGates() []SupportedGates { + if o == nil { + var ret []SupportedGates + return ret + } + return o.RequiredGates +} + +// GetRequiredGatesOk returns a tuple with the RequiredGates field value if set, nil otherwise +// and a boolean to check if the value has been set. +// NOTE: If the value is an explicit nil, `nil, true` will be returned +func (o *RunInformation) GetRequiredGatesOk() ([]SupportedGates, bool) { + if o == nil || isNil(o.RequiredGates) { + return nil, false + } + return o.RequiredGates, true +} + +// HasRequiredGates returns a boolean if a field has been set. +func (o *RunInformation) HasRequiredGates() bool { + if o != nil && isNil(o.RequiredGates) { + return true + } + + return false +} + +// SetRequiredGates gets a reference to the given []SupportedGates and assigns it to the RequiredGates field. +func (o *RunInformation) SetRequiredGates(v []SupportedGates) { + o.RequiredGates = v +} + func (o RunInformation) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -157,6 +191,9 @@ func (o RunInformation) ToMap() (map[string]interface{}, error) { if !isNil(o.Variables) { toSerialize["variables"] = o.Variables } + if o.RequiredGates != nil { + toSerialize["requiredGates"] = o.RequiredGates + } return toSerialize, nil } diff --git a/cli/openapi/model_supported_gates.go b/cli/openapi/model_supported_gates.go new file mode 100644 index 0000000000..9963f972d6 --- /dev/null +++ b/cli/openapi/model_supported_gates.go @@ -0,0 +1,112 @@ +/* +TraceTest + +OpenAPI definition for TraceTest endpoint and resources + +API version: 0.2.1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package openapi + +import ( + "encoding/json" + "fmt" +) + +// SupportedGates the model 'SupportedGates' +type SupportedGates string + +// List of SupportedGates +const ( + ANALYZER_SCORE SupportedGates = "analyzer-score" + ANALYZER_RULES SupportedGates = "analyzer-rules" + TEST_SPECS SupportedGates = "test-specs" +) + +// All allowed values of SupportedGates enum +var AllowedSupportedGatesEnumValues = []SupportedGates{ + "analyzer-score", + "analyzer-rules", + "test-specs", +} + +func (v *SupportedGates) UnmarshalJSON(src []byte) error { + var value string + err := json.Unmarshal(src, &value) + if err != nil { + return err + } + enumTypeValue := SupportedGates(value) + for _, existing := range AllowedSupportedGatesEnumValues { + if existing == enumTypeValue { + *v = enumTypeValue + return nil + } + } + + return fmt.Errorf("%+v is not a valid SupportedGates", value) +} + +// NewSupportedGatesFromValue returns a pointer to a valid SupportedGates +// for the value passed as argument, or an error if the value passed is not allowed by the enum +func NewSupportedGatesFromValue(v string) (*SupportedGates, error) { + ev := SupportedGates(v) + if ev.IsValid() { + return &ev, nil + } else { + return nil, fmt.Errorf("invalid value '%v' for SupportedGates: valid values are %v", v, AllowedSupportedGatesEnumValues) + } +} + +// IsValid return true if the value is valid for the enum, false otherwise +func (v SupportedGates) IsValid() bool { + for _, existing := range AllowedSupportedGatesEnumValues { + if existing == v { + return true + } + } + return false +} + +// Ptr returns reference to SupportedGates value +func (v SupportedGates) Ptr() *SupportedGates { + return &v +} + +type NullableSupportedGates struct { + value *SupportedGates + isSet bool +} + +func (v NullableSupportedGates) Get() *SupportedGates { + return v.value +} + +func (v *NullableSupportedGates) Set(val *SupportedGates) { + v.value = val + v.isSet = true +} + +func (v NullableSupportedGates) IsSet() bool { + return v.isSet +} + +func (v *NullableSupportedGates) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSupportedGates(val *SupportedGates) *NullableSupportedGates { + return &NullableSupportedGates{value: val, isSet: true} +} + +func (v NullableSupportedGates) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSupportedGates) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/cli/openapi/model_test_run.go b/cli/openapi/model_test_run.go index 4044e6bbe4..55b2f4f518 100644 --- a/cli/openapi/model_test_run.go +++ b/cli/openapi/model_test_run.go @@ -44,6 +44,7 @@ type TestRun struct { Result *AssertionResults `json:"result,omitempty"` Linter *LinterResult `json:"linter,omitempty"` Outputs []TestRunOutputsInner `json:"outputs,omitempty"` + RequiredGatesResult *RequiredGatesResult `json:"requiredGatesResult,omitempty"` Metadata *map[string]string `json:"metadata,omitempty"` TransactionId *string `json:"transactionId,omitempty"` TransactionRunId *string `json:"transactionRunId,omitempty"` @@ -674,6 +675,38 @@ func (o *TestRun) SetOutputs(v []TestRunOutputsInner) { o.Outputs = v } +// GetRequiredGatesResult returns the RequiredGatesResult field value if set, zero value otherwise. +func (o *TestRun) GetRequiredGatesResult() RequiredGatesResult { + if o == nil || isNil(o.RequiredGatesResult) { + var ret RequiredGatesResult + return ret + } + return *o.RequiredGatesResult +} + +// GetRequiredGatesResultOk returns a tuple with the RequiredGatesResult field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TestRun) GetRequiredGatesResultOk() (*RequiredGatesResult, bool) { + if o == nil || isNil(o.RequiredGatesResult) { + return nil, false + } + return o.RequiredGatesResult, true +} + +// HasRequiredGatesResult returns a boolean if a field has been set. +func (o *TestRun) HasRequiredGatesResult() bool { + if o != nil && !isNil(o.RequiredGatesResult) { + return true + } + + return false +} + +// SetRequiredGatesResult gets a reference to the given RequiredGatesResult and assigns it to the RequiredGatesResult field. +func (o *TestRun) SetRequiredGatesResult(v RequiredGatesResult) { + o.RequiredGatesResult = &v +} + // GetMetadata returns the Metadata field value if set, zero value otherwise. func (o *TestRun) GetMetadata() map[string]string { if o == nil || isNil(o.Metadata) { @@ -831,6 +864,9 @@ func (o TestRun) ToMap() (map[string]interface{}, error) { if !isNil(o.Outputs) { toSerialize["outputs"] = o.Outputs } + if !isNil(o.RequiredGatesResult) { + toSerialize["requiredGatesResult"] = o.RequiredGatesResult + } if !isNil(o.Metadata) { toSerialize["metadata"] = o.Metadata } diff --git a/cli/openapi/model_transaction_run.go b/cli/openapi/model_transaction_run.go index abb5220cb3..ef9fd0e91e 100644 --- a/cli/openapi/model_transaction_run.go +++ b/cli/openapi/model_transaction_run.go @@ -20,16 +20,17 @@ var _ MappedNullable = &TransactionRun{} // TransactionRun struct for TransactionRun type TransactionRun struct { - Id *string `json:"id,omitempty"` - Version *int32 `json:"version,omitempty"` - CreatedAt *time.Time `json:"createdAt,omitempty"` - CompletedAt *time.Time `json:"completedAt,omitempty"` - State *string `json:"state,omitempty"` - Steps []TestRun `json:"steps,omitempty"` - Environment *Environment `json:"environment,omitempty"` - Metadata *map[string]string `json:"metadata,omitempty"` - Pass *int32 `json:"pass,omitempty"` - Fail *int32 `json:"fail,omitempty"` + Id *string `json:"id,omitempty"` + Version *int32 `json:"version,omitempty"` + CreatedAt *time.Time `json:"createdAt,omitempty"` + CompletedAt *time.Time `json:"completedAt,omitempty"` + State *string `json:"state,omitempty"` + Steps []TestRun `json:"steps,omitempty"` + Environment *Environment `json:"environment,omitempty"` + Metadata *map[string]string `json:"metadata,omitempty"` + Pass *int32 `json:"pass,omitempty"` + Fail *int32 `json:"fail,omitempty"` + AllStepsRequiredGatesPassed *bool `json:"allStepsRequiredGatesPassed,omitempty"` } // NewTransactionRun instantiates a new TransactionRun object @@ -369,6 +370,38 @@ func (o *TransactionRun) SetFail(v int32) { o.Fail = &v } +// GetAllStepsRequiredGatesPassed returns the AllStepsRequiredGatesPassed field value if set, zero value otherwise. +func (o *TransactionRun) GetAllStepsRequiredGatesPassed() bool { + if o == nil || isNil(o.AllStepsRequiredGatesPassed) { + var ret bool + return ret + } + return *o.AllStepsRequiredGatesPassed +} + +// GetAllStepsRequiredGatesPassedOk returns a tuple with the AllStepsRequiredGatesPassed field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TransactionRun) GetAllStepsRequiredGatesPassedOk() (*bool, bool) { + if o == nil || isNil(o.AllStepsRequiredGatesPassed) { + return nil, false + } + return o.AllStepsRequiredGatesPassed, true +} + +// HasAllStepsRequiredGatesPassed returns a boolean if a field has been set. +func (o *TransactionRun) HasAllStepsRequiredGatesPassed() bool { + if o != nil && !isNil(o.AllStepsRequiredGatesPassed) { + return true + } + + return false +} + +// SetAllStepsRequiredGatesPassed gets a reference to the given bool and assigns it to the AllStepsRequiredGatesPassed field. +func (o *TransactionRun) SetAllStepsRequiredGatesPassed(v bool) { + o.AllStepsRequiredGatesPassed = &v +} + func (o TransactionRun) MarshalJSON() ([]byte, error) { toSerialize, err := o.ToMap() if err != nil { @@ -405,6 +438,9 @@ func (o TransactionRun) ToMap() (map[string]interface{}, error) { if !isNil(o.Fail) { toSerialize["fail"] = o.Fail } + if !isNil(o.AllStepsRequiredGatesPassed) { + toSerialize["allStepsRequiredGatesPassed"] = o.AllStepsRequiredGatesPassed + } return toSerialize, nil } diff --git a/cli/runner/orchestrator.go b/cli/runner/orchestrator.go index b620ae68b2..30915263c3 100644 --- a/cli/runner/orchestrator.go +++ b/cli/runner/orchestrator.go @@ -40,6 +40,9 @@ type RunOptions struct { // Optional path to the file where the result of the run will be saved // in JUnit xml format JUnitOuptutFile string + + // Overrides the default required gates for the resource + RequiredGates []string } // RunResult holds the result of the run @@ -122,6 +125,7 @@ func (o orchestrator) Run(ctx context.Context, r Runner, opts RunOptions, output zap.String("envID", opts.EnvID), zap.Bool("skipResultsWait", opts.SkipResultWait), zap.String("junitOutputFile", opts.JUnitOuptutFile), + zap.Strings("requiredGates", opts.RequiredGates), ) envID, err := o.resolveEnvID(ctx, opts.EnvID) @@ -168,6 +172,7 @@ func (o orchestrator) Run(ctx context.Context, r Runner, opts RunOptions, output EnvironmentId: &envID, Variables: ev.toOpenapi(), Metadata: getMetadata(), + RequiredGates: getRequiredGates(opts.RequiredGates), } result, err = r.StartRun(ctx, resource, runInfo) @@ -348,6 +353,19 @@ func getMetadata() map[string]string { return metadata } +func getRequiredGates(gates []string) []openapi.SupportedGates { + if len(gates) == 0 { + return nil + } + requiredGates := make([]openapi.SupportedGates, 0, len(gates)) + + for _, g := range gates { + requiredGates = append(requiredGates, openapi.SupportedGates(g)) + } + + return requiredGates +} + // HandleRunError handles errors returned by the server when running a test. // It normalizes the handling of general errors, like 404, // but more importantly, it processes the missing environment variables error diff --git a/go.work.sum b/go.work.sum index d82dc02383..441b3890f6 100644 --- a/go.work.sum +++ b/go.work.sum @@ -263,7 +263,6 @@ github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WT github.com/mostynb/go-grpc-compression v1.1.17/go.mod h1:FUSBr0QjKqQgoDG/e0yiqlR6aqyXC39+g/hFLDfSsEY= github.com/opencontainers/runc v1.1.2/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc= github.com/opencontainers/selinux v1.10.1/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI= -github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= @@ -308,6 +307,7 @@ go.opentelemetry.io/otel/trace v1.9.0/go.mod h1:2737Q0MuG8q1uILYm2YYVkAyLtOofiTN go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -320,6 +320,7 @@ golang.org/x/net v0.0.0-20221014081412-f15817d10f9b/go.mod h1:YDH+HFinaLZZlnHAfS golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= @@ -329,6 +330,8 @@ golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.4.0/go.mod h1:RznEsdpjGAINPTOF0UH/t+xJ75L18YO3Ho6Pyn+uRec= golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= +golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -348,11 +351,14 @@ golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=