diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b7f29f1dc5..d31399b768 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -19,16 +19,22 @@ jobs: lint: name: Lint uses: flyteorg/flytetools/.github/workflows/lint.yml@master + with: + go-version: 1.17 tests: name: Unit Tests uses: flyteorg/flytetools/.github/workflows/tests.yml@master secrets: FLYTE_BOT_PAT: ${{ secrets.FLYTE_BOT_PAT }} + with: + go-version: 1.17 generate: name: Check Go Gennerate uses: flyteorg/flytetools/.github/workflows/go_generate.yml@master + with: + go-version: 1.17 dry_run_goreleaser: name: Dry Run Goreleaser @@ -65,6 +71,10 @@ jobs: ~/.cache/go-build ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 - name: Build Flytectl binary run: make compile - name: Create a sandbox cluster diff --git a/boilerplate/flyte/golang_support_tools/go.mod b/boilerplate/flyte/golang_support_tools/go.mod index 307398c89e..441224926c 100644 --- a/boilerplate/flyte/golang_support_tools/go.mod +++ b/boilerplate/flyte/golang_support_tools/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/alvaroloes/enumer v1.1.2 - github.com/flyteorg/flytestdlib v0.4.7 + github.com/flyteorg/flytestdlib v0.4.16 github.com/golangci/golangci-lint v1.38.0 github.com/pseudomuto/protoc-gen-doc v1.4.1 github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5 @@ -14,7 +14,10 @@ require ( 4d63.com/gochecknoglobals v0.0.0-20201008074935-acfc0b28355a // indirect cloud.google.com/go v0.75.0 // indirect cloud.google.com/go/storage v1.12.0 // indirect - github.com/Azure/azure-sdk-for-go v51.0.0+incompatible // indirect + github.com/Azure/azure-sdk-for-go v62.3.0+incompatible // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect + github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest v0.11.17 // indirect github.com/Azure/go-autorest/autorest/adal v0.9.10 // indirect @@ -46,6 +49,7 @@ require ( github.com/esimonov/ifshort v1.0.1 // indirect github.com/fatih/color v1.10.0 // indirect github.com/fatih/structtag v1.2.0 // indirect + github.com/flyteorg/stow v0.3.1 // indirect github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/fzipp/gocyclo v0.3.1 // indirect @@ -62,6 +66,7 @@ require ( github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gofrs/flock v0.8.0 // indirect + github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.4.3 // indirect @@ -82,7 +87,6 @@ require ( github.com/gostaticanalysis/comment v1.4.1 // indirect github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5 // indirect github.com/gostaticanalysis/nilerr v0.1.1 // indirect - github.com/graymeta/stow v0.2.7 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/huandu/xstrings v1.0.0 // indirect github.com/imdario/mergo v0.3.5 // indirect @@ -135,7 +139,6 @@ require ( github.com/ryancurrah/gomodguard v1.2.0 // indirect github.com/ryanrolds/sqlclosecheck v0.3.0 // indirect github.com/sanposhiho/wastedassign v0.1.3 // indirect - github.com/satori/go.uuid v1.2.0 // indirect github.com/securego/gosec/v2 v2.6.1 // indirect github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect github.com/sirupsen/logrus v1.8.0 // indirect @@ -160,15 +163,15 @@ require ( github.com/ultraware/whitespace v0.0.4 // indirect github.com/uudashr/gocognit v1.0.1 // indirect go.opencensus.io v0.22.6 // indirect - golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect - golang.org/x/mod v0.4.1 // indirect - golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect + golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect + golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect golang.org/x/oauth2 v0.0.0-20210126194326-f9ce19ea3013 // indirect - golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect - golang.org/x/text v0.3.5 // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect + golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect - golang.org/x/tools v0.1.0 // indirect + golang.org/x/tools v0.1.10 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/api v0.38.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/boilerplate/flyte/golang_support_tools/go.sum b/boilerplate/flyte/golang_support_tools/go.sum index a62010d29f..755f8cf6ef 100644 --- a/boilerplate/flyte/golang_support_tools/go.sum +++ b/boilerplate/flyte/golang_support_tools/go.sum @@ -41,9 +41,14 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 cloud.google.com/go/storage v1.12.0 h1:4y3gHptW1EHVtcPAVE0eBBlFuGqEejTTG3KdIE0lUX4= cloud.google.com/go/storage v1.12.0/go.mod h1:fFLk2dp2oAhDz8QFKwqrjdJvxSp/W2g7nillojlL5Ho= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v51.0.0+incompatible h1:p7blnyJSjJqf5jflHbSGhIhEpXIgIFmYZNg5uwqweso= -github.com/Azure/azure-sdk-for-go v51.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go v62.3.0+incompatible h1:Ctfsn9UoA/BB4HMYQlbPPgNXdX0tZ4tmb85+KFb2+RE= +github.com/Azure/azure-sdk-for-go v62.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 h1:qoVeMsc9/fh/yhxVaA0obYjVH/oI/ihrOoMwsLS9KSA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm2CYY3CK4spn5OmUIiQtk= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 h1:Px2UA+2RvSSvv+RvJNuUB6n7rs5Wsel4dXLe90Um2n4= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= @@ -177,8 +182,9 @@ github.com/denis-tingajkin/go-header v0.4.2 h1:jEeSF4sdv8/3cT/WY8AgDHUoItNSoEZ7q github.com/denis-tingajkin/go-header v0.4.2/go.mod h1:eLRHAVXzE5atsKAnNRDB90WHCFFnBUn4RN0nRcs1LJA= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -210,10 +216,12 @@ github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/flyteorg/flytestdlib v0.4.7 h1:SMPPXI3j/MjP7D2fqaR+lPQkTrqYS7xZbwsgJI2F8SU= -github.com/flyteorg/flytestdlib v0.4.7/go.mod h1:fv1ar34LJLMTaf0tbfetisLykUlARi7rP+NQTUn6QQs= +github.com/flyteorg/flytestdlib v0.4.16 h1:r4dCPUOqoE9xCAhOw9KDB7O6cBoCxyEtepIWYcj93H0= +github.com/flyteorg/flytestdlib v0.4.16/go.mod h1:WA5Y4hrcgD0ybGOKJVOQ4sP8q7NLRV+S5SWOlH0axgM= github.com/flyteorg/protoc-gen-doc v1.4.2 h1:Otw0F+RHaPQ8XlpzhLLgjsCMcrAIcMO01Zh+ALe3rrE= github.com/flyteorg/protoc-gen-doc v1.4.2/go.mod h1:exDTOVwqpp30eV/EDPFLZy3Pwr2sn6hBC1WIYH/UbIg= +github.com/flyteorg/stow v0.3.1 h1:cBMbWl03Gsy5KoA5mutUYTuYpqtT7Pb8+ANGCLnmFEs= +github.com/flyteorg/stow v0.3.1/go.mod h1:HBld7ud0i4khMHwJjkO8v+NSP7ddKa/ruhf4I8fliaA= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= @@ -276,6 +284,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gofrs/flock v0.8.0 h1:MSdYClljsF3PbENUUEx85nkWfJSGfzYI9yEBZOJz6CY= github.com/gofrs/flock v0.8.0/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= +github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= +github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -397,8 +407,6 @@ github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5 h github.com/gostaticanalysis/forcetypeassert v0.0.0-20200621232751-01d4955beaa5/go.mod h1:qZEedyP/sY1lTGV1uJ3VhWZ2mqag3IkWsDHVbplHXak= github.com/gostaticanalysis/nilerr v0.1.1 h1:ThE+hJP0fEp4zWLkWHWcRyI2Od0p7DlgYG3Uqrmrcpk= github.com/gostaticanalysis/nilerr v0.1.1/go.mod h1:wZYb6YI5YAxxq0i1+VJbY0s2YONW0HU0GPE3+5PWN4A= -github.com/graymeta/stow v0.2.7 h1:b31cB1Ylw/388sYSZxnmpjT2QxC21AaQ8fRnUtE13b4= -github.com/graymeta/stow v0.2.7/go.mod h1:JAs139Zr29qfsecy7b+h9DRsWXbFbsd7LCrbCDYI84k= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -484,6 +492,8 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -577,7 +587,6 @@ github.com/nbutton23/zxcvbn-go v0.0.0-20201221231540-e56b841a3c88/go.mod h1:KSVJ github.com/ncw/swift v1.0.49/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks= github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nishanths/exhaustive v0.1.0 h1:kVlMw8h2LHPMGUVqUj6230oQjjTMFjwcZrnkhXzFfl8= github.com/nishanths/exhaustive v0.1.0/go.mod h1:S1j9110vxV1ECdCudXRkeMnFQ/DQk9ajLT0Uf2MYZQQ= @@ -698,8 +707,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sanposhiho/wastedassign v0.1.3 h1:qIMpTh4NGZYRbFJ+DSpLoVn8F4SLciX2afRvXPefC7w= github.com/sanposhiho/wastedassign v0.1.3/go.mod h1:LGpq5Hsv74QaqM47WtIsRSF/ik9kqk07kchgv66tLVE= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/securego/gosec/v2 v2.6.1 h1:+KCw+uz16FYfFyJ/A5aU6uP7mnrL+j1TbDnk1yN+8R0= github.com/securego/gosec/v2 v2.6.1/go.mod h1:I76p3NTHBXsGhybUW+cEQ692q2Vp+A0Z6ZLzDIZy+Ao= @@ -799,6 +806,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= @@ -832,8 +840,9 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -867,8 +876,9 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -907,14 +917,18 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 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-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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= @@ -936,6 +950,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -993,8 +1008,10 @@ golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1003,8 +1020,9 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 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.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= -golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 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= @@ -1106,8 +1124,9 @@ golang.org/x/tools v0.0.0-20210104081019-d8d6ddbec6ee/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1225,8 +1244,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/cmd/config/subcommand/matchable_attr_file_config_utils.go b/cmd/config/subcommand/matchable_attr_file_config_utils.go index d7fa956373..b21e7832a9 100644 --- a/cmd/config/subcommand/matchable_attr_file_config_utils.go +++ b/cmd/config/subcommand/matchable_attr_file_config_utils.go @@ -57,4 +57,4 @@ func DumpTaskResourceAttr(matchableAttrConfig interface{}, fileName string) erro fmt.Printf("%v", String(matchableAttrConfig)) } return nil -} \ No newline at end of file +} diff --git a/cmd/config/subcommand/register/files_config.go b/cmd/config/subcommand/register/files_config.go index ae618d3380..ea2333583a 100644 --- a/cmd/config/subcommand/register/files_config.go +++ b/cmd/config/subcommand/register/files_config.go @@ -1,5 +1,7 @@ package register +import "github.com/flyteorg/flytestdlib/config" + //go:generate pflags FilesConfig --default-var DefaultFilesConfig --bind-default-var var ( @@ -7,19 +9,25 @@ var ( Version: "", ContinueOnError: false, } + + cfg = config.MustRegisterSection("files", DefaultFilesConfig) ) // FilesConfig containing flags used for registration type FilesConfig struct { - Version string `json:"version" pflag:",version of the entity to be registered with flyte which are un-versioned after serialization."` - Force bool `json:"force" pflag:",force use of version number on entities registered with flyte."` - ContinueOnError bool `json:"continueOnError" pflag:",continue on error when registering files."` - Archive bool `json:"archive" pflag:",pass in archive file either an http link or local path."` - AssumableIamRole string `json:"assumableIamRole" pflag:", custom assumable iam auth role to register launch plans with."` - K8sServiceAccount string `json:"k8sServiceAccount" pflag:", custom kubernetes service account auth role to register launch plans with."` - K8ServiceAccount string `json:"k8ServiceAccount" pflag:", deprecated. Please use --K8sServiceAccount"` - OutputLocationPrefix string `json:"outputLocationPrefix" pflag:", custom output location prefix for offloaded types (files/schemas)."` - SourceUploadPath string `json:"sourceUploadPath" pflag:", Location for source code in storage."` - DestinationDirectory string `json:"destinationDirectory" pflag:", Location of source code in container."` - DryRun bool `json:"dryRun" pflag:",execute command without making any modifications."` + Version string `json:"version" pflag:",Version of the entity to be registered with flyte which are un-versioned after serialization."` + Force bool `json:"force" pflag:",Force use of version number on entities registered with flyte."` + ContinueOnError bool `json:"continueOnError" pflag:",Continue on error when registering files."` + Archive bool `json:"archive" pflag:",Pass in archive file either an http link or local path."` + AssumableIamRole string `json:"assumableIamRole" pflag:",Custom assumable iam auth role to register launch plans with."` + K8sServiceAccount string `json:"k8sServiceAccount" pflag:",Custom kubernetes service account auth role to register launch plans with."` + K8ServiceAccount string `json:"k8ServiceAccount" pflag:",Deprecated. Please use --K8sServiceAccount"` + OutputLocationPrefix string `json:"outputLocationPrefix" pflag:",Custom output location prefix for offloaded types (files/schemas)."` + DeprecatedSourceUploadPath string `json:"sourceUploadPath" pflag:",Deprecated: Update flyte admin to avoid having to configure storage access from flytectl."` + DestinationDirectory string `json:"destinationDirectory" pflag:",Location of source code in container."` + DryRun bool `json:"dryRun" pflag:",Execute command without making any modifications."` +} + +func GetConfig() *FilesConfig { + return cfg.GetConfig().(*FilesConfig) } diff --git a/cmd/config/subcommand/register/filesconfig_flags.go b/cmd/config/subcommand/register/filesconfig_flags.go index 910245ee9f..9ca76123d8 100755 --- a/cmd/config/subcommand/register/filesconfig_flags.go +++ b/cmd/config/subcommand/register/filesconfig_flags.go @@ -50,16 +50,16 @@ func (FilesConfig) mustMarshalJSON(v json.Marshaler) string { // flags is json-name.json-sub-name... etc. func (cfg FilesConfig) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags := pflag.NewFlagSet("FilesConfig", pflag.ExitOnError) - cmdFlags.StringVar(&DefaultFilesConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultFilesConfig.Version, "version of the entity to be registered with flyte which are un-versioned after serialization.") - cmdFlags.BoolVar(&DefaultFilesConfig.Force, fmt.Sprintf("%v%v", prefix, "force"), DefaultFilesConfig.Force, "force use of version number on entities registered with flyte.") - cmdFlags.BoolVar(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), DefaultFilesConfig.ContinueOnError, "continue on error when registering files.") - cmdFlags.BoolVar(&DefaultFilesConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), DefaultFilesConfig.Archive, "pass in archive file either an http link or local path.") - cmdFlags.StringVar(&DefaultFilesConfig.AssumableIamRole, fmt.Sprintf("%v%v", prefix, "assumableIamRole"), DefaultFilesConfig.AssumableIamRole, " custom assumable iam auth role to register launch plans with.") - cmdFlags.StringVar(&DefaultFilesConfig.K8sServiceAccount, fmt.Sprintf("%v%v", prefix, "k8sServiceAccount"), DefaultFilesConfig.K8sServiceAccount, " custom kubernetes service account auth role to register launch plans with.") - cmdFlags.StringVar(&DefaultFilesConfig.K8ServiceAccount, fmt.Sprintf("%v%v", prefix, "k8ServiceAccount"), DefaultFilesConfig.K8ServiceAccount, " deprecated. Please use --K8sServiceAccount") - cmdFlags.StringVar(&DefaultFilesConfig.OutputLocationPrefix, fmt.Sprintf("%v%v", prefix, "outputLocationPrefix"), DefaultFilesConfig.OutputLocationPrefix, " custom output location prefix for offloaded types (files/schemas).") - cmdFlags.StringVar(&DefaultFilesConfig.SourceUploadPath, fmt.Sprintf("%v%v", prefix, "sourceUploadPath"), DefaultFilesConfig.SourceUploadPath, " Location for source code in storage.") - cmdFlags.StringVar(&DefaultFilesConfig.DestinationDirectory, fmt.Sprintf("%v%v", prefix, "destinationDirectory"), DefaultFilesConfig.DestinationDirectory, " Location of source code in container.") - cmdFlags.BoolVar(&DefaultFilesConfig.DryRun, fmt.Sprintf("%v%v", prefix, "dryRun"), DefaultFilesConfig.DryRun, "execute command without making any modifications.") + cmdFlags.StringVar(&DefaultFilesConfig.Version, fmt.Sprintf("%v%v", prefix, "version"), DefaultFilesConfig.Version, "Version of the entity to be registered with flyte which are un-versioned after serialization.") + cmdFlags.BoolVar(&DefaultFilesConfig.Force, fmt.Sprintf("%v%v", prefix, "force"), DefaultFilesConfig.Force, "Force use of version number on entities registered with flyte.") + cmdFlags.BoolVar(&DefaultFilesConfig.ContinueOnError, fmt.Sprintf("%v%v", prefix, "continueOnError"), DefaultFilesConfig.ContinueOnError, "Continue on error when registering files.") + cmdFlags.BoolVar(&DefaultFilesConfig.Archive, fmt.Sprintf("%v%v", prefix, "archive"), DefaultFilesConfig.Archive, "Pass in archive file either an http link or local path.") + cmdFlags.StringVar(&DefaultFilesConfig.AssumableIamRole, fmt.Sprintf("%v%v", prefix, "assumableIamRole"), DefaultFilesConfig.AssumableIamRole, "Custom assumable iam auth role to register launch plans with.") + cmdFlags.StringVar(&DefaultFilesConfig.K8sServiceAccount, fmt.Sprintf("%v%v", prefix, "k8sServiceAccount"), DefaultFilesConfig.K8sServiceAccount, "Custom kubernetes service account auth role to register launch plans with.") + cmdFlags.StringVar(&DefaultFilesConfig.K8ServiceAccount, fmt.Sprintf("%v%v", prefix, "k8ServiceAccount"), DefaultFilesConfig.K8ServiceAccount, "Deprecated. Please use --K8sServiceAccount") + cmdFlags.StringVar(&DefaultFilesConfig.OutputLocationPrefix, fmt.Sprintf("%v%v", prefix, "outputLocationPrefix"), DefaultFilesConfig.OutputLocationPrefix, "Custom output location prefix for offloaded types (files/schemas).") + cmdFlags.StringVar(&DefaultFilesConfig.DeprecatedSourceUploadPath, fmt.Sprintf("%v%v", prefix, "sourceUploadPath"), DefaultFilesConfig.DeprecatedSourceUploadPath, "Deprecated: Update flyte admin to avoid having to configure storage access from flytectl.") + cmdFlags.StringVar(&DefaultFilesConfig.DestinationDirectory, fmt.Sprintf("%v%v", prefix, "destinationDirectory"), DefaultFilesConfig.DestinationDirectory, "Location of source code in container.") + cmdFlags.BoolVar(&DefaultFilesConfig.DryRun, fmt.Sprintf("%v%v", prefix, "dryRun"), DefaultFilesConfig.DryRun, "Execute command without making any modifications.") return cmdFlags } diff --git a/cmd/config/subcommand/register/filesconfig_flags_test.go b/cmd/config/subcommand/register/filesconfig_flags_test.go index 29c5494a67..911df3dc31 100755 --- a/cmd/config/subcommand/register/filesconfig_flags_test.go +++ b/cmd/config/subcommand/register/filesconfig_flags_test.go @@ -218,7 +218,7 @@ func TestFilesConfig_SetFlags(t *testing.T) { cmdFlags.Set("sourceUploadPath", testValue) if vString, err := cmdFlags.GetString("sourceUploadPath"); err == nil { - testDecodeJson_FilesConfig(t, fmt.Sprintf("%v", vString), &actual.SourceUploadPath) + testDecodeJson_FilesConfig(t, fmt.Sprintf("%v", vString), &actual.DeprecatedSourceUploadPath) } else { assert.FailNow(t, err.Error()) diff --git a/cmd/config/subcommand/sandbox/config_flags.go b/cmd/config/subcommand/sandbox/config_flags.go index 0355ee08f5..426e24204b 100755 --- a/cmd/config/subcommand/sandbox/config_flags.go +++ b/cmd/config/subcommand/sandbox/config_flags.go @@ -56,5 +56,7 @@ func (cfg Config) GetPFlagSet(prefix string) *pflag.FlagSet { cmdFlags.BoolVar(&DefaultConfig.Prerelease, fmt.Sprintf("%v%v", prefix, "pre"), DefaultConfig.Prerelease, "Optional. Pre release Version of flyte will be used for sandbox.") cmdFlags.StringSliceVar(&DefaultConfig.Env, fmt.Sprintf("%v%v", prefix, "env"), DefaultConfig.Env, "Optional. Provide Env variable in key=value format which can be passed to sandbox container.") cmdFlags.Var(&DefaultConfig.ImagePullPolicy, fmt.Sprintf("%v%v", prefix, "imagePullPolicy"), "Optional. Defines the image pull behavior [Always/IfNotPresent/Never]") + cmdFlags.StringVar(&DefaultConfig.ImagePullOptions.RegistryAuth, fmt.Sprintf("%v%v", prefix, "imagePullOptions.registryAuth"), DefaultConfig.ImagePullOptions.RegistryAuth, "The base64 encoded credentials for the registry.") + cmdFlags.StringVar(&DefaultConfig.ImagePullOptions.Platform, fmt.Sprintf("%v%v", prefix, "imagePullOptions.platform"), DefaultConfig.ImagePullOptions.Platform, "Forces a specific platform's image to be pulled.'") return cmdFlags } diff --git a/cmd/config/subcommand/sandbox/config_flags_test.go b/cmd/config/subcommand/sandbox/config_flags_test.go index 6433a3e647..3fdc64ba40 100755 --- a/cmd/config/subcommand/sandbox/config_flags_test.go +++ b/cmd/config/subcommand/sandbox/config_flags_test.go @@ -181,4 +181,32 @@ func TestConfig_SetFlags(t *testing.T) { } }) }) + t.Run("Test_imagePullOptions.registryAuth", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("imagePullOptions.registryAuth", testValue) + if vString, err := cmdFlags.GetString("imagePullOptions.registryAuth"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.ImagePullOptions.RegistryAuth) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) + t.Run("Test_imagePullOptions.platform", func(t *testing.T) { + + t.Run("Override", func(t *testing.T) { + testValue := "1" + + cmdFlags.Set("imagePullOptions.platform", testValue) + if vString, err := cmdFlags.GetString("imagePullOptions.platform"); err == nil { + testDecodeJson_Config(t, fmt.Sprintf("%v", vString), &actual.ImagePullOptions.Platform) + + } else { + assert.FailNow(t, err.Error()) + } + }) + }) } diff --git a/cmd/config/subcommand/sandbox/sandbox_config.go b/cmd/config/subcommand/sandbox/sandbox_config.go index a2fd3d1521..7381a398b7 100644 --- a/cmd/config/subcommand/sandbox/sandbox_config.go +++ b/cmd/config/subcommand/sandbox/sandbox_config.go @@ -53,4 +53,11 @@ type Config struct { // Optionally it is possible to use local sandbox image // Flytectl will not pull the image from the registry if the local flag passes. It is usually useful while testing your local images without pushing them to a registry. ImagePullPolicy ImagePullPolicy `json:"imagePullPolicy" pflag:",Optional. Defines the image pull behavior [Always/IfNotPresent/Never]"` + + ImagePullOptions ImagePullOptions `json:"imagePullOptions" pflag:",Optional. Defines image pull options (e.g. auth)"` +} + +type ImagePullOptions struct { + RegistryAuth string `json:"registryAuth" pflag:",The base64 encoded credentials for the registry."` + Platform string `json:"platform" pflag:",Forces a specific platform's image to be pulled.'"` } diff --git a/cmd/configuration/configuration_test.go b/cmd/configuration/configuration_test.go index bb2d256229..da5b0a6f97 100644 --- a/cmd/configuration/configuration_test.go +++ b/cmd/configuration/configuration_test.go @@ -9,6 +9,8 @@ import ( "strings" "testing" + admin2 "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/flyteorg/flytectl/pkg/configutil" initConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/config" @@ -51,7 +53,8 @@ func TestSetupConfigFunc(t *testing.T) { _ = util.SetupFlyteDir() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + mockClient := admin2.InitializeMockClientset() + cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) err := configInitFunc(ctx, []string{}, cmdCtx) initConfig.DefaultConfig.Host = "" assert.Nil(t, err) diff --git a/cmd/core/cmd.go b/cmd/core/cmd.go index c1121355fb..20188130a6 100644 --- a/cmd/core/cmd.go +++ b/cmd/core/cmd.go @@ -35,9 +35,11 @@ func AddCommands(rootCmd *cobra.Command, cmdFuncs map[string]CommandEntry) { RunE: generateCommandFunc(cmdEntry), SilenceUsage: true, } + if cmdEntry.PFlagProvider != nil { cmd.Flags().AddFlagSet(cmdEntry.PFlagProvider.GetPFlagSet("")) } + rootCmd.AddCommand(cmd) } } @@ -67,6 +69,6 @@ func generateCommandFunc(cmdEntry CommandEntry) func(cmd *cobra.Command, args [] if err != nil { return err } - return cmdEntry.CmdFunc(ctx, args, NewCommandContext(clientSet.AdminClient(), cmd.OutOrStdout())) + return cmdEntry.CmdFunc(ctx, args, NewCommandContext(clientSet, cmd.OutOrStdout())) } } diff --git a/cmd/core/cmd_ctx.go b/cmd/core/cmd_ctx.go index ab1c6c6afd..7d02474490 100644 --- a/cmd/core/cmd_ctx.go +++ b/cmd/core/cmd_ctx.go @@ -3,12 +3,14 @@ package cmdcore import ( "io" + "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/flyteorg/flytectl/pkg/ext" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service" ) type CommandContext struct { - adminClient service.AdminServiceClient + clientSet *admin.Clientset adminClientFetcherExt ext.AdminFetcherExtInterface adminClientUpdateExt ext.AdminUpdaterExtInterface adminClientDeleteExt ext.AdminDeleterExtInterface @@ -16,28 +18,38 @@ type CommandContext struct { out io.Writer } -func NewCommandContext(adminClient service.AdminServiceClient, out io.Writer) CommandContext { - return CommandContext{adminClient: adminClient, out: out, - adminClientFetcherExt: &ext.AdminFetcherExtClient{AdminClient: adminClient}, - adminClientUpdateExt: &ext.AdminUpdaterExtClient{AdminClient: adminClient}, - adminClientDeleteExt: &ext.AdminDeleterExtClient{AdminClient: adminClient}} +func NewCommandContext(clientSet *admin.Clientset, out io.Writer) CommandContext { + return CommandContext{ + clientSet: clientSet, + out: out, + adminClientFetcherExt: &ext.AdminFetcherExtClient{AdminClient: clientSet.AdminClient()}, + adminClientUpdateExt: &ext.AdminUpdaterExtClient{AdminClient: clientSet.AdminClient()}, + adminClientDeleteExt: &ext.AdminDeleterExtClient{AdminClient: clientSet.AdminClient()}, + } } // NewCommandContextWithExt construct command context with injected extensions. Helps in injecting mocked ones for testing. func NewCommandContextWithExt( - adminClient service.AdminServiceClient, + clientSet *admin.Clientset, fetcher ext.AdminFetcherExtInterface, updater ext.AdminUpdaterExtInterface, deleter ext.AdminDeleterExtInterface, out io.Writer) CommandContext { - return CommandContext{adminClient: adminClient, out: out, + return CommandContext{ + clientSet: clientSet, + out: out, adminClientFetcherExt: fetcher, adminClientUpdateExt: updater, - adminClientDeleteExt: deleter} + adminClientDeleteExt: deleter, + } } func (c CommandContext) AdminClient() service.AdminServiceClient { - return c.adminClient + return c.clientSet.AdminClient() +} + +func (c CommandContext) ClientSet() *admin.Clientset { + return c.clientSet } func (c CommandContext) OutputPipe() io.Writer { diff --git a/cmd/create/create_test.go b/cmd/create/create_test.go index 40b8d5d861..dafd803a03 100644 --- a/cmd/create/create_test.go +++ b/cmd/create/create_test.go @@ -1,26 +1,15 @@ package create import ( - "context" "sort" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) const testDataFolder = "../testdata/" -var ( - err error - ctx context.Context - mockClient *mocks.AdminServiceClient - args []string - cmdCtx cmdCore.CommandContext -) var setup = testutils.Setup var tearDownAndVerify = testutils.TearDownAndVerify diff --git a/cmd/create/execution_test.go b/cmd/create/execution_test.go index d671e0f5b0..1a3a7217e5 100644 --- a/cmd/create/execution_test.go +++ b/cmd/create/execution_test.go @@ -15,13 +15,17 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) +type TestStruct struct { + executionConfig *ExecutionConfig + args []string +} + // This function needs to be called after testutils.Steup() -func createExecutionSetup() { - ctx = testutils.Ctx - mockClient = testutils.MockClient - executionConfig = &ExecutionConfig{} +func createExecutionSetup(s *testutils.TestStruct) (t TestStruct) { + ctx := s.Ctx + t.executionConfig = &ExecutionConfig{} // TODO: migrate to new command context from testutils - cmdCtx = cmdCore.NewCommandContext(mockClient, testutils.MockOutStream) + s.CmdCtx = cmdCore.NewCommandContext(s.MockClient, s.MockOutStream) sortedListLiteralType := core.Variable{ Type: &core.LiteralType{ Type: &core.LiteralType_CollectionType{ @@ -56,7 +60,7 @@ func createExecutionSetup() { }, }, } - mockClient.OnGetTaskMatch(ctx, mock.Anything).Return(task1, nil) + s.MockAdminClient.OnGetTaskMatch(ctx, mock.Anything).Return(task1, nil) parameterMap := map[string]*core.Parameter{ "numbers": { Var: &core.Variable{ @@ -128,15 +132,20 @@ func createExecutionSetup() { Project: config.GetConfig().Project, Domain: config.GetConfig().Domain, Name: "core.advanced.run_merge_sort.merge_sort", - Version: "v3", + Version: "v2", }, } - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan1, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan1, nil) + + return TestStruct{ + executionConfig: executionConfig, + args: []string{}, + } } func TestCreateTaskExecutionFunc(t *testing.T) { - setup() - createExecutionSetup() + s := setup() + ts := createExecutionSetup(&s) executionCreateResponseTask := &admin.ExecutionCreateResponse{ Id: &core.WorkflowExecutionIdentifier{ Project: "flytesnacks", @@ -144,28 +153,31 @@ func TestCreateTaskExecutionFunc(t *testing.T) { Name: "ff513c0e44b5b4a35aa5", }, } - mockClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseTask, nil) - executionConfig.ExecFile = testDataFolder + "task_execution_spec_with_iamrole.yaml" - err = createExecutionCommand(ctx, args, cmdCtx) + + ctx := s.Ctx + s.MockAdminClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseTask, nil) + ts.executionConfig.ExecFile = testDataFolder + "task_execution_spec_with_iamrole.yaml" + err := createExecutionCommand(ctx, ts.args, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) - tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"ff513c0e44b5b4a35aa5" `) + s.MockAdminClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) + tearDownAndVerify(t, s.Writer, `execution identifier project:"flytesnacks" domain:"development" name:"ff513c0e44b5b4a35aa5" `) } func TestCreateTaskExecutionFuncError(t *testing.T) { - setup() - createExecutionSetup() - mockClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(nil, fmt.Errorf("error launching task")) - executionConfig.ExecFile = testDataFolder + "task_execution_spec.yaml" - err = createExecutionCommand(ctx, args, cmdCtx) + s := setup() + ts := createExecutionSetup(&s) + ctx := s.Ctx + s.MockAdminClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(nil, fmt.Errorf("error launching task")) + ts.executionConfig.ExecFile = testDataFolder + "task_execution_spec.yaml" + err := createExecutionCommand(ctx, ts.args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error launching task"), err) - mockClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) + s.MockAdminClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) } func TestCreateLaunchPlanExecutionFunc(t *testing.T) { - setup() - createExecutionSetup() + s := setup() + ts := createExecutionSetup(&s) executionCreateResponseLP := &admin.ExecutionCreateResponse{ Id: &core.WorkflowExecutionIdentifier{ Project: "flytesnacks", @@ -173,18 +185,20 @@ func TestCreateLaunchPlanExecutionFunc(t *testing.T) { Name: "f652ea3596e7f4d80a0e", }, } - mockClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseLP, nil) - executionConfig.ExecFile = testDataFolder + "launchplan_execution_spec.yaml" - err = createExecutionCommand(ctx, args, cmdCtx) + + ctx := s.Ctx + s.MockAdminClient.OnCreateExecutionMatch(ctx, mock.Anything).Return(executionCreateResponseLP, nil) + ts.executionConfig.ExecFile = testDataFolder + "launchplan_execution_spec.yaml" + err := createExecutionCommand(ctx, ts.args, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) - tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e" `) + s.MockAdminClient.AssertCalled(t, "CreateExecution", ctx, mock.Anything) + tearDownAndVerify(t, s.Writer, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e" `) } func TestCreateRelaunchExecutionFunc(t *testing.T) { - setup() - createExecutionSetup() - defer func() { executionConfig.Relaunch = "" }() + s := setup() + ts := createExecutionSetup(&s) + defer func() { ts.executionConfig.Relaunch = "" }() relaunchExecResponse := &admin.ExecutionCreateResponse{ Id: &core.WorkflowExecutionIdentifier{ Project: "flytesnacks", @@ -193,7 +207,7 @@ func TestCreateRelaunchExecutionFunc(t *testing.T) { }, } - executionConfig.Relaunch = relaunchExecResponse.Id.Name + ts.executionConfig.Relaunch = relaunchExecResponse.Id.Name relaunchRequest := &admin.ExecutionRelaunchRequest{ Id: &core.WorkflowExecutionIdentifier{ Name: executionConfig.Relaunch, @@ -201,17 +215,18 @@ func TestCreateRelaunchExecutionFunc(t *testing.T) { Domain: config.GetConfig().Domain, }, } - mockClient.OnRelaunchExecutionMatch(ctx, relaunchRequest).Return(relaunchExecResponse, nil) - err = createExecutionCommand(ctx, args, cmdCtx) + ctx := s.Ctx + s.MockAdminClient.OnRelaunchExecutionMatch(ctx, relaunchRequest).Return(relaunchExecResponse, nil) + err := createExecutionCommand(ctx, ts.args, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "RelaunchExecution", ctx, relaunchRequest) - tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e"`) + s.MockAdminClient.AssertCalled(t, "RelaunchExecution", ctx, relaunchRequest) + tearDownAndVerify(t, s.Writer, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e"`) } func TestCreateRecoverExecutionFunc(t *testing.T) { - setup() - createExecutionSetup() - defer func() { executionConfig.Recover = "" }() + s := setup() + ts := createExecutionSetup(&s) + defer func() { ts.executionConfig.Recover = "" }() originalExecutionName := "abc123" recoverExecResponse := &admin.ExecutionCreateResponse{ @@ -222,7 +237,7 @@ func TestCreateRecoverExecutionFunc(t *testing.T) { }, } - executionConfig.Recover = originalExecutionName + ts.executionConfig.Recover = originalExecutionName recoverRequest := &admin.ExecutionRecoverRequest{ Id: &core.WorkflowExecutionIdentifier{ Name: originalExecutionName, @@ -230,28 +245,31 @@ func TestCreateRecoverExecutionFunc(t *testing.T) { Domain: config.GetConfig().Domain, }, } - mockClient.OnRecoverExecutionMatch(ctx, recoverRequest).Return(recoverExecResponse, nil) - err = createExecutionCommand(ctx, args, cmdCtx) + + ctx := s.Ctx + s.MockAdminClient.OnRecoverExecutionMatch(ctx, recoverRequest).Return(recoverExecResponse, nil) + err := createExecutionCommand(ctx, ts.args, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "RecoverExecution", ctx, recoverRequest) - tearDownAndVerify(t, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e"`) - executionConfig.Relaunch = "" + s.MockAdminClient.AssertCalled(t, "RecoverExecution", ctx, recoverRequest) + tearDownAndVerify(t, s.Writer, `execution identifier project:"flytesnacks" domain:"development" name:"f652ea3596e7f4d80a0e"`) + ts.executionConfig.Relaunch = "" } func TestCreateExecutionFuncInvalid(t *testing.T) { - setup() - createExecutionSetup() + s := setup() + ts := createExecutionSetup(&s) + executionConfig := ts.executionConfig executionConfig.Relaunch = "" executionConfig.ExecFile = "" - err = createExecutionCommand(ctx, args, cmdCtx) + err := createExecutionCommand(s.Ctx, ts.args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("executionConfig, relaunch and recover can't be empty. Run the flytectl get task/launchplan to generate the config"), err) executionConfig.ExecFile = "Invalid-file" - err = createExecutionCommand(ctx, args, cmdCtx) + err = createExecutionCommand(s.Ctx, ts.args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from %v yaml file", executionConfig.ExecFile), err) executionConfig.ExecFile = testDataFolder + "invalid_execution_spec.yaml" - err = createExecutionCommand(ctx, args, cmdCtx) + err = createExecutionCommand(s.Ctx, ts.args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("either task or workflow name should be specified to launch an execution"), err) } diff --git a/cmd/create/execution_util_test.go b/cmd/create/execution_util_test.go index 9d6bf63d41..643248daaa 100644 --- a/cmd/create/execution_util_test.go +++ b/cmd/create/execution_util_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config" - "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -20,9 +19,6 @@ var ( // This function needs to be called after testutils.Steup() func createExecutionUtilSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient executionCreateResponse = &admin.ExecutionCreateResponse{ Id: &core.WorkflowExecutionIdentifier{ Project: "flytesnacks", @@ -47,35 +43,35 @@ func createExecutionUtilSetup() { } func TestCreateExecutionForRelaunch(t *testing.T) { - setup() + s := setup() createExecutionUtilSetup() - mockClient.OnRelaunchExecutionMatch(ctx, relaunchRequest).Return(executionCreateResponse, nil) - err = relaunchExecution(ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, cmdCtx) + s.MockAdminClient.OnRelaunchExecutionMatch(s.Ctx, relaunchRequest).Return(executionCreateResponse, nil) + err := relaunchExecution(s.Ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, s.CmdCtx) assert.Nil(t, err) } func TestCreateExecutionForRelaunchNotFound(t *testing.T) { - setup() + s := setup() createExecutionUtilSetup() - mockClient.OnRelaunchExecutionMatch(ctx, relaunchRequest).Return(nil, errors.New("unknown execution")) - err = relaunchExecution(ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, cmdCtx) + s.MockAdminClient.OnRelaunchExecutionMatch(s.Ctx, relaunchRequest).Return(nil, errors.New("unknown execution")) + err := relaunchExecution(s.Ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, err, errors.New("unknown execution")) } func TestCreateExecutionForRecovery(t *testing.T) { - setup() + s := setup() createExecutionUtilSetup() - mockClient.OnRecoverExecutionMatch(ctx, recoverRequest).Return(executionCreateResponse, nil) - err = recoverExecution(ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, cmdCtx) + s.MockAdminClient.OnRecoverExecutionMatch(s.Ctx, recoverRequest).Return(executionCreateResponse, nil) + err := recoverExecution(s.Ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, s.CmdCtx) assert.Nil(t, err) } func TestCreateExecutionForRecoveryNotFound(t *testing.T) { - setup() + s := setup() createExecutionUtilSetup() - mockClient.OnRecoverExecutionMatch(ctx, recoverRequest).Return(nil, errors.New("unknown execution")) - err = recoverExecution(ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, cmdCtx) + s.MockAdminClient.OnRecoverExecutionMatch(s.Ctx, recoverRequest).Return(nil, errors.New("unknown execution")) + err := recoverExecution(s.Ctx, "execName", config.GetConfig().Project, config.GetConfig().Domain, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, err, errors.New("unknown execution")) } diff --git a/cmd/create/project_test.go b/cmd/create/project_test.go index 538fd70f62..2de7ee24e1 100644 --- a/cmd/create/project_test.go +++ b/cmd/create/project_test.go @@ -9,7 +9,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config/subcommand/project" - "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -23,9 +22,6 @@ var ( ) func createProjectSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient projectRegisterRequest = &admin.ProjectRegisterRequest{ Project: &admin.Project{ Id: projectValue, @@ -42,39 +38,39 @@ func createProjectSetup() { project.DefaultProjectConfig.Description = "" } func TestCreateProjectFunc(t *testing.T) { - setup() + s := setup() createProjectSetup() - defer tearDownAndVerify(t, "project created successfully.") + defer tearDownAndVerify(t, s.Writer, "project created successfully.") project.DefaultProjectConfig.ID = projectValue project.DefaultProjectConfig.Name = projectValue project.DefaultProjectConfig.Labels = map[string]string{} project.DefaultProjectConfig.Description = "" - mockClient.OnRegisterProjectMatch(ctx, projectRegisterRequest).Return(nil, nil) - err := createProjectsCommand(ctx, args, cmdCtx) + s.MockAdminClient.OnRegisterProjectMatch(s.Ctx, projectRegisterRequest).Return(nil, nil) + err := createProjectsCommand(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "RegisterProject", ctx, projectRegisterRequest) + s.MockAdminClient.AssertCalled(t, "RegisterProject", s.Ctx, projectRegisterRequest) } func TestEmptyProjectID(t *testing.T) { - setup() + s := setup() createProjectSetup() - defer tearDownAndVerify(t, "") + defer tearDownAndVerify(t, s.Writer, "") project.DefaultProjectConfig = &project.ConfigProject{} - mockClient.OnRegisterProjectMatch(ctx, projectRegisterRequest).Return(nil, nil) - err := createProjectsCommand(ctx, args, cmdCtx) + s.MockAdminClient.OnRegisterProjectMatch(s.Ctx, projectRegisterRequest).Return(nil, nil) + err := createProjectsCommand(s.Ctx, []string{}, s.CmdCtx) assert.Equal(t, errors.New(clierrors.ErrProjectNotPassed), err) - mockClient.AssertNotCalled(t, "RegisterProject", ctx, mock.Anything) + s.MockAdminClient.AssertNotCalled(t, "RegisterProject", s.Ctx, mock.Anything) } func TestEmptyProjectName(t *testing.T) { - setup() + s := setup() createProjectSetup() - defer tearDownAndVerify(t, "") + defer tearDownAndVerify(t, s.Writer, "") project.DefaultProjectConfig.ID = projectValue project.DefaultProjectConfig.Labels = map[string]string{} project.DefaultProjectConfig.Description = "" - mockClient.OnRegisterProjectMatch(ctx, projectRegisterRequest).Return(nil, nil) - err := createProjectsCommand(ctx, args, cmdCtx) + s.MockAdminClient.OnRegisterProjectMatch(s.Ctx, projectRegisterRequest).Return(nil, nil) + err := createProjectsCommand(s.Ctx, []string{}, s.CmdCtx) assert.Equal(t, fmt.Errorf("project name is a required flag"), err) - mockClient.AssertNotCalled(t, "RegisterProject", ctx, mock.Anything) + s.MockAdminClient.AssertNotCalled(t, "RegisterProject", s.Ctx, mock.Anything) } diff --git a/cmd/delete/delete_test.go b/cmd/delete/delete_test.go index 70af741071..88119c37cd 100644 --- a/cmd/delete/delete_test.go +++ b/cmd/delete/delete_test.go @@ -1,24 +1,13 @@ package delete import ( - "context" "sort" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) -var ( - err error - ctx context.Context - mockClient *mocks.AdminServiceClient - cmdCtx cmdCore.CommandContext -) - const ( testDataNonExistentFile = "testdata/non-existent-file" testDataInvalidAttrFile = "testdata/invalid_attribute.yaml" diff --git a/cmd/delete/execution_test.go b/cmd/delete/execution_test.go index c9a5b11c62..1d74a9d524 100644 --- a/cmd/delete/execution_test.go +++ b/cmd/delete/execution_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config" - "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -18,9 +17,6 @@ var ( ) func terminateExecutionSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient args = append(args, "exec1", "exec2") terminateExecRequests = []*admin.ExecutionTerminateRequest{ {Id: &core.WorkflowExecutionIdentifier{ @@ -37,40 +33,40 @@ func terminateExecutionSetup() { } func TestTerminateExecutionFunc(t *testing.T) { - setup() + s := setup() terminateExecutionSetup() terminateExecResponse := &admin.ExecutionTerminateResponse{} - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil) - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[1]).Return(terminateExecResponse, nil) - err = terminateExecutionFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[1]).Return(terminateExecResponse, nil) + err := terminateExecutionFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "TerminateExecution", ctx, terminateExecRequests[0]) - mockClient.AssertCalled(t, "TerminateExecution", ctx, terminateExecRequests[1]) - tearDownAndVerify(t, "") + s.MockAdminClient.AssertCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[0]) + s.MockAdminClient.AssertCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[1]) + tearDownAndVerify(t, s.Writer, "") } func TestTerminateExecutionFuncWithError(t *testing.T) { - setup() + s := setup() terminateExecutionSetup() terminateExecResponse := &admin.ExecutionTerminateResponse{} - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[0]).Return(nil, errors.New("failed to terminate")) - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[1]).Return(terminateExecResponse, nil) - err = terminateExecutionFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(nil, errors.New("failed to terminate")) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[1]).Return(terminateExecResponse, nil) + err := terminateExecutionFunc(s.Ctx, args, s.CmdCtx) assert.Equal(t, errors.New("failed to terminate"), err) - mockClient.AssertCalled(t, "TerminateExecution", ctx, terminateExecRequests[0]) - mockClient.AssertNotCalled(t, "TerminateExecution", ctx, terminateExecRequests[1]) - tearDownAndVerify(t, "") + s.MockAdminClient.AssertCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[0]) + s.MockAdminClient.AssertNotCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[1]) + tearDownAndVerify(t, s.Writer, "") } func TestTerminateExecutionFuncWithPartialSuccess(t *testing.T) { - setup() + s := setup() terminateExecutionSetup() terminateExecResponse := &admin.ExecutionTerminateResponse{} - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil) - mockClient.OnTerminateExecutionMatch(ctx, terminateExecRequests[1]).Return(nil, errors.New("failed to terminate")) - err = terminateExecutionFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[0]).Return(terminateExecResponse, nil) + s.MockAdminClient.OnTerminateExecutionMatch(s.Ctx, terminateExecRequests[1]).Return(nil, errors.New("failed to terminate")) + err := terminateExecutionFunc(s.Ctx, args, s.CmdCtx) assert.Equal(t, errors.New("failed to terminate"), err) - mockClient.AssertCalled(t, "TerminateExecution", ctx, terminateExecRequests[0]) - mockClient.AssertCalled(t, "TerminateExecution", ctx, terminateExecRequests[1]) - tearDownAndVerify(t, "") + s.MockAdminClient.AssertCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[0]) + s.MockAdminClient.AssertCalled(t, "TerminateExecution", s.Ctx, terminateExecRequests[1]) + tearDownAndVerify(t, s.Writer, "") } diff --git a/cmd/delete/matchable_cluster_resource_attribute_test.go b/cmd/delete/matchable_cluster_resource_attribute_test.go index f9290ad6b7..d4556224ff 100644 --- a/cmd/delete/matchable_cluster_resource_attribute_test.go +++ b/cmd/delete/matchable_cluster_resource_attribute_test.go @@ -6,7 +6,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/clusterresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -14,121 +13,118 @@ import ( ) func deleteClusterResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient clusterresourceattribute.DefaultDelConfig = &clusterresourceattribute.AttrDeleteConfig{} args = []string{} } func TestDeleteClusterResourceAttributes(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delte project domain attributes")) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delte project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_CLUSTER_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = "testdata/valid_workflow_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_CLUSTER_RESOURCE) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deleteClusterResourceAttributeSetup() // Empty attribute file clusterresourceattribute.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deleteClusterResourceAttributes(ctx, args, cmdCtx) + err := deleteClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_CLUSTER_RESOURCE) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_CLUSTER_RESOURCE) }) } diff --git a/cmd/delete/matchable_execution_cluster_label_test.go b/cmd/delete/matchable_execution_cluster_label_test.go index 834e5afb66..c36248c267 100644 --- a/cmd/delete/matchable_execution_cluster_label_test.go +++ b/cmd/delete/matchable_execution_cluster_label_test.go @@ -6,7 +6,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionclusterlabel" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -14,121 +13,118 @@ import ( ) func deleteExecutionClusterLabelSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionclusterlabel.DefaultDelConfig = &executionclusterlabel.AttrDeleteConfig{} args = []string{} } func TestDeleteExecutionClusterLabels(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete project domain attributes")) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = "testdata/valid_workflow_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deleteExecutionClusterLabelSetup() // Empty attribute file executionclusterlabel.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deleteExecutionClusterLabel(ctx, args, cmdCtx) + err := deleteExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) }) } diff --git a/cmd/delete/matchable_execution_queue_attribute_test.go b/cmd/delete/matchable_execution_queue_attribute_test.go index ef5b2975c0..5c4843ede3 100644 --- a/cmd/delete/matchable_execution_queue_attribute_test.go +++ b/cmd/delete/matchable_execution_queue_attribute_test.go @@ -6,7 +6,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionqueueattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -14,121 +13,118 @@ import ( ) func deleteExecutionQueueAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionqueueattribute.DefaultDelConfig = &executionqueueattribute.AttrDeleteConfig{} args = []string{} } func TestDeleteExecutionQueueAttributes(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deleteExecutionQueueAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delte project domain attributes")) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delte project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_QUEUE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = "testdata/valid_workflow_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_EXECUTION_QUEUE) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file executionqueueattribute.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deleteExecutionQueueAttributes(ctx, args, cmdCtx) + err := deleteExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_QUEUE) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_EXECUTION_QUEUE) }) } diff --git a/cmd/delete/matchable_plugin_override_test.go b/cmd/delete/matchable_plugin_override_test.go index d8ed34818f..af64254d3c 100644 --- a/cmd/delete/matchable_plugin_override_test.go +++ b/cmd/delete/matchable_plugin_override_test.go @@ -6,7 +6,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config" pluginoverride "github.com/flyteorg/flytectl/cmd/config/subcommand/plugin_override" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -14,121 +13,118 @@ import ( ) func deletePluginOverrideSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient pluginoverride.DefaultDelConfig = &pluginoverride.AttrDeleteConfig{} args = []string{} } func TestPluginOverride(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delte project domain attributes")) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delte project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_plugin_override.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_PLUGIN_OVERRIDE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = "testdata/valid_workflow_plugin_override.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_PLUGIN_OVERRIDE) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deletePluginOverrideSetup() // Empty attribute file pluginoverride.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deletePluginOverride(ctx, args, cmdCtx) + err := deletePluginOverride(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_PLUGIN_OVERRIDE) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_PLUGIN_OVERRIDE) }) } diff --git a/cmd/delete/matchable_task_resource_attribute_test.go b/cmd/delete/matchable_task_resource_attribute_test.go index 204d46f8c7..62dd7930ce 100644 --- a/cmd/delete/matchable_task_resource_attribute_test.go +++ b/cmd/delete/matchable_task_resource_attribute_test.go @@ -6,7 +6,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/taskresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -14,121 +13,118 @@ import ( ) func deleteTaskResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient taskresourceattribute.DefaultDelConfig = &taskresourceattribute.AttrDeleteConfig{} args = []string{} } func TestDeleteTaskResourceAttributes(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delte project domain attributes")) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delte project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_task_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_TASK_RESOURCE) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_TASK_RESOURCE) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_TASK_RESOURCE) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_TASK_RESOURCE) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = "testdata/valid_workflow_task_attribute.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_TASK_RESOURCE) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_TASK_RESOURCE) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deleteTaskResourceAttributeSetup() // Empty attribute file taskresourceattribute.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deleteTaskResourceAttributes(ctx, args, cmdCtx) + err := deleteTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_TASK_RESOURCE) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_TASK_RESOURCE) }) } diff --git a/cmd/delete/matchable_workflow_execution_config_test.go b/cmd/delete/matchable_workflow_execution_config_test.go index acebc7d06b..592a53edba 100644 --- a/cmd/delete/matchable_workflow_execution_config_test.go +++ b/cmd/delete/matchable_workflow_execution_config_test.go @@ -7,7 +7,6 @@ import ( "github.com/flyteorg/flytectl/cmd/config/subcommand/workflowexecutionconfig" "github.com/flyteorg/flytectl/cmd/config" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,121 +14,118 @@ import ( ) func deleteWorkflowExecutionConfigSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient workflowexecutionconfig.DefaultDelConfig = &workflowexecutionconfig.AttrDeleteConfig{} args = []string{} } func TestDeleteWorkflowExecutionConfig(t *testing.T) { t.Run("successful project domain attribute deletion commandline", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = "" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("failed project domain attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete project domain attributes")) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete project domain attributes"), err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("successful project domain attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = "testdata/valid_project_domain_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + s.DeleterExt.AssertCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("successful workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("failed workflow attribute deletion", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = "" args := []string{"workflow1"} - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to delete workflow attribute")) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to delete workflow attribute"), err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow1", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("successful workflow attribute deletion file", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = "testdata/valid_workflow_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("workflow attribute deletion non existent file", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = testDataNonExistentFile // No args implying project domain attribute deletion - u.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.DeleterExt.OnDeleteWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - u.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", - ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", + s.DeleterExt.AssertNotCalled(t, "DeleteWorkflowAttributes", + s.Ctx, "flytectldemo", "development", "core.control_flow.run_merge_sort.merge_sort", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) t.Run("attribute deletion invalid file", func(t *testing.T) { - setup() + s := setup() deleteWorkflowExecutionConfigSetup() // Empty attribute file workflowexecutionconfig.DefaultDelConfig.AttrFile = testDataInvalidAttrFile // No args implying project domain attribute deletion - err = deleteWorkflowExecutionConfig(ctx, args, cmdCtx) + err := deleteWorkflowExecutionConfig(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - u.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", - ctx, "flytectldemo", "development", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + s.DeleterExt.AssertNotCalled(t, "DeleteProjectDomainAttributes", + s.Ctx, "flytectldemo", "development", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) }) } diff --git a/cmd/get/execution_test.go b/cmd/get/execution_test.go index bcedf1f6d3..ff11d03db0 100644 --- a/cmd/get/execution_test.go +++ b/cmd/get/execution_test.go @@ -4,14 +4,12 @@ import ( "context" "errors" "fmt" - "io" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/execution" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -32,12 +30,9 @@ func getExecutionSetup() { } func TestListExecutionFunc(t *testing.T) { - ctx := context.Background() getExecutionSetup() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := setup() + ctx := s.Ctx execListRequest := &admin.ResourceListRequest{ Limit: 100, SortBy: &admin.Sort{ @@ -77,21 +72,15 @@ func TestListExecutionFunc(t *testing.T) { executionList := &admin.ExecutionList{ Executions: executions, } - mockClient.OnListExecutionsMatch(mock.Anything, mock.MatchedBy(func(o *admin.ResourceListRequest) bool { - return execListRequest.SortBy.Key == o.SortBy.Key && execListRequest.SortBy.Direction == o.SortBy.Direction && execListRequest.Filters == o.Filters && execListRequest.Limit == o.Limit - })).Return(executionList, nil) - err := getExecutionFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnListExecutionsMatch(mock.Anything, execListRequest).Return(executionList, nil) + err := getExecutionFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListExecutions", ctx, execListRequest) + s.MockAdminClient.AssertCalled(t, "ListExecutions", ctx, execListRequest) } func TestListExecutionFuncWithError(t *testing.T) { ctx := context.Background() getExecutionSetup() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) execListRequest := &admin.ResourceListRequest{ Limit: 100, SortBy: &admin.Sort{ @@ -102,6 +91,7 @@ func TestListExecutionFuncWithError(t *testing.T) { Domain: domainValue, }, } + _ = &admin.Execution{ Id: &core.WorkflowExecutionIdentifier{ Project: projectValue, @@ -126,21 +116,18 @@ func TestListExecutionFuncWithError(t *testing.T) { Phase: core.WorkflowExecution_SUCCEEDED, }, } - mockClient.OnListExecutionsMatch(mock.Anything, mock.MatchedBy(func(o *admin.ResourceListRequest) bool { - return execListRequest.SortBy.Key == o.SortBy.Key && execListRequest.SortBy.Direction == o.SortBy.Direction && execListRequest.Filters == o.Filters && execListRequest.Limit == o.Limit - })).Return(nil, errors.New("executions NotFound")) - err := getExecutionFunc(ctx, args, cmdCtx) + s := setup() + s.FetcherExt.OnListExecutionMatch(s.Ctx, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("executions NotFound")) + s.MockAdminClient.OnListExecutionsMatch(mock.Anything, execListRequest).Return(nil, errors.New("executions NotFound")) + err := getExecutionFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, err, errors.New("executions NotFound")) - mockClient.AssertCalled(t, "ListExecutions", ctx, execListRequest) + s.MockAdminClient.AssertCalled(t, "ListExecutions", ctx, execListRequest) } func TestGetExecutionFunc(t *testing.T) { ctx := context.Background() getExecutionSetup() - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) execGetRequest := &admin.WorkflowExecutionGetRequest{ Id: &core.WorkflowExecutionIdentifier{ Project: projectValue, @@ -173,37 +160,39 @@ func TestGetExecutionFunc(t *testing.T) { }, } args := []string{executionNameValue} - mockClient.OnGetExecutionMatch(ctx, execGetRequest).Return(executionResponse, nil) - err := getExecutionFunc(ctx, args, cmdCtx) - assert.Nil(t, err) - mockClient.AssertCalled(t, "GetExecution", ctx, execGetRequest) + s := setup() + //executionList := &admin.ExecutionList{ + // Executions: []*admin.Execution{executionResponse}, + //} + s.MockAdminClient.OnGetExecutionMatch(ctx, execGetRequest).Return(executionResponse, nil) + err := getExecutionFunc(s.Ctx, args, s.CmdCtx) + assert.Nil(t, err) + s.MockAdminClient.AssertCalled(t, "GetExecution", ctx, execGetRequest) } func TestGetExecutionFuncForDetails(t *testing.T) { - setup() + s := testutils.SetupWithExt() getExecutionSetup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockClient = u.MockClient - mockFetcherExt := u.FetcherExt + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt execution.DefaultConfig.Details = true args := []string{dummyExec} mockFetcherExt.OnFetchExecutionMatch(ctx, dummyExec, dummyProject, dummyDomain).Return(&admin.Execution{}, nil) mockFetcherExt.OnFetchNodeExecutionDetailsMatch(ctx, dummyExec, dummyProject, dummyDomain, "").Return(nil, fmt.Errorf("unable to fetch details")) - err = getExecutionFunc(ctx, args, mockCmdCtx) + err := getExecutionFunc(ctx, args, mockCmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to fetch details"), err) } func TestGetExecutionFuncWithIOData(t *testing.T) { t.Run("successful inputs outputs", func(t *testing.T) { - setup() + s := testutils.SetupWithExt() getExecutionSetup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockClient = u.MockClient - mockFetcherExt := u.FetcherExt + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt execution.DefaultConfig.NodeID = nodeID args := []string{dummyExec} @@ -259,16 +248,15 @@ func TestGetExecutionFuncWithIOData(t *testing.T) { }, nil) mockFetcherExt.OnFetchNodeExecutionDataMatch(ctx, mock.Anything, dummyExec, dummyProject, dummyDomain).Return(dataResp, nil) - err = getExecutionFunc(ctx, args, mockCmdCtx) + err := getExecutionFunc(ctx, args, mockCmdCtx) assert.Nil(t, err) }) t.Run("fetch data error from admin", func(t *testing.T) { - setup() + s := testutils.SetupWithExt() getExecutionSetup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockClient = u.MockClient - mockFetcherExt := u.FetcherExt + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt execution.DefaultConfig.NodeID = nodeID args := []string{dummyExec} @@ -285,7 +273,7 @@ func TestGetExecutionFuncWithIOData(t *testing.T) { }, nil) mockFetcherExt.OnFetchNodeExecutionDataMatch(ctx, mock.Anything, dummyExec, dummyProject, dummyDomain).Return(nil, fmt.Errorf("error in fetching data")) - err = getExecutionFunc(ctx, args, mockCmdCtx) + err := getExecutionFunc(ctx, args, mockCmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error in fetching data"), err) }) @@ -304,13 +292,13 @@ func TestGetExecutionFuncWithIOData(t *testing.T) { args := []string{dummyExec} for _, tt := range tests { - setup() + s := testutils.SetupWithExt() config.GetConfig().Output = tt.outputFormat execution.DefaultConfig.NodeID = tt.nodeID - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockFetcherExt := u.FetcherExt + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt nodeExecToTaskExec := map[string]*admin.TaskExecutionList{} nodeExec1 := createDummyNodeWithID("n0", false) @@ -377,16 +365,6 @@ func TestGetExecutionFuncWithIOData(t *testing.T) { func TestGetExecutionFuncWithError(t *testing.T) { ctx := context.Background() getExecutionSetup() - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) - execGetRequest := &admin.WorkflowExecutionGetRequest{ - Id: &core.WorkflowExecutionIdentifier{ - Project: projectValue, - Domain: domainValue, - Name: executionNameValue, - }, - } _ = &admin.Execution{ Id: &core.WorkflowExecutionIdentifier{ Project: projectValue, @@ -413,9 +391,10 @@ func TestGetExecutionFuncWithError(t *testing.T) { } args := []string{executionNameValue} - mockClient.OnGetExecutionMatch(ctx, execGetRequest).Return(nil, errors.New("execution NotFound")) - err := getExecutionFunc(ctx, args, cmdCtx) + s := testutils.SetupWithExt() + s.FetcherExt.OnFetchExecutionMatch(s.Ctx, mock.Anything, mock.Anything, mock.Anything).Return(nil, errors.New("execution NotFound")) + err := getExecutionFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, err, errors.New("execution NotFound")) - mockClient.AssertCalled(t, "GetExecution", ctx, execGetRequest) + s.FetcherExt.AssertCalled(t, "FetchExecution", ctx, "e124", "dummyProject", "dummyDomain") } diff --git a/cmd/get/get_test.go b/cmd/get/get_test.go index e92d7c1261..e4a1aec40d 100644 --- a/cmd/get/get_test.go +++ b/cmd/get/get_test.go @@ -1,15 +1,11 @@ package get import ( - "context" "fmt" "sort" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) @@ -23,12 +19,6 @@ const workflowNameValue = "wf_name" const workflowVersionValue = "wf_version" const testDataFolder = "../testdata/" -var ( - err error - ctx context.Context - mockClient *mocks.AdminServiceClient - cmdCtx cmdCore.CommandContext -) var setup = testutils.Setup var tearDownAndVerify = testutils.TearDownAndVerify diff --git a/cmd/get/launch_plan_test.go b/cmd/get/launch_plan_test.go index a36cd2ec77..3831631f87 100644 --- a/cmd/get/launch_plan_test.go +++ b/cmd/get/launch_plan_test.go @@ -5,14 +5,14 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/pkg/printer" "github.com/flyteorg/flytectl/pkg/filters" "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/launchplan" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flytectl/pkg/ext/mocks" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -35,10 +35,7 @@ var ( ) func getLaunchPlanSetup() { - ctx = u.Ctx - mockClient = u.MockClient // TODO: migrate to new command context from testutils - cmdCtx = cmdCore.NewCommandContext(mockClient, u.MockOutStream) argsLp = []string{"launchplan1"} parameterMap := map[string]*core.Parameter{ "numbers": { @@ -196,158 +193,168 @@ func getLaunchPlanSetup() { func TestGetLaunchPlanFuncWithError(t *testing.T) { t.Run("failure fetch latest", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) launchplan.DefaultConfig.Latest = true launchplan.DefaultConfig.Filter = filters.Filters{} mockFetcher.OnFetchLPLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching latest version")) - _, err = FetchLPForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchLPForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching version ", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) launchplan.DefaultConfig.Version = "v1" launchplan.DefaultConfig.Filter = filters.Filters{} mockFetcher.OnFetchLPVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching version")) - _, err = FetchLPForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchLPForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching all version ", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() launchplan.DefaultConfig.Filter = filters.Filters{} launchplan.DefaultConfig.Filter = filters.Filters{} mockFetcher := new(mocks.AdminFetcherExtInterface) mockFetcher.OnFetchAllVerOfLPMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching all version")) - _, err = FetchLPForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchLPForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching ", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() - mockClient.OnListLaunchPlansMatch(ctx, resourceGetRequest).Return(nil, fmt.Errorf("error fetching all version")) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(nil, fmt.Errorf("error fetching lanuch plan")) - mockClient.OnListLaunchPlanIdsMatch(ctx, namedIDRequest).Return(nil, fmt.Errorf("error listing lanuch plan ids")) - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "launchplan1", "dummyProject", "dummyDomain", filters.Filters{}).Return(nil, fmt.Errorf("error fetching all version")) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceGetRequest).Return(nil, fmt.Errorf("error fetching all version")) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(nil, fmt.Errorf("error fetching lanuch plan")) + s.MockAdminClient.OnListLaunchPlanIdsMatch(s.Ctx, namedIDRequest).Return(nil, fmt.Errorf("error listing lanuch plan ids")) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.NotNil(t, err) }) t.Run("failure fetching list", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() argsLp = []string{} - mockClient.OnListLaunchPlansMatch(ctx, resourceListRequest).Return(nil, fmt.Errorf("error fetching all version")) - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "", "dummyProject", "dummyDomain", filters.Filters{}).Return(nil, fmt.Errorf("error fetching all version")) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceListRequest).Return(nil, fmt.Errorf("error fetching all version")) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.NotNil(t, err) }) } func TestGetLaunchPlanFunc(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() - mockClient.OnListLaunchPlansMatch(ctx, resourceGetRequest).Return(launchPlanListResponse, nil) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan2, nil) - mockClient.OnListLaunchPlanIdsMatch(ctx, namedIDRequest).Return(namedIdentifierList, nil) - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceGetRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(launchPlan2, nil) + s.MockAdminClient.OnListLaunchPlanIdsMatch(s.Ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "launchplan1", "dummyProject", "dummyDomain", filters.Filters{}).Return(launchPlanListResponse.LaunchPlans, nil) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListLaunchPlans", ctx, resourceGetRequest) - tearDownAndVerify(t, `[{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "launchplan1","version": "v1"},"spec": {"workflowId": {"name": "workflow1"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) + s.MockAdminClient.AssertCalled(t, "ListLaunchPlans", s.Ctx, resourceGetRequest) + tearDownAndVerify(t, s.Writer, `[{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "launchplan1","version": "v1"},"spec": {"workflowId": {"name": "workflow1"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) } func TestGetLaunchPlanFuncLatest(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() launchplan.DefaultConfig.Latest = true launchplan.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListLaunchPlansMatch(ctx, resourceGetRequest).Return(launchPlanListResponse, nil) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan2, nil) - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceGetRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(launchPlan2, nil) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListLaunchPlans", ctx, resourceGetRequest) - tearDownAndVerify(t, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) + s.MockAdminClient.AssertCalled(t, "ListLaunchPlans", s.Ctx, resourceGetRequest) + tearDownAndVerify(t, s.Writer, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) } func TestGetLaunchPlanWithVersion(t *testing.T) { - setup() + s := testutils.SetupWithExt() getLaunchPlanSetup() launchplan.DefaultConfig.Version = "v2" - mockClient.OnListLaunchPlansMatch(ctx, resourceListRequest).Return(launchPlanListResponse, nil) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan2, nil) - mockClient.OnListLaunchPlanIdsMatch(ctx, namedIDRequest).Return(namedIdentifierList, nil) - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceListRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(launchPlan2, nil) + s.MockAdminClient.OnListLaunchPlanIdsMatch(s.Ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.FetcherExt.OnFetchLPVersion(s.Ctx, "launchplan1", "v2", "dummyProject", "dummyDomain").Return(launchPlan2, nil) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetLaunchPlan", ctx, objectGetRequest) - tearDownAndVerify(t, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) + s.FetcherExt.AssertCalled(t, "FetchLPVersion", s.Ctx, "launchplan1", "v2", "dummyProject", "dummyDomain") + tearDownAndVerify(t, s.Writer, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) } func TestGetLaunchPlans(t *testing.T) { t.Run("no workflow filter", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() - mockClient.OnListLaunchPlansMatch(ctx, resourceListRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceListRequest).Return(launchPlanListResponse, nil) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "", "dummyProject", "dummyDomain", filters.Filters{}).Return(launchPlanListResponse.LaunchPlans, nil) argsLp = []string{} - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `[{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "launchplan1","version": "v1"},"spec": {"workflowId": {"name": "workflow1"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) + tearDownAndVerify(t, s.Writer, `[{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "launchplan1","version": "v1"},"spec": {"workflowId": {"name": "workflow1"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) }) t.Run("workflow filter", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() resourceListRequest.Filters = "eq(workflow.name,workflow2)" - mockClient.OnListLaunchPlansMatch(ctx, resourceListRequest).Return(filteredLaunchPlanListResponse, nil) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceListRequest).Return(filteredLaunchPlanListResponse, nil) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "", "dummyProject", "dummyDomain", filters.Filters{ + FieldSelector: "workflow.name=workflow2", + }).Return(launchPlanListResponse.LaunchPlans, nil) argsLp = []string{} launchplan.DefaultConfig.Workflow = "workflow2" - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) + tearDownAndVerify(t, s.Writer, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) }) t.Run("workflow filter error", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() argsLp = []string{} launchplan.DefaultConfig.Workflow = "workflow2" launchplan.DefaultConfig.Filter.FieldSelector = "workflow.name" - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("fieldSelector cannot be specified with workflow flag"), err) }) } func TestGetLaunchPlansWithExecFile(t *testing.T) { - setup() + s := testutils.SetupWithExt() getLaunchPlanSetup() - mockClient.OnListLaunchPlansMatch(ctx, resourceListRequest).Return(launchPlanListResponse, nil) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan2, nil) - mockClient.OnListLaunchPlanIdsMatch(ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceListRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(launchPlan2, nil) + s.MockAdminClient.OnListLaunchPlanIdsMatch(s.Ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.FetcherExt.OnFetchLPVersion(s.Ctx, "launchplan1", "v2", "dummyProject", "dummyDomain").Return(launchPlan2, nil) launchplan.DefaultConfig.Version = "v2" launchplan.DefaultConfig.ExecFile = testDataFolder + "exec_file" - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) os.Remove(launchplan.DefaultConfig.ExecFile) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetLaunchPlan", ctx, objectGetRequest) - tearDownAndVerify(t, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) + s.FetcherExt.AssertCalled(t, "FetchLPVersion", s.Ctx, "launchplan1", "v2", "dummyProject", "dummyDomain") + tearDownAndVerify(t, s.Writer, `{"id": {"name": "launchplan1","version": "v2"},"spec": {"workflowId": {"name": "workflow2"},"defaultInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}}},"closure": {"expectedInputs": {"parameters": {"numbers": {"var": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "short desc"}},"numbers_count": {"var": {"type": {"simple": "INTEGER"},"description": "long description will be truncated in table"}},"run_local_at_count": {"var": {"type": {"simple": "INTEGER"},"description": "run_local_at_count"},"default": {"scalar": {"primitive": {"integer": "10"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}}`) } func TestGetLaunchPlanTableFunc(t *testing.T) { - setup() + s := testutils.SetupWithExt() getLaunchPlanSetup() - mockClient.OnListLaunchPlansMatch(ctx, resourceGetRequest).Return(launchPlanListResponse, nil) - mockClient.OnGetLaunchPlanMatch(ctx, objectGetRequest).Return(launchPlan2, nil) - mockClient.OnListLaunchPlanIdsMatch(ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.MockAdminClient.OnListLaunchPlansMatch(s.Ctx, resourceGetRequest).Return(launchPlanListResponse, nil) + s.MockAdminClient.OnGetLaunchPlanMatch(s.Ctx, objectGetRequest).Return(launchPlan2, nil) + s.MockAdminClient.OnListLaunchPlanIdsMatch(s.Ctx, namedIDRequest).Return(namedIdentifierList, nil) + s.FetcherExt.OnFetchAllVerOfLP(s.Ctx, "launchplan1", "dummyProject", "dummyDomain", filters.Filters{}).Return(launchPlanListResponse.LaunchPlans, nil) config.GetConfig().Output = printer.OutputFormatTABLE.String() - err = getLaunchPlanFunc(ctx, argsLp, cmdCtx) + err := getLaunchPlanFunc(s.Ctx, argsLp, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListLaunchPlans", ctx, resourceGetRequest) - tearDownAndVerify(t, ` + s.FetcherExt.AssertCalled(t, "FetchAllVerOfLP", s.Ctx, "launchplan1", "dummyProject", "dummyDomain", filters.Filters{}) + tearDownAndVerify(t, s.Writer, ` --------- ------------- ------ ------- ---------- --------------------------- --------- | VERSION | NAME | TYPE | STATE | SCHEDULE | INPUTS | OUTPUTS | --------- ------------- ------ ------- ---------- --------------------------- --------- diff --git a/cmd/get/matchable_cluster_resource_attribute_test.go b/cmd/get/matchable_cluster_resource_attribute_test.go index 9991e3688d..82fba0a6c8 100644 --- a/cmd/get/matchable_cluster_resource_attribute_test.go +++ b/cmd/get/matchable_cluster_resource_attribute_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/clusterresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getClusterResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient clusterresourceattribute.DefaultFetchConfig = &clusterresourceattribute.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -51,88 +49,82 @@ func TestGetClusterResourceAttributes(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","attributes":{"foo":"bar"}}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","attributes":{"foo":"bar"}}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() clusterresourceattribute.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() clusterresourceattribute.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_CLUSTER_RESOURCE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","attributes":{"foo":"bar"}}`) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","attributes":{"foo":"bar"}}`) }) t.Run("failed get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getClusterResourceAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getClusterResourceAttributes(ctx, args, cmdCtx) + err := getClusterResourceAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_CLUSTER_RESOURCE) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/matchable_execution_cluster_label_test.go b/cmd/get/matchable_execution_cluster_label_test.go index b49aab9d8b..d3aff8d6a5 100644 --- a/cmd/get/matchable_execution_cluster_label_test.go +++ b/cmd/get/matchable_execution_cluster_label_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionclusterlabel" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getExecutionClusterLabelSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionclusterlabel.DefaultFetchConfig = &executionclusterlabel.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -51,88 +49,82 @@ func TestGetExecutionClusterLabel(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","value":"foo"}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","value":"foo"}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() executionclusterlabel.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() executionclusterlabel.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed to get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_CLUSTER_LABEL) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","value":"foo"}`) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","value":"foo"}`) }) t.Run("failed to get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionClusterLabelSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getExecutionClusterLabel(ctx, args, cmdCtx) + err := getExecutionClusterLabel(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_EXECUTION_CLUSTER_LABEL) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/matchable_execution_queue_attribute_test.go b/cmd/get/matchable_execution_queue_attribute_test.go index 92bf156d95..521ee8e522 100644 --- a/cmd/get/matchable_execution_queue_attribute_test.go +++ b/cmd/get/matchable_execution_queue_attribute_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionqueueattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getExecutionQueueAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionqueueattribute.DefaultFetchConfig = &executionqueueattribute.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -51,88 +49,82 @@ func TestGetExecutionQueueAttributes(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","tags":["foo","bar"]}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","tags":["foo","bar"]}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() executionqueueattribute.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() executionqueueattribute.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_EXECUTION_QUEUE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","tags":["foo","bar"]}`) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","tags":["foo","bar"]}`) }) t.Run("failed get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getExecutionQueueAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getExecutionQueueAttributes(ctx, args, cmdCtx) + err := getExecutionQueueAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_EXECUTION_QUEUE) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/matchable_plugin_override_test.go b/cmd/get/matchable_plugin_override_test.go index b72ab6524e..16ec913754 100644 --- a/cmd/get/matchable_plugin_override_test.go +++ b/cmd/get/matchable_plugin_override_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" pluginoverride "github.com/flyteorg/flytectl/cmd/config/subcommand/plugin_override" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getPluginOverrideSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient pluginoverride.DefaultFetchConfig = &pluginoverride.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -63,86 +61,80 @@ func TestGetPluginOverride(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","overrides":[{"task_type":"python_task","plugin_id":["plugin-override1","plugin-override2"]},{"task_type":"java_task","plugin_id":["plugin-override3","plugin-override3"],"missing_plugin_behavior":1}]}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","overrides":[{"task_type":"python_task","plugin_id":["plugin-override1","plugin-override2"]},{"task_type":"java_task","plugin_id":["plugin-override3","plugin-override3"],"missing_plugin_behavior":1}]}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() pluginoverride.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() pluginoverride.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","overrides":[{"task_type":"python_task","plugin_id":["plugin-override1","plugin-override2"]},{"task_type":"java_task","plugin_id":["plugin-override3","plugin-override3"],"missing_plugin_behavior":1}]}`) + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","overrides":[{"task_type":"python_task","plugin_id":["plugin-override1","plugin-override2"]},{"task_type":"java_task","plugin_id":["plugin-override3","plugin-override3"],"missing_plugin_behavior":1}]}`) }) t.Run("failed get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getPluginOverrideSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getPluginOverridesFunc(ctx, args, cmdCtx) + err := getPluginOverridesFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_PLUGIN_OVERRIDE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_PLUGIN_OVERRIDE) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/matchable_task_resource_attribute_test.go b/cmd/get/matchable_task_resource_attribute_test.go index 6df5479859..021f02ea7f 100644 --- a/cmd/get/matchable_task_resource_attribute_test.go +++ b/cmd/get/matchable_task_resource_attribute_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/taskresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getTaskResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient taskresourceattribute.DefaultFetchConfig = &taskresourceattribute.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -58,88 +56,82 @@ func TestGetTaskResourceAttributes(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() taskresourceattribute.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() taskresourceattribute.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_TASK_RESOURCE) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","defaults":{"cpu":"1","memory":"150Mi"},"limits":{"cpu":"2","memory":"350Mi"}}`) }) t.Run("failed get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getTaskResourceAttributeSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getTaskResourceAttributes(ctx, args, cmdCtx) + err := getTaskResourceAttributes(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_TASK_RESOURCE) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/matchable_workflow_execution_config_test.go b/cmd/get/matchable_workflow_execution_config_test.go index c3c97829a6..e477bb3158 100644 --- a/cmd/get/matchable_workflow_execution_config_test.go +++ b/cmd/get/matchable_workflow_execution_config_test.go @@ -5,9 +5,10 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/cmd/config/subcommand/workflowexecutionconfig" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -15,9 +16,6 @@ import ( ) func getWorkflowExecutionConfigSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient workflowexecutionconfig.DefaultFetchConfig = &workflowexecutionconfig.AttrFetchConfig{} // Clean up the temp directory. _ = os.Remove(testDataTempFile) @@ -51,88 +49,82 @@ func TestGetWorkflowExecutionConfig(t *testing.T) { }, } t.Run("successful get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","max_parallelism":5}`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","max_parallelism":5}`) }) t.Run("successful get project domain attribute and write to file", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultFetchConfig.AttrFile = testDataTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, `wrote the config to file temp-output-file`) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + tearDownAndVerify(t, s.Writer, `wrote the config to file temp-output-file`) }) t.Run("successful get project domain attribute and write to file failure", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultFetchConfig.AttrFile = testDataNotExistentTempFile // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(projectDomainResp, nil) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error dumping in file due to open non-existent-dir/temp-output-file: no such file or directory"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("failed get project domain attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() // No args implying project domain attribute deletion - u.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, ``) + s.FetcherExt.AssertCalled(t, "FetchProjectDomainAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(workflowResp, nil) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","max_parallelism":5}`) + tearDownAndVerify(t, s.Writer, `{"project":"dummyProject","domain":"dummyDomain","workflow":"workflow","max_parallelism":5}`) }) t.Run("failed get workflow attribute", func(t *testing.T) { - var args []string - setup() + s := testutils.SetupWithExt() getWorkflowExecutionConfigSetup() - args = []string{"workflow"} - u.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + args := []string{"workflow"} + s.FetcherExt.OnFetchWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to fetch response")) - err = getWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := getWorkflowExecutionConfigFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to fetch response"), err) - u.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", - ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", + s.FetcherExt.AssertCalled(t, "FetchWorkflowAttributes", + s.Ctx, config.GetConfig().Project, config.GetConfig().Domain, "workflow", admin.MatchableResource_WORKFLOW_EXECUTION_CONFIG) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/get/node_execution_test.go b/cmd/get/node_execution_test.go index 05d5c2372f..1958f6a5c6 100644 --- a/cmd/get/node_execution_test.go +++ b/cmd/get/node_execution_test.go @@ -5,7 +5,8 @@ import ( "testing" "time" - u "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/event" @@ -159,10 +160,10 @@ func createDummyTaskExecutionForNode(nodeID string, taskID string) *admin.TaskEx func TestGetExecutionDetails(t *testing.T) { t.Run("successful get details default view", func(t *testing.T) { - setup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockFetcherExt := u.FetcherExt + s := testutils.SetupWithExt() + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt nodeExecStart := createDummyNodeWithID("start-node", false) nodeExecN2 := createDummyNodeWithID("n2", true) @@ -225,10 +226,10 @@ func TestGetExecutionDetails(t *testing.T) { }) t.Run("successful get details default view for node-id", func(t *testing.T) { - setup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockFetcherExt := u.FetcherExt + s := testutils.SetupWithExt() + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt nodeExec1 := createDummyNodeWithID("n0", false) taskExec1 := createDummyTaskExecutionForNode("n0", "task21") @@ -288,10 +289,10 @@ func TestGetExecutionDetails(t *testing.T) { }) t.Run("failure task exec fetch", func(t *testing.T) { - setup() - ctx := u.Ctx - mockCmdCtx := u.CmdCtx - mockFetcherExt := u.FetcherExt + s := testutils.SetupWithExt() + ctx := s.Ctx + mockCmdCtx := s.CmdCtx + mockFetcherExt := s.FetcherExt nodeExecToTaskExec := map[string]*admin.TaskExecutionList{} nodeExec1 := createDummyNodeWithID("n0", false) @@ -307,7 +308,7 @@ func TestGetExecutionDetails(t *testing.T) { mockFetcherExt.OnFetchNodeExecutionDetailsMatch(ctx, dummyExec, dummyProject, dummyDomain, "").Return(nodeExecList, nil) mockFetcherExt.OnFetchTaskExecutionsOnNodeMatch(ctx, "n0", dummyExec, dummyProject, dummyDomain).Return(nil, fmt.Errorf("unable to fetch task exec details")) - _, err = getExecutionDetails(ctx, dummyProject, dummyDomain, dummyExec, "", mockCmdCtx) + _, err := getExecutionDetails(ctx, dummyProject, dummyDomain, dummyExec, "", mockCmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to fetch task exec details"), err) }) diff --git a/cmd/get/project_test.go b/cmd/get/project_test.go index 264aa35c1c..d2a3a1abe7 100644 --- a/cmd/get/project_test.go +++ b/cmd/get/project_test.go @@ -2,15 +2,13 @@ package get import ( "fmt" - "io" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" + "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flytectl/cmd/config/subcommand/project" "github.com/flyteorg/flytectl/pkg/filters" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" ) @@ -18,16 +16,11 @@ import ( var ( resourceListRequestProject *admin.ProjectListRequest projectListResponse *admin.Projects - argsProject []string + argsProject = []string{"flyteexample"} project1 *admin.Project ) func getProjectSetup() { - - mockOutStream := new(io.Writer) - cmdCtx = cmdCore.NewCommandContext(mockClient, *mockOutStream) - - argsProject = []string{"flyteexample"} resourceListRequestProject = &admin.ProjectListRequest{} project1 = &admin.Project{ @@ -60,40 +53,40 @@ func getProjectSetup() { } func TestListProjectFunc(t *testing.T) { - setup() + s := testutils.SetupWithExt() getProjectSetup() - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) - project.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListProjectsMatch(ctx, resourceListRequestProject).Return(projectListResponse, nil) - err = getProjectsFunc(ctx, argsProject, cmdCtx) + s.MockAdminClient.OnListProjectsMatch(s.Ctx, resourceListRequestProject).Return(projectListResponse, nil) + s.FetcherExt.OnListProjects(s.Ctx, filters.Filters{}).Return(projectListResponse, nil) + err := getProjectsFunc(s.Ctx, argsProject, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListProjects", ctx, resourceListRequestProject) + s.FetcherExt.AssertCalled(t, "ListProjects", s.Ctx, filters.Filters{}) } func TestGetProjectFunc(t *testing.T) { - setup() + s := testutils.SetupWithExt() getProjectSetup() - argsProject = []string{} project.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListProjectsMatch(ctx, resourceListRequestProject).Return(projectListResponse, nil) - err = getProjectsFunc(ctx, argsProject, cmdCtx) + s.MockAdminClient.OnListProjectsMatch(s.Ctx, resourceListRequestProject).Return(projectListResponse, nil) + s.FetcherExt.OnListProjects(s.Ctx, filters.Filters{}).Return(projectListResponse, nil) + err := getProjectsFunc(s.Ctx, argsProject, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListProjects", ctx, resourceListRequestProject) + s.FetcherExt.AssertCalled(t, "ListProjects", s.Ctx, filters.Filters{}) } func TestGetProjectFuncError(t *testing.T) { - setup() + s := testutils.SetupWithExt() getProjectSetup() project.DefaultConfig.Filter = filters.Filters{ FieldSelector: "hello=", } - mockClient.OnListProjectsMatch(ctx, resourceListRequestProject).Return(nil, fmt.Errorf("Please add a valid field selector")) - err = getProjectsFunc(ctx, argsProject, cmdCtx) + s.MockAdminClient.OnListProjectsMatch(s.Ctx, resourceListRequestProject).Return(nil, fmt.Errorf("Please add a valid field selector")) + s.FetcherExt.OnListProjects(s.Ctx, filters.Filters{ + FieldSelector: "hello=", + }).Return(nil, fmt.Errorf("Please add a valid field selector")) + err := getProjectsFunc(s.Ctx, argsProject, s.CmdCtx) assert.NotNil(t, err) } diff --git a/cmd/get/task_test.go b/cmd/get/task_test.go index 0133c20f46..28816e8a1c 100644 --- a/cmd/get/task_test.go +++ b/cmd/get/task_test.go @@ -5,14 +5,14 @@ import ( "os" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" taskConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/task" "github.com/flyteorg/flytectl/pkg/filters" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flytectl/pkg/ext/mocks" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" @@ -37,10 +37,6 @@ var ( ) func getTaskSetup() { - ctx = u.Ctx - mockClient = u.MockClient - // TODO: migrate to new command context from testutils - cmdCtx = cmdCore.NewCommandContext(mockClient, u.MockOutStream) argsTask = []string{"task1"} sortedListLiteralType := core.Variable{ Type: &core.LiteralType{ @@ -179,73 +175,79 @@ func getTaskSetup() { func TestGetTaskFuncWithError(t *testing.T) { t.Run("failure fetch latest", func(t *testing.T) { - setup() + s := setup() getTaskSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) taskConfig.DefaultConfig.Latest = true taskConfig.DefaultConfig.Filter = filters.Filters{} mockFetcher.OnFetchTaskLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching latest version")) - _, err = FetchTaskForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchTaskForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching version ", func(t *testing.T) { - setup() + s := setup() getTaskSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) taskConfig.DefaultConfig.Version = "v1" taskConfig.DefaultConfig.Filter = filters.Filters{} mockFetcher.OnFetchTaskVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching version")) - _, err = FetchTaskForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchTaskForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching all version ", func(t *testing.T) { - setup() + s := setup() getTaskSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) taskConfig.DefaultConfig.Filter = filters.Filters{} mockFetcher.OnFetchAllVerOfTaskMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching all version")) - _, err = FetchTaskForName(ctx, mockFetcher, "lpName", projectValue, domainValue) + _, err := FetchTaskForName(s.Ctx, mockFetcher, "lpName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching ", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(nil, fmt.Errorf("error fetching all version")) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(nil, fmt.Errorf("error fetching task")) - mockClient.OnListTaskIdsMatch(ctx, namedIDRequestTask).Return(nil, fmt.Errorf("error listing task ids")) - err = getTaskFunc(ctx, argsTask, cmdCtx) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(nil, fmt.Errorf("error fetching all version")) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(nil, fmt.Errorf("error fetching task")) + s.MockAdminClient.OnListTaskIdsMatch(s.Ctx, namedIDRequestTask).Return(nil, fmt.Errorf("error listing task ids")) + s.FetcherExt.OnFetchAllVerOfTaskMatch(mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching all version")) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.NotNil(t, err) }) t.Run("failure fetching list task", func(t *testing.T) { - setup() + s := setup() getLaunchPlanSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} argsTask = []string{} - mockClient.OnListTasksMatch(ctx, resourceListTaskRequest).Return(nil, fmt.Errorf("error fetching all version")) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(nil, fmt.Errorf("error fetching task")) - mockClient.OnListTaskIdsMatch(ctx, namedIDRequestTask).Return(nil, fmt.Errorf("error listing task ids")) - err = getTaskFunc(ctx, argsTask, cmdCtx) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListTaskRequest).Return(nil, fmt.Errorf("error fetching all version")) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(nil, fmt.Errorf("error fetching task")) + s.MockAdminClient.OnListTaskIdsMatch(s.Ctx, namedIDRequestTask).Return(nil, fmt.Errorf("error listing task ids")) + s.FetcherExt.OnFetchAllVerOfTaskMatch(mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching all version")) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.NotNil(t, err) }) } func TestGetTaskFunc(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) - err = getTaskFunc(ctx, argsTask, cmdCtx) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.FetcherExt.OnFetchAllVerOfTaskMatch(mock.Anything, mock.Anything, mock.Anything, + mock.Anything, mock.Anything).Return(taskListResponse.Tasks, nil) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListTasks", ctx, resourceListRequestTask) - tearDownAndVerify(t, `[ + s.FetcherExt.AssertCalled(t, "FetchAllVerOfTask", s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}) + tearDownAndVerify(t, s.Writer, `[ { "id": { "name": "task1", @@ -320,16 +322,17 @@ func TestGetTaskFunc(t *testing.T) { } func TestGetTaskFuncWithTable(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.FetcherExt.OnFetchAllVerOfTask(s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}).Return(taskListResponse.Tasks, nil) config.GetConfig().Output = "table" - err = getTaskFunc(ctx, argsTask, cmdCtx) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListTasks", ctx, resourceListRequestTask) - tearDownAndVerify(t, ` + s.FetcherExt.AssertCalled(t, "FetchAllVerOfTask", s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}) + tearDownAndVerify(t, s.Writer, ` --------- ------- ------ --------------------------- --------- -------------- ------------------- ---------------------- | VERSION | NAME | TYPE | INPUTS | OUTPUTS | DISCOVERABLE | DISCOVERY VERSION | CREATED AT | --------- ------- ------ --------------------------- --------- -------------- ------------------- ---------------------- @@ -343,17 +346,18 @@ func TestGetTaskFuncWithTable(t *testing.T) { } func TestGetTaskFuncLatest(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) - mockClient.OnListTaskIdsMatch(ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.MockAdminClient.OnListTaskIdsMatch(s.Ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.FetcherExt.OnFetchTaskLatestVersion(s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}).Return(task2, nil) taskConfig.DefaultConfig.Latest = true - err = getTaskFunc(ctx, argsTask, cmdCtx) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "ListTasks", ctx, resourceListRequestTask) - tearDownAndVerify(t, `{ + s.FetcherExt.AssertCalled(t, "FetchTaskLatestVersion", s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}) + tearDownAndVerify(t, s.Writer, `{ "id": { "name": "task1", "version": "v2" @@ -391,18 +395,19 @@ func TestGetTaskFuncLatest(t *testing.T) { } func TestGetTaskWithVersion(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) - mockClient.OnListTaskIdsMatch(ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.MockAdminClient.OnListTaskIdsMatch(s.Ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.FetcherExt.OnFetchTaskVersion(s.Ctx, "task1", "v2", "dummyProject", "dummyDomain").Return(task2, nil) taskConfig.DefaultConfig.Version = "v2" objectGetRequestTask.Id.ResourceType = core.ResourceType_TASK - err = getTaskFunc(ctx, argsTask, cmdCtx) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetTask", ctx, objectGetRequestTask) - tearDownAndVerify(t, `{ + s.FetcherExt.AssertCalled(t, "FetchTaskVersion", s.Ctx, "task1", "v2", "dummyProject", "dummyDomain") + tearDownAndVerify(t, s.Writer, `{ "id": { "name": "task1", "version": "v2" @@ -440,41 +445,47 @@ func TestGetTaskWithVersion(t *testing.T) { } func TestGetTasks(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{} - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) - err = getTaskFunc(ctx, argsTask, cmdCtx) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.FetcherExt.OnFetchAllVerOfTask(s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{}).Return(taskListResponse.Tasks, nil) + + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `[{"id": {"name": "task1","version": "v2"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) + tearDownAndVerify(t, s.Writer, `[{"id": {"name": "task1","version": "v2"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:01Z"}},{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}]`) } func TestGetTasksFilters(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() taskConfig.DefaultConfig.Filter = filters.Filters{ FieldSelector: "task.name=task1,task.version=v1", } - mockClient.OnListTasksMatch(ctx, resourceListFilterRequestTask).Return(taskListFilterResponse, nil) - err = getTaskFunc(ctx, argsTask, cmdCtx) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListFilterRequestTask).Return(taskListFilterResponse, nil) + s.FetcherExt.OnFetchAllVerOfTask(s.Ctx, "task1", "dummyProject", "dummyDomain", filters.Filters{ + FieldSelector: "task.name=task1,task.version=v1", + }).Return(taskListResponse.Tasks, nil) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}`) + tearDownAndVerify(t, s.Writer, `{"id": {"name": "task1","version": "v1"},"closure": {"compiledTask": {"template": {"interface": {"inputs": {"variables": {"sorted_list1": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"},"sorted_list2": {"type": {"collectionType": {"simple": "INTEGER"}},"description": "var description"}}}}}},"createdAt": "1970-01-01T00:00:00Z"}}`) } func TestGetTaskWithExecFile(t *testing.T) { - setup() + s := testutils.SetupWithExt() getTaskSetup() - mockClient.OnListTasksMatch(ctx, resourceListRequestTask).Return(taskListResponse, nil) - mockClient.OnGetTaskMatch(ctx, objectGetRequestTask).Return(task2, nil) - mockClient.OnListTaskIdsMatch(ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.MockAdminClient.OnListTasksMatch(s.Ctx, resourceListRequestTask).Return(taskListResponse, nil) + s.MockAdminClient.OnGetTaskMatch(s.Ctx, objectGetRequestTask).Return(task2, nil) + s.MockAdminClient.OnListTaskIdsMatch(s.Ctx, namedIDRequestTask).Return(namedIdentifierListTask, nil) + s.FetcherExt.OnFetchTaskVersion(s.Ctx, "task1", "v2", "dummyProject", "dummyDomain").Return(task2, nil) taskConfig.DefaultConfig.Version = "v2" taskConfig.DefaultConfig.ExecFile = testDataFolder + "task_exec_file" - err = getTaskFunc(ctx, argsTask, cmdCtx) + err := getTaskFunc(s.Ctx, argsTask, s.CmdCtx) os.Remove(taskConfig.DefaultConfig.ExecFile) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetTask", ctx, objectGetRequestTask) - tearDownAndVerify(t, `{ + s.FetcherExt.AssertCalled(t, "FetchTaskVersion", s.Ctx, "task1", "v2", "dummyProject", "dummyDomain") + tearDownAndVerify(t, s.Writer, `{ "id": { "name": "task1", "version": "v2" diff --git a/cmd/get/workflow_test.go b/cmd/get/workflow_test.go index 46ad846cdd..d0b50007ca 100644 --- a/cmd/get/workflow_test.go +++ b/cmd/get/workflow_test.go @@ -4,6 +4,8 @@ import ( "fmt" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytectl/pkg/filters" "github.com/flyteorg/flytectl/pkg/printer" @@ -17,7 +19,6 @@ import ( "github.com/stretchr/testify/mock" "github.com/flyteorg/flytectl/cmd/config/subcommand/workflow" - u "github.com/flyteorg/flytectl/cmd/testutils" ) var ( @@ -29,9 +30,6 @@ var ( ) func getWorkflowSetup() { - ctx = u.Ctx - mockClient = u.MockClient - cmdCtx = u.CmdCtx resourceListRequestWorkflow = &admin.ResourceListRequest{ Id: &admin.NamedEntityIdentifier{ Project: projectValue, @@ -110,59 +108,59 @@ func getWorkflowSetup() { func TestGetWorkflowFuncWithError(t *testing.T) { t.Run("failure fetch latest", func(t *testing.T) { - setup() + s := setup() getWorkflowSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) workflow.DefaultConfig.Latest = true mockFetcher.OnFetchWorkflowLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching latest version")) - _, _, err = FetchWorkflowForName(ctx, mockFetcher, "workflowName", projectValue, domainValue) + _, _, err := FetchWorkflowForName(s.Ctx, mockFetcher, "workflowName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching version ", func(t *testing.T) { - setup() + s := setup() getWorkflowSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) workflow.DefaultConfig.Version = "v1" mockFetcher.OnFetchWorkflowVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching version")) - _, _, err = FetchWorkflowForName(ctx, mockFetcher, "workflowName", projectValue, domainValue) + _, _, err := FetchWorkflowForName(s.Ctx, mockFetcher, "workflowName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching all version ", func(t *testing.T) { - setup() + s := setup() getWorkflowSetup() mockFetcher := new(mocks.AdminFetcherExtInterface) mockFetcher.OnFetchAllVerOfWorkflowMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching all version")) - _, _, err = FetchWorkflowForName(ctx, mockFetcher, "workflowName", projectValue, domainValue) + _, _, err := FetchWorkflowForName(s.Ctx, mockFetcher, "workflowName", projectValue, domainValue) assert.NotNil(t, err) }) t.Run("failure fetching ", func(t *testing.T) { - setup() + s := testutils.SetupWithExt() getWorkflowSetup() workflow.DefaultConfig.Latest = true args := []string{"workflowName"} - u.FetcherExt.OnFetchWorkflowLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, + s.FetcherExt.OnFetchWorkflowLatestVersionMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("error fetching latest version")) - err = getWorkflowFunc(ctx, args, cmdCtx) + err := getWorkflowFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) }) } func TestGetWorkflowFuncLatestWithTable(t *testing.T) { - setup() + s := testutils.SetupWithExt() getWorkflowSetup() workflow.DefaultConfig.Latest = true workflow.DefaultConfig.Filter = filters.Filters{} config.GetConfig().Output = printer.OutputFormatTABLE.String() - u.FetcherExt.OnFetchWorkflowLatestVersionMatch(ctx, "workflow1", projectValue, domainValue, filters.Filters{}).Return(workflow1, nil) - err = getWorkflowFunc(ctx, argsWf, cmdCtx) + s.FetcherExt.OnFetchWorkflowLatestVersionMatch(s.Ctx, "workflow1", projectValue, domainValue, filters.Filters{}).Return(workflow1, nil) + err := getWorkflowFunc(s.Ctx, argsWf, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, ` + tearDownAndVerify(t, s.Writer, ` --------- ----------- --------------------------- --------- ---------------------- | VERSION | NAME | INPUTS | OUTPUTS | CREATED AT | --------- ----------- --------------------------- --------- ---------------------- @@ -173,14 +171,14 @@ func TestGetWorkflowFuncLatestWithTable(t *testing.T) { } func TestListWorkflowFuncWithTable(t *testing.T) { - setup() + s := testutils.SetupWithExt() getWorkflowSetup() workflow.DefaultConfig.Filter = filters.Filters{} config.GetConfig().Output = printer.OutputFormatTABLE.String() - u.FetcherExt.OnFetchAllVerOfWorkflowMatch(ctx, "workflow1", projectValue, domainValue, filters.Filters{}).Return(workflows, nil) - err = getWorkflowFunc(ctx, argsWf, cmdCtx) + s.FetcherExt.OnFetchAllVerOfWorkflowMatch(s.Ctx, "workflow1", projectValue, domainValue, filters.Filters{}).Return(workflows, nil) + err := getWorkflowFunc(s.Ctx, argsWf, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, ` + tearDownAndVerify(t, s.Writer, ` --------- ----------- ---------------------- | VERSION | NAME | CREATED AT | --------- ----------- ---------------------- diff --git a/cmd/register/examples.go b/cmd/register/examples.go index 8d1434294e..eb3feff8ec 100644 --- a/cmd/register/examples.go +++ b/cmd/register/examples.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "github.com/flyteorg/flytectl/cmd/config" + "github.com/flyteorg/flytestdlib/logger" "github.com/google/go-github/v42/github" @@ -54,8 +56,8 @@ func registerExamplesFunc(ctx context.Context, args []string, cmdCtx cmdCore.Com args := []string{ *v.BrowserDownloadURL, } - if err := Register(ctx, args, cmdCtx); err != nil { - return fmt.Errorf("Example %v failed to register %v", v.Name, err) + if err := Register(ctx, args, config.GetConfig(), cmdCtx); err != nil { + return fmt.Errorf("example %v failed to register %v", v.Name, err) } } return nil diff --git a/cmd/register/examples_test.go b/cmd/register/examples_test.go index f405d44284..fc3996f185 100644 --- a/cmd/register/examples_test.go +++ b/cmd/register/examples_test.go @@ -7,19 +7,18 @@ import ( ) func TestRegisterExamplesFunc(t *testing.T) { - setup() + s := setup() registerFilesSetup() - args = []string{""} - err := registerExamplesFunc(ctx, args, cmdCtx) + args := []string{""} + err := registerExamplesFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) } func TestRegisterExamplesFuncErr(t *testing.T) { - setup() + s := setup() registerFilesSetup() flytesnacks = "testingsnacks" - args = []string{""} - - err := registerExamplesFunc(ctx, args, cmdCtx) + args := []string{""} + err := registerExamplesFunc(s.Ctx, args, s.CmdCtx) // TODO (Yuvraj) make test to success after fixing flytesnacks bug assert.NotNil(t, err) flytesnacks = "flytesnacks" diff --git a/cmd/register/files.go b/cmd/register/files.go index c66ceddf7a..18f43c40c0 100644 --- a/cmd/register/files.go +++ b/cmd/register/files.go @@ -5,7 +5,10 @@ import ( "encoding/json" "fmt" "os" - "path/filepath" + + "github.com/flyteorg/flytectl/cmd/config" + + "github.com/flyteorg/flytestdlib/storage" rconfig "github.com/flyteorg/flytectl/cmd/config/subcommand/register" cmdCore "github.com/flyteorg/flytectl/cmd/core" @@ -106,10 +109,10 @@ Usage ) func registerFromFilesFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { - return Register(ctx, args, cmdCtx) + return Register(ctx, args, config.GetConfig(), cmdCtx) } -func Register(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { +func Register(ctx context.Context, args []string, cfg *config.Config, cmdCtx cmdCore.CommandContext) error { var regErr error var dataRefs []string @@ -125,7 +128,7 @@ func Register(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) logger.Infof(ctx, "Parsing file... Total(%v)", len(dataRefs)) // It will segregate serialize output files in valid proto,Invalid files if have any and source code(In case of fast serialize input files) - sourceCode, validProto, InvalidFiles := segregateSourceAndProtos(dataRefs) + sourceCodePath, validProto, InvalidFiles := segregateSourceAndProtos(dataRefs) // If any invalid files provide in input then through an error if len(InvalidFiles) > 0 { @@ -133,20 +136,22 @@ func Register(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) } // In case of fast serialize input upload source code to destination bucket - var sourceCodeName string - if len(sourceCode) > 0 { + var uploadLocation storage.DataReference + if len(sourceCodePath) > 0 { logger.Infof(ctx, "Fast Registration detected") - _, sourceCodeName = filepath.Split(sourceCode) - if err = uploadFastRegisterArtifact(ctx, sourceCode, sourceCodeName, rconfig.DefaultFilesConfig.Version, &rconfig.DefaultFilesConfig.SourceUploadPath); err != nil { - return fmt.Errorf("please check your Storage Config. It failed while uploading the source code. %v", err) + uploadLocation, err = uploadFastRegisterArtifact(ctx, cfg.Project, cfg.Domain, sourceCodePath, rconfig.DefaultFilesConfig.Version, + cmdCtx.ClientSet().DataProxyClient(), rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath) + if err != nil { + return fmt.Errorf("failed to upload source code from [%v]. Error: %w", sourceCodePath, err) } - logger.Infof(ctx, "Source code successfully uploaded %v/%v ", rconfig.DefaultFilesConfig.SourceUploadPath, sourceCodeName) + + logger.Infof(ctx, "Source code successfully uploaded to [%v]", uploadLocation) } var registerResults []Result fastFail := !rconfig.DefaultFilesConfig.ContinueOnError for i := 0; i < len(validProto) && !(fastFail && regErr != nil); i++ { - registerResults, regErr = registerFile(ctx, validProto[i], sourceCodeName, registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + registerResults, regErr = registerFile(ctx, validProto[i], registerResults, cmdCtx, uploadLocation, *rconfig.DefaultFilesConfig) } payload, _ := json.Marshal(registerResults) diff --git a/cmd/register/files_test.go b/cmd/register/files_test.go index 744e9cef2c..ea167f2971 100644 --- a/cmd/register/files_test.go +++ b/cmd/register/files_test.go @@ -4,6 +4,10 @@ import ( "fmt" "testing" + "github.com/flyteorg/flyteidl/clients/go/admin/mocks" + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service" + + "github.com/flyteorg/flytectl/cmd/config" "github.com/flyteorg/flytestdlib/contextutils" "github.com/flyteorg/flytestdlib/promutils/labeled" "github.com/flyteorg/flytestdlib/storage" @@ -20,161 +24,169 @@ const ( func TestRegisterFromFiles(t *testing.T) { t.Run("Valid registration", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/valid-parent-folder-register.tar"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) - err := registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/valid-parent-folder-register.tar"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + err := registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) }) t.Run("Valid fast registration", func(t *testing.T) { - setup() + s := setup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - rconfig.DefaultFilesConfig.SourceUploadPath = s3Output + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = s3Output mockStorage, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) assert.Nil(t, err) Client = mockStorage - args = []string{"testdata/flytesnacks-core.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + args := []string{"testdata/flytesnacks-core.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + + mockDataProxy := s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient) + mockDataProxy.OnCreateUploadLocationMatch(s.Ctx, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) - err = registerFromFilesFunc(ctx, args, cmdCtx) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) }) t.Run("Failed fast registration while uploading the codebase", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = true rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - s, err := storage.NewDataStore(&storage.Config{ + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) assert.Nil(t, err) - Client = s - args = []string{"testdata/flytesnacks-core.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) - err = Register(ctx, args, cmdCtx) + Client = store + args := []string{"testdata/flytesnacks-core.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(mock.Anything, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) + err = Register(s.Ctx, args, config.GetConfig(), s.CmdCtx) assert.Nil(t, err) }) t.Run("Failed registration because of invalid files", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = true - rconfig.DefaultFilesConfig.SourceUploadPath = "" - s, err := storage.NewDataStore(&storage.Config{ + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = "" + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) - Client = s + Client = store assert.Nil(t, err) - args = []string{"testdata/invalid-fast.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) - err = registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/invalid-fast.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) }) t.Run("Failure registration of fast serialize", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = true rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - rconfig.DefaultFilesConfig.SourceUploadPath = s3Output - s, err := storage.NewDataStore(&storage.Config{ + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = s3Output + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) - Client = s + Client = store assert.Nil(t, err) - args = []string{"testdata/flytesnacks-core.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) - err = registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/flytesnacks-core.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(1) + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(mock.Anything, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed"), err) }) t.Run("Failure registration of fast serialize continue on error", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = true rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - rconfig.DefaultFilesConfig.SourceUploadPath = s3Output + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = s3Output rconfig.DefaultFilesConfig.ContinueOnError = true - s, err := storage.NewDataStore(&storage.Config{ + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) - Client = s + Client = store assert.Nil(t, err) - args = []string{"testdata/flytesnacks-core.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(39) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(21) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(24) - err = registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/flytesnacks-core.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(39) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(21) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")).Call.Times(24) + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(mock.Anything, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed"), err) }) t.Run("Valid registration of fast serialize", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = true rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - rconfig.DefaultFilesConfig.SourceUploadPath = s3Output - s, err := storage.NewDataStore(&storage.Config{ + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = s3Output + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) - Client = s + Client = store assert.Nil(t, err) - args = []string{"testdata/flytesnacks-core.tgz"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) - err = registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/flytesnacks-core.tgz"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(mock.Anything, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) }) t.Run("Registration with proto files ", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) rconfig.DefaultFilesConfig.Archive = false rconfig.DefaultFilesConfig.OutputLocationPrefix = s3Output - rconfig.DefaultFilesConfig.SourceUploadPath = "" - s, err := storage.NewDataStore(&storage.Config{ + rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath = "" + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) - Client = s + Client = store assert.Nil(t, err) - args = []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) - err = registerFromFilesFunc(ctx, args, cmdCtx) + args := []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateWorkflowMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(mock.Anything, mock.Anything).Return(&service.CreateUploadLocationResponse{}, nil) + err = registerFromFilesFunc(s.Ctx, args, s.CmdCtx) assert.Nil(t, err) }) } diff --git a/cmd/register/register_test.go b/cmd/register/register_test.go index 871fc2523b..26a3186344 100644 --- a/cmd/register/register_test.go +++ b/cmd/register/register_test.go @@ -1,25 +1,17 @@ package register import ( - "context" "fmt" "net/http" "sort" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) var ( - ctx context.Context - mockAdminClient *mocks.AdminServiceClient - cmdCtx cmdCore.CommandContext - args []string - GetDoFunc func(req *http.Request) (*http.Response, error) + GetDoFunc func(req *http.Request) (*http.Response, error) ) var setup = u.Setup diff --git a/cmd/register/register_util.go b/cmd/register/register_util.go index f81c438fec..1982417f16 100644 --- a/cmd/register/register_util.go +++ b/cmd/register/register_util.go @@ -4,7 +4,6 @@ import ( "archive/tar" "compress/gzip" "context" - "encoding/json" "errors" "fmt" "io" @@ -12,9 +11,15 @@ import ( "net/http" "os" "path/filepath" + "regexp" "sort" + "strconv" "strings" + errors2 "github.com/flyteorg/flytestdlib/errors" + + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service" + "github.com/flyteorg/flytectl/pkg/githubutil" "github.com/flyteorg/flytestdlib/contextutils" @@ -54,6 +59,12 @@ var supportedExtensions = []string{".tar", ".tgz", ".tar.gz"} // All supported extensions for gzip compress var validGzipExtensions = []string{".tgz", ".tar.gz"} +type SignedURLPatternMatcher = *regexp.Regexp + +var ( + SignedURLPattern SignedURLPatternMatcher = regexp.MustCompile(`https://((storage\.googleapis\.com/(?P[^/]+))|((?P[^\.]+)\.s3\.amazonaws\.com)|(.*\.blob\.core\.windows\.net/(?P[^/]+)))/(?P[^?]*)`) +) + type Result struct { Name string Status string @@ -81,21 +92,34 @@ var projectColumns = []printer.Column{ func unMarshalContents(ctx context.Context, fileContents []byte, fname string) (proto.Message, error) { workflowSpec := &admin.WorkflowSpec{} - if err := proto.Unmarshal(fileContents, workflowSpec); err == nil { + errCollection := errors2.ErrorCollection{} + err := proto.Unmarshal(fileContents, workflowSpec) + if err == nil { return workflowSpec, nil } + + errCollection.Append(fmt.Errorf("as a Workflow: %w", err)) + logger.Debugf(ctx, "Failed to unmarshal file %v for workflow type", fname) taskSpec := &admin.TaskSpec{} - if err := proto.Unmarshal(fileContents, taskSpec); err == nil { + err = proto.Unmarshal(fileContents, taskSpec) + if err == nil { return taskSpec, nil } - logger.Debugf(ctx, "Failed to unmarshal file %v for task type", fname) + + errCollection.Append(fmt.Errorf("as a Task: %w", err)) + + logger.Debugf(ctx, "Failed to unmarshal file %v for task type", fname) launchPlan := &admin.LaunchPlan{} - if err := proto.Unmarshal(fileContents, launchPlan); err == nil { + err = proto.Unmarshal(fileContents, launchPlan) + if err == nil { return launchPlan, nil } + + errCollection.Append(fmt.Errorf("as a Launchplan: %w", err)) + logger.Debugf(ctx, "Failed to unmarshal file %v for launch plan type", fname) - return nil, fmt.Errorf("failed unmarshalling file %v", fname) + return nil, fmt.Errorf("failed unmarshalling file %v. Errors: %w", fname, errCollection.ErrorOrDefault()) } @@ -221,15 +245,11 @@ func hydrateIdentifier(identifier *core.Identifier, version string, force bool) } } -func hydrateTaskSpec(task *admin.TaskSpec, sourceCode, sourceUploadPath, version, destinationDir string) error { +func hydrateTaskSpec(task *admin.TaskSpec, sourceUploadedLocation storage.DataReference, destinationDir string) error { if task.Template.GetContainer() != nil { for k := range task.Template.GetContainer().Args { if task.Template.GetContainer().Args[k] == registrationRemotePackagePattern { - remotePath, err := getRemoteStoragePath(context.Background(), Client, sourceUploadPath, sourceCode, version) - if err != nil { - return err - } - task.Template.GetContainer().Args[k] = string(remotePath) + task.Template.GetContainer().Args[k] = sourceUploadedLocation.String() } if task.Template.GetContainer().Args[k] == registrationDestDirPattern { task.Template.GetContainer().Args[k] = "." @@ -247,11 +267,7 @@ func hydrateTaskSpec(task *admin.TaskSpec, sourceCode, sourceUploadPath, version for containerIdx, container := range podSpec.Containers { for argIdx, arg := range container.Args { if arg == registrationRemotePackagePattern { - remotePath, err := getRemoteStoragePath(context.Background(), Client, sourceUploadPath, sourceCode, version) - if err != nil { - return err - } - podSpec.Containers[containerIdx].Args[argIdx] = string(remotePath) + podSpec.Containers[containerIdx].Args[argIdx] = sourceUploadedLocation.String() } if arg == registrationDestDirPattern { podSpec.Containers[containerIdx].Args[argIdx] = "." @@ -392,7 +408,7 @@ func validateSpec(ctx context.Context, message proto.Message, cmdCtx cmdCore.Com return nil } -func hydrateSpec(message proto.Message, sourceCode string, config rconfig.FilesConfig) error { +func hydrateSpec(message proto.Message, uploadLocation storage.DataReference, config rconfig.FilesConfig) error { switch v := message.(type) { case *admin.LaunchPlan: launchPlan := message.(*admin.LaunchPlan) @@ -421,7 +437,7 @@ func hydrateSpec(message proto.Message, sourceCode string, config rconfig.FilesC taskSpec := message.(*admin.TaskSpec) hydrateIdentifier(taskSpec.Template.Id, config.Version, config.Force) // In case of fast serialize input proto also have on additional variable to substitute i.e destination bucket for source code - if err := hydrateTaskSpec(taskSpec, sourceCode, config.SourceUploadPath, config.Version, config.DestinationDirectory); err != nil { + if err := hydrateTaskSpec(taskSpec, uploadLocation, config.DestinationDirectory); err != nil { return err } @@ -456,8 +472,18 @@ func getSerializeOutputFiles(ctx context.Context, args []string, archive bool) ( * generated otherwise the registration can fail if the dependent files are not registered earlier. */ - sort.Strings(args) - return args, "", nil + finalList := make([]string, 0, len(args)) + for _, arg := range args { + matches, err := filepath.Glob(arg) + if err != nil { + return nil, "", fmt.Errorf("failed to glob [%v]. Error: %w", arg, err) + } + + finalList = append(finalList, matches...) + } + + sort.Strings(finalList) + return finalList, "", nil } tempDir, err := ioutil.TempDir("/tmp", "register") @@ -523,7 +549,9 @@ func readAndCopyArchive(src io.Reader, tempDir string, unarchivedFiles []string) } } -func registerFile(ctx context.Context, fileName, sourceCode string, registerResults []Result, cmdCtx cmdCore.CommandContext, config rconfig.FilesConfig) ([]Result, error) { +func registerFile(ctx context.Context, fileName string, registerResults []Result, + cmdCtx cmdCore.CommandContext, uploadLocation storage.DataReference, config rconfig.FilesConfig) ([]Result, error) { + var registerResult Result var fileContents []byte var err error @@ -539,7 +567,7 @@ func registerFile(ctx context.Context, fileName, sourceCode string, registerResu return registerResults, err } - if err := hydrateSpec(spec, sourceCode, config); err != nil { + if err := hydrateSpec(spec, uploadLocation, config); err != nil { registerResult = Result{Name: fileName, Status: "Failed", Info: fmt.Sprintf("Error hydrating spec due to %v", err)} registerResults = append(registerResults, registerResult) return registerResults, err @@ -642,44 +670,124 @@ func getAllExample(repository, version string) ([]*github.ReleaseAsset, *github. func getRemoteStoragePath(ctx context.Context, s *storage.DataStore, remoteLocation, file, identifier string) (storage.DataReference, error) { remotePath, err := s.ConstructReference(ctx, storage.DataReference(remoteLocation), fmt.Sprintf("%v-%v", identifier, file)) if err != nil { - return storage.DataReference(""), err + return "", err } + return remotePath, nil } -func uploadFastRegisterArtifact(ctx context.Context, file, sourceCodeName, version string, sourceUploadPath *string) error { +func getTotalSize(reader io.Reader) (size int64, err error) { + page := make([]byte, 512) + size = 0 + + n := 0 + for n, err = reader.Read(page); n > 0 && err == nil; n, err = reader.Read(page) { + size += int64(n) + } + + if err == io.EOF { + return size + int64(n), nil + } + + return size, err +} + +func uploadFastRegisterArtifact(ctx context.Context, project, domain, sourceCodeFilePath, version string, + dataProxyClient service.DataProxyServiceClient, deprecatedSourceUploadPath string) (uploadLocation storage.DataReference, err error) { + + fileHandle, err := os.Open(sourceCodeFilePath) + if err != nil { + return "", err + } + + dataRefReaderCloser, err := gzip.NewReader(fileHandle) + if err != nil { + return "", err + } + + size, err := getTotalSize(dataRefReaderCloser) + if err != nil { + return "", err + } + + _, err = fileHandle.Seek(0, 0) + if err != nil { + return "", err + } + + err = dataRefReaderCloser.Reset(fileHandle) + if err != nil { + return "", err + } + + remotePath := storage.DataReference(deprecatedSourceUploadPath) + _, fileName := filepath.Split(sourceCodeFilePath) + resp, err := dataProxyClient.CreateUploadLocation(ctx, &service.CreateUploadLocationRequest{ + Project: project, + Domain: domain, + Suffix: strings.Join([]string{version, fileName}, "/"), + }) + + if err != nil { + if status.Code(err) == codes.Unimplemented { + logger.Infof(ctx, "Using an older version of FlyteAdmin. Falling back to the configured storage client.") + } else { + return "", fmt.Errorf("failed to create an upload location. Error: %w", err) + } + } + + if resp != nil && len(resp.SignedUrl) > 0 { + return storage.DataReference(resp.NativeUrl), DirectUpload(resp.SignedUrl, size, dataRefReaderCloser) + } + dataStore, err := getStorageClient(ctx) if err != nil { - return err + return "", err } - var dataRefReaderCloser io.ReadCloser - remotePath := storage.DataReference(*sourceUploadPath) - if len(*sourceUploadPath) == 0 { + + if len(deprecatedSourceUploadPath) == 0 { remotePath, err = dataStore.ConstructReference(ctx, dataStore.GetBaseContainerFQN(ctx), "fast") if err != nil { - return err + return "", err } } - *sourceUploadPath = string(remotePath) - fullRemotePath, err := getRemoteStoragePath(ctx, dataStore, *sourceUploadPath, sourceCodeName, version) + + remotePath, err = getRemoteStoragePath(ctx, dataStore, remotePath.String(), fileName, version) if err != nil { - return err + return "", err } - raw, err := json.Marshal(file) - if err != nil { - return err + + if err := dataStore.ComposedProtobufStore.WriteRaw(ctx, remotePath, size, storage.Options{}, dataRefReaderCloser); err != nil { + return "", err } - dataRefReaderCloser, err = os.Open(file) + + return remotePath, nil +} + +func DirectUpload(url string, size int64, data io.Reader) error { + req, err := http.NewRequest(http.MethodPut, url, data) if err != nil { return err } - dataRefReaderCloser, err = gzip.NewReader(dataRefReaderCloser) + + req.ContentLength = size + req.Header.Set("Content-Length", strconv.FormatInt(size, 10)) + + client := &http.Client{} + res, err := client.Do(req) if err != nil { return err } - if err := dataStore.ComposedProtobufStore.WriteRaw(ctx, fullRemotePath, int64(len(raw)), storage.Options{}, dataRefReaderCloser); err != nil { - return err + + if res.StatusCode != http.StatusOK { + raw, err := ioutil.ReadAll(res.Body) + if err != nil { + return fmt.Errorf("received response code [%v]. Failed to read response body. Error: %w", res.StatusCode, err) + } + + return fmt.Errorf("bad status: %s : %s", res.Status, string(raw)) } + return nil } diff --git a/cmd/register/register_util_test.go b/cmd/register/register_util_test.go index 491c0c1f98..e9b4caae05 100644 --- a/cmd/register/register_util_test.go +++ b/cmd/register/register_util_test.go @@ -1,6 +1,7 @@ package register import ( + "bytes" "context" "errors" "fmt" @@ -11,6 +12,9 @@ import ( "strings" "testing" + "github.com/flyteorg/flyteidl/clients/go/admin/mocks" + "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/service" + "github.com/flyteorg/flytestdlib/utils" v1 "k8s.io/api/core/v1" @@ -23,8 +27,6 @@ import ( "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" rconfig "github.com/flyteorg/flytectl/cmd/config/subcommand/register" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -54,9 +56,6 @@ func registerFilesSetup() { GetDoFunc = func(*http.Request) (*http.Response, error) { return response, nil } - ctx = u.Ctx - mockAdminClient = u.MockClient - cmdCtx = cmdCore.NewCommandContext(mockAdminClient, u.MockOutStream) rconfig.DefaultFilesConfig.AssumableIamRole = "" rconfig.DefaultFilesConfig.K8sServiceAccount = "" @@ -64,11 +63,11 @@ func registerFilesSetup() { } func TestGetSortedArchivedFileWithParentFolderList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/valid-parent-folder-register.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/valid-parent-folder-register.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 4) assert.Equal(t, filepath.Join(tmpDir, "parentfolder", "014_recipes.core.basic.basic_workflow.t1_1.pb"), fileList[0]) assert.Equal(t, filepath.Join(tmpDir, "parentfolder", "015_recipes.core.basic.basic_workflow.t2_1.pb"), fileList[1]) @@ -81,11 +80,11 @@ func TestGetSortedArchivedFileWithParentFolderList(t *testing.T) { } func TestGetSortedArchivedFileList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/valid-register.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/valid-register.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 4) assert.Equal(t, filepath.Join(tmpDir, "014_recipes.core.basic.basic_workflow.t1_1.pb"), fileList[0]) assert.Equal(t, filepath.Join(tmpDir, "015_recipes.core.basic.basic_workflow.t2_1.pb"), fileList[1]) @@ -98,11 +97,11 @@ func TestGetSortedArchivedFileList(t *testing.T) { } func TestGetSortedArchivedFileUnorderedList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/valid-unordered-register.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/valid-unordered-register.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 4) assert.Equal(t, filepath.Join(tmpDir, "014_recipes.core.basic.basic_workflow.t1_1.pb"), fileList[0]) assert.Equal(t, filepath.Join(tmpDir, "015_recipes.core.basic.basic_workflow.t2_1.pb"), fileList[1]) @@ -115,11 +114,11 @@ func TestGetSortedArchivedFileUnorderedList(t *testing.T) { } func TestGetSortedArchivedCorruptedFileList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/invalid.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/invalid.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 0) assert.True(t, strings.HasPrefix(tmpDir, "/tmp/register")) assert.NotNil(t, err) @@ -128,11 +127,11 @@ func TestGetSortedArchivedCorruptedFileList(t *testing.T) { } func TestGetSortedArchivedTgzList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/valid-register.tgz"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/valid-register.tgz"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 4) assert.Equal(t, filepath.Join(tmpDir, "014_recipes.core.basic.basic_workflow.t1_1.pb"), fileList[0]) assert.Equal(t, filepath.Join(tmpDir, "015_recipes.core.basic.basic_workflow.t2_1.pb"), fileList[1]) @@ -145,10 +144,10 @@ func TestGetSortedArchivedTgzList(t *testing.T) { } func TestGetSortedArchivedCorruptedTgzFileList(t *testing.T) { - setup() + s := setup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/invalid.tgz"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/invalid.tgz"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, 0, len(fileList)) assert.True(t, strings.HasPrefix(tmpDir, "/tmp/register")) assert.NotNil(t, err) @@ -157,11 +156,11 @@ func TestGetSortedArchivedCorruptedTgzFileList(t *testing.T) { } func TestGetSortedArchivedInvalidArchiveFileList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"testdata/invalid-extension-register.zip"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"testdata/invalid-extension-register.zip"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, 0, len(fileList)) assert.True(t, strings.HasPrefix(tmpDir, "/tmp/register")) assert.NotNil(t, err) @@ -171,10 +170,10 @@ func TestGetSortedArchivedInvalidArchiveFileList(t *testing.T) { } func TestGetSortedArchivedFileThroughInvalidHttpList(t *testing.T) { - setup() + s := setup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"http://invalidhost:invalidport/testdata/valid-register.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"http://invalidhost:invalidport/testdata/valid-register.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, 0, len(fileList)) assert.True(t, strings.HasPrefix(tmpDir, "/tmp/register")) assert.NotNil(t, err) @@ -183,11 +182,11 @@ func TestGetSortedArchivedFileThroughInvalidHttpList(t *testing.T) { } func TestGetSortedArchivedFileThroughValidHttpList(t *testing.T) { - setup() + s := setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"http://dummyhost:80/testdata/valid-register.tar"} - fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) + args := []string{"http://dummyhost:80/testdata/valid-register.tar"} + fileList, tmpDir, err := getSerializeOutputFiles(s.Ctx, args, rconfig.DefaultFilesConfig.Archive) assert.Equal(t, len(fileList), 4) assert.Equal(t, filepath.Join(tmpDir, "014_recipes.core.basic.basic_workflow.t1_1.pb"), fileList[0]) assert.Equal(t, filepath.Join(tmpDir, "015_recipes.core.basic.basic_workflow.t2_1.pb"), fileList[1]) @@ -203,10 +202,10 @@ func TestGetSortedArchivedFileThroughValidHttpWithNullContextList(t *testing.T) setup() registerFilesSetup() rconfig.DefaultFilesConfig.Archive = true - args = []string{"http://dummyhost:80/testdata/valid-register.tar"} - ctx = nil + args := []string{"http://dummyhost:80/testdata/valid-register.tar"} + var ctx context.Context = nil fileList, tmpDir, err := getSerializeOutputFiles(ctx, args, rconfig.DefaultFilesConfig.Archive) - assert.Equal(t, len(fileList), 0) + assert.Equal(t, 0, len(fileList)) assert.True(t, strings.HasPrefix(tmpDir, "/tmp/register")) assert.NotNil(t, err) assert.Equal(t, errors.New("net/http: nil Context"), err) @@ -214,21 +213,28 @@ func TestGetSortedArchivedFileThroughValidHttpWithNullContextList(t *testing.T) assert.Nil(t, os.RemoveAll(tmpDir), "unable to delete temp dir %v", tmpDir) } +func Test_getTotalSize(t *testing.T) { + b := bytes.NewBufferString("hello world") + size, err := getTotalSize(b) + assert.NoError(t, err) + assert.Equal(t, int64(11), size) +} + func TestRegisterFile(t *testing.T) { t.Run("Successful run", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) - args = []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, nil) + args := []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Nil(t, err) }) t.Run("Failed Scheduled launch plan registration", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) + s.MockAdminClient.OnCreateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, nil) variableMap := map[string]*core.Variable{ "var1": { Type: &core.LiteralType{ @@ -270,58 +276,60 @@ func TestRegisterFile(t *testing.T) { }, }, } - mockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) - args = []string{"testdata/152_my_cron_scheduled_lp_3.pb"} + s.MockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) + s.FetcherExt.OnFetchWorkflowVersion(s.Ctx, "core.scheduled_workflows.lp_schedules.date_formatter_wf", "v0.3.59", "dummyProject", "dummyDomain").Return(wf, nil) + s.FetcherExt.OnFetchWorkflowVersion(s.Ctx, "core.scheduled_workflows.lp_schedules.date_formatter_wf", "", "dummyProject", "dummyDomain").Return(wf, nil) + args := []string{"testdata/152_my_cron_scheduled_lp_3.pb"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Equal(t, "Failed", results[0].Status) assert.Contains(t, results[0].Info, "param values are missing on scheduled workflow for the following params") assert.NotNil(t, err) }) t.Run("Non existent file", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - args = []string{"testdata/non-existent.pb"} + args := []string{"testdata/non-existent.pb"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Equal(t, "Failed", results[0].Status) assert.Equal(t, "Error reading file due to open testdata/non-existent.pb: no such file or directory", results[0].Info) assert.NotNil(t, err) }) t.Run("unmarhal failure", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - args = []string{"testdata/valid-register.tar"} + args := []string{"testdata/valid-register.tar"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Equal(t, "Failed", results[0].Status) - assert.Equal(t, "Error unmarshalling file due to failed unmarshalling file testdata/valid-register.tar", results[0].Info) + assert.True(t, strings.HasPrefix(results[0].Info, "Error unmarshalling file due to failed unmarshalling file testdata/valid-register.tar")) assert.NotNil(t, err) }) t.Run("AlreadyExists", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, status.Error(codes.AlreadyExists, "AlreadyExists")) - args = []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} + args := []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Equal(t, "Success", results[0].Status) assert.Equal(t, "AlreadyExists", results[0].Info) assert.Nil(t, err) }) t.Run("Registration Error", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, + s.MockAdminClient.OnCreateTaskMatch(mock.Anything, mock.Anything).Return(nil, status.Error(codes.InvalidArgument, "Invalid")) - args = []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} + args := []string{"testdata/69_core.flyte_basics.lp.greet_1.pb"} var registerResults []Result - results, err := registerFile(ctx, args[0], "", registerResults, cmdCtx, *rconfig.DefaultFilesConfig) + results, err := registerFile(s.Ctx, args[0], registerResults, s.CmdCtx, "", *rconfig.DefaultFilesConfig) assert.Equal(t, 1, len(results)) assert.Equal(t, "Failed", results[0].Status) assert.Equal(t, "Error registering file due to rpc error: code = InvalidArgument desc = Invalid", results[0].Info) @@ -340,7 +348,6 @@ func TestHydrateLaunchPlanSpec(t *testing.T) { assert.Equal(t, &admin.AuthRole{AssumableIamRole: "iamRole"}, lpSpec.AuthRole) }) t.Run("k8sService account override", func(t *testing.T) { - setup() registerFilesSetup() rconfig.DefaultFilesConfig.K8sServiceAccount = "k8Account" lpSpec := &admin.LaunchPlanSpec{} @@ -349,7 +356,6 @@ func TestHydrateLaunchPlanSpec(t *testing.T) { assert.Equal(t, &admin.AuthRole{KubernetesServiceAccount: "k8Account"}, lpSpec.AuthRole) }) t.Run("Both k8sService and IamRole", func(t *testing.T) { - setup() registerFilesSetup() rconfig.DefaultFilesConfig.AssumableIamRole = "iamRole" rconfig.DefaultFilesConfig.K8sServiceAccount = "k8Account" @@ -360,7 +366,6 @@ func TestHydrateLaunchPlanSpec(t *testing.T) { KubernetesServiceAccount: "k8Account"}, lpSpec.AuthRole) }) t.Run("Output prefix", func(t *testing.T) { - setup() registerFilesSetup() rconfig.DefaultFilesConfig.OutputLocationPrefix = "prefix" lpSpec := &admin.LaunchPlanSpec{} @@ -372,25 +377,37 @@ func TestHydrateLaunchPlanSpec(t *testing.T) { func TestUploadFastRegisterArtifact(t *testing.T) { t.Run("Successful upload", func(t *testing.T) { + s := setup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) - s, err := storage.NewDataStore(&storage.Config{ + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) assert.Nil(t, err) - Client = s - err = uploadFastRegisterArtifact(ctx, "testdata/flytesnacks-core.tgz", "flytesnacks-core.tgz", "", &rconfig.DefaultFilesConfig.SourceUploadPath) + Client = store + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(s.Ctx, &service.CreateUploadLocationRequest{ + Project: "flytesnacks", + Domain: "development", + Suffix: "/flytesnacks-core.tgz", + }).Return(&service.CreateUploadLocationResponse{}, nil) + _, err = uploadFastRegisterArtifact(s.Ctx, "flytesnacks", "development", "testdata/flytesnacks-core.tgz", "", s.MockClient.DataProxyClient(), rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath) assert.Nil(t, err) }) t.Run("Failed upload", func(t *testing.T) { + s := setup() testScope := promutils.NewTestScope() labeled.SetMetricKeys(contextutils.AppNameKey, contextutils.ProjectKey, contextutils.DomainKey) - s, err := storage.NewDataStore(&storage.Config{ + store, err := storage.NewDataStore(&storage.Config{ Type: storage.TypeMemory, }, testScope.NewSubScope("flytectl")) assert.Nil(t, err) - Client = s - err = uploadFastRegisterArtifact(ctx, "testdata/flytesnacks-core.tgz", "", "", &rconfig.DefaultFilesConfig.SourceUploadPath) + Client = store + s.MockClient.DataProxyClient().(*mocks.DataProxyServiceClient).OnCreateUploadLocationMatch(s.Ctx, &service.CreateUploadLocationRequest{ + Project: "flytesnacks", + Domain: "development", + Suffix: "/flytesnacks-core.tgz", + }).Return(&service.CreateUploadLocationResponse{}, nil) + _, err = uploadFastRegisterArtifact(context.Background(), "flytesnacks", "development", "testdata/flytesnacks-core.tgz", "", s.MockClient.DataProxyClient(), rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath) assert.Nil(t, err) }) t.Run("Failed upload", func(t *testing.T) { @@ -401,7 +418,7 @@ func TestUploadFastRegisterArtifact(t *testing.T) { }, testScope.NewSubScope("flytectl")) assert.Nil(t, err) Client = s - err = uploadFastRegisterArtifact(ctx, "testdata/flytesnacksre.tgz", "", "", &rconfig.DefaultFilesConfig.SourceUploadPath) + _, err = uploadFastRegisterArtifact(context.Background(), "flytesnacks", "development", "testdata/flytesnacksre.tgz", "", nil, rconfig.DefaultFilesConfig.DeprecatedSourceUploadPath) assert.NotNil(t, err) }) } @@ -409,7 +426,7 @@ func TestUploadFastRegisterArtifact(t *testing.T) { func TestGetStorageClient(t *testing.T) { t.Run("Failed to create storage client", func(t *testing.T) { Client = nil - s, err := getStorageClient(ctx) + s, err := getStorageClient(context.Background()) assert.NotNil(t, err) assert.Nil(t, s) }) @@ -434,17 +451,16 @@ func TestGetAllFlytesnacksExample(t *testing.T) { func TestRegister(t *testing.T) { t.Run("Failed to register", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() node := &admin.NodeExecution{} - err := register(ctx, node, cmdCtx, rconfig.DefaultFilesConfig.DryRun) + err := register(s.Ctx, node, s.CmdCtx, rconfig.DefaultFilesConfig.DryRun) assert.NotNil(t, err) }) } func TestHydrateNode(t *testing.T) { t.Run("Failed hydrate node", func(t *testing.T) { - setup() registerFilesSetup() node := &core.Node{} err := hydrateNode(node, rconfig.DefaultFilesConfig.Version, true) @@ -452,7 +468,6 @@ func TestHydrateNode(t *testing.T) { }) t.Run("hydrateSpec with wrong type", func(t *testing.T) { - setup() registerFilesSetup() task := &admin.Task{} err := hydrateSpec(task, "", *rconfig.DefaultFilesConfig) @@ -503,13 +518,13 @@ func TestHydrateTaskSpec(t *testing.T) { }, }, } - err = hydrateTaskSpec(task, "sourcey", rconfig.DefaultFilesConfig.SourceUploadPath, rconfig.DefaultFilesConfig.Version, "") + err = hydrateTaskSpec(task, storage.DataReference("file://somewhere"), "sourcey") assert.NoError(t, err) var hydratedPodSpec = v1.PodSpec{} err = utils.UnmarshalStructToObj(task.Template.GetK8SPod().PodSpec, &hydratedPodSpec) assert.NoError(t, err) assert.Len(t, hydratedPodSpec.Containers[1].Args, 2) - assert.True(t, strings.HasSuffix(hydratedPodSpec.Containers[1].Args[1], "sourcey")) + assert.Contains(t, hydratedPodSpec.Containers[1].Args[1], "somewhere") } func TestLeftDiff(t *testing.T) { @@ -564,17 +579,20 @@ func TestLeftDiff(t *testing.T) { func TestValidateLaunchSpec(t *testing.T) { ctx := context.Background() t.Run("nil launchplan spec", func(t *testing.T) { + s := setup() registerFilesSetup() - err := validateLaunchSpec(ctx, nil, cmdCtx) + err := validateLaunchSpec(ctx, nil, s.CmdCtx) assert.Nil(t, err) }) t.Run("launchplan spec with nil workflow id", func(t *testing.T) { + s := setup() registerFilesSetup() lpSpec := &admin.LaunchPlanSpec{} - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.Nil(t, err) }) t.Run("launchplan spec with empty metadata", func(t *testing.T) { + s := setup() registerFilesSetup() lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ @@ -584,10 +602,11 @@ func TestValidateLaunchSpec(t *testing.T) { Version: "workflowVersionValue", }, } - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.Nil(t, err) }) t.Run("launchplan spec with metadata and empty schedule", func(t *testing.T) { + s := setup() registerFilesSetup() lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ @@ -598,14 +617,14 @@ func TestValidateLaunchSpec(t *testing.T) { }, EntityMetadata: &admin.LaunchPlanMetadata{}, } - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.Nil(t, err) }) t.Run("validate spec failed to fetch workflow", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")) + s.MockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")) lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ Project: "projectValue", @@ -622,15 +641,15 @@ func TestValidateLaunchSpec(t *testing.T) { lp := &admin.LaunchPlan{ Spec: lpSpec, } - err := validateSpec(ctx, lp, cmdCtx) + err := validateSpec(ctx, lp, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, "failed", err.Error()) }) t.Run("failed to fetch workflow", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() - mockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")) + s.MockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed")) lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ Project: "projectValue", @@ -644,12 +663,12 @@ func TestValidateLaunchSpec(t *testing.T) { }, }, } - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, "failed", err.Error()) }) t.Run("launchplan spec missing required param schedule", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() variableMap := map[string]*core.Variable{ "var1": { @@ -692,7 +711,7 @@ func TestValidateLaunchSpec(t *testing.T) { }, }, } - mockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) + s.MockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ Project: "projectValue", @@ -706,12 +725,12 @@ func TestValidateLaunchSpec(t *testing.T) { }, }, } - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.NotNil(t, err) assert.Contains(t, err.Error(), "param values are missing on scheduled workflow for the following params") }) t.Run("launchplan spec non empty schedule required param success", func(t *testing.T) { - setup() + s := setup() registerFilesSetup() variableMap := map[string]*core.Variable{ "var1": { @@ -754,7 +773,7 @@ func TestValidateLaunchSpec(t *testing.T) { }, }, } - mockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) + s.MockAdminClient.OnGetWorkflowMatch(mock.Anything, mock.Anything).Return(wf, nil) lpSpec := &admin.LaunchPlanSpec{ WorkflowId: &core.Identifier{ Project: "projectValue", @@ -796,7 +815,7 @@ func TestValidateLaunchSpec(t *testing.T) { }, }, } - err := validateLaunchSpec(ctx, lpSpec, cmdCtx) + err := validateLaunchSpec(ctx, lpSpec, s.CmdCtx) assert.Nil(t, err) }) } diff --git a/cmd/root.go b/cmd/root.go index dba5b8f85a..ca08c94966 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,13 +3,8 @@ package cmd import ( "context" "fmt" - "os" - "github.com/flyteorg/flytectl/cmd/sandbox" - - f "github.com/flyteorg/flytectl/pkg/filesystemutils" - "github.com/flyteorg/flytectl/cmd/config" configuration "github.com/flyteorg/flytectl/cmd/configuration" cmdCore "github.com/flyteorg/flytectl/cmd/core" @@ -17,9 +12,11 @@ import ( "github.com/flyteorg/flytectl/cmd/delete" "github.com/flyteorg/flytectl/cmd/get" "github.com/flyteorg/flytectl/cmd/register" + "github.com/flyteorg/flytectl/cmd/sandbox" "github.com/flyteorg/flytectl/cmd/update" "github.com/flyteorg/flytectl/cmd/upgrade" "github.com/flyteorg/flytectl/cmd/version" + f "github.com/flyteorg/flytectl/pkg/filesystemutils" "github.com/flyteorg/flytectl/pkg/printer" stdConfig "github.com/flyteorg/flytestdlib/config" "github.com/flyteorg/flytestdlib/config/viper" diff --git a/cmd/sandbox/exec_test.go b/cmd/sandbox/exec_test.go index 4aa0e2148a..8cd7059c19 100644 --- a/cmd/sandbox/exec_test.go +++ b/cmd/sandbox/exec_test.go @@ -8,6 +8,10 @@ import ( "strings" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + + admin2 "github.com/flyteorg/flyteidl/clients/go/admin" + cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/stretchr/testify/assert" @@ -21,7 +25,8 @@ func TestSandboxClusterExec(t *testing.T) { mockDocker := &mocks.Docker{} mockOutStream := new(io.Writer) ctx := context.Background() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + mockClient := admin2.InitializeMockClientset() + cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) reader := bufio.NewReader(strings.NewReader("test")) mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{ @@ -46,10 +51,9 @@ func TestSandboxClusterExec(t *testing.T) { func TestSandboxClusterExecWithoutCmd(t *testing.T) { mockDocker := &mocks.Docker{} - mockOutStream := new(io.Writer) - ctx := context.Background() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) reader := bufio.NewReader(strings.NewReader("test")) + s := testutils.Setup() + ctx := s.Ctx mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{ { @@ -66,7 +70,7 @@ func TestSandboxClusterExecWithoutCmd(t *testing.T) { Reader: reader, }, fmt.Errorf("Test")) docker.Client = mockDocker - err := sandboxClusterExec(ctx, []string{}, cmdCtx) + err := sandboxClusterExec(ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) } diff --git a/cmd/sandbox/start.go b/cmd/sandbox/start.go index 979e666788..7c373bb2ed 100644 --- a/cmd/sandbox/start.go +++ b/cmd/sandbox/start.go @@ -201,7 +201,7 @@ func startSandbox(ctx context.Context, cli docker.Docker, reader io.Reader) (*bu fmt.Printf("%v Running Flyte %s release\n", emoji.Whale, version) } fmt.Printf("%v pulling docker image for release %s\n", emoji.Whale, sandboxImage) - if err := docker.PullDockerImage(ctx, cli, sandboxImage, sandboxConfig.DefaultConfig.ImagePullPolicy); err != nil { + if err := docker.PullDockerImage(ctx, cli, sandboxImage, sandboxConfig.DefaultConfig.ImagePullPolicy, sandboxConfig.DefaultConfig.ImagePullOptions); err != nil { return nil, err } diff --git a/cmd/sandbox/start_test.go b/cmd/sandbox/start_test.go index a70e136334..ae938ab1e2 100644 --- a/cmd/sandbox/start_test.go +++ b/cmd/sandbox/start_test.go @@ -10,6 +10,8 @@ import ( "strings" "testing" + "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/flyteorg/flytectl/pkg/githubutil" "github.com/flyteorg/flytectl/pkg/k8s" @@ -511,7 +513,7 @@ func TestStartSandboxFunc(t *testing.T) { t.Run("Successfully run sandbox cluster command", func(t *testing.T) { mockOutStream := new(io.Writer) ctx := context.Background() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + cmdCtx := cmdCore.NewCommandContext(admin.InitializeMockClientset(), *mockOutStream) mockDocker := &mocks.Docker{} errCh := make(chan error) client := testclient.NewSimpleClientset() @@ -561,7 +563,7 @@ func TestStartSandboxFunc(t *testing.T) { t.Run("Error in running sandbox cluster command", func(t *testing.T) { mockOutStream := new(io.Writer) ctx := context.Background() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + cmdCtx := cmdCore.NewCommandContext(admin.InitializeMockClientset(), *mockOutStream) mockDocker := &mocks.Docker{} errCh := make(chan error) bodyStatus := make(chan container.ContainerWaitOKBody) diff --git a/cmd/sandbox/status_test.go b/cmd/sandbox/status_test.go index fa5fbf424a..e38cfb0271 100644 --- a/cmd/sandbox/status_test.go +++ b/cmd/sandbox/status_test.go @@ -1,12 +1,11 @@ package sandbox import ( - "context" - "io" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/docker/docker/api/types" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/pkg/docker" "github.com/flyteorg/flytectl/pkg/docker/mocks" "github.com/stretchr/testify/assert" @@ -14,19 +13,16 @@ import ( func TestSandboxStatus(t *testing.T) { t.Run("Sandbox status with zero result", func(t *testing.T) { - ctx := context.Background() - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) mockDocker := &mocks.Docker{} - mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{}, nil) + s := testutils.Setup() + mockDocker.OnContainerList(s.Ctx, types.ContainerListOptions{All: true}).Return([]types.Container{}, nil) docker.Client = mockDocker - err := sandboxClusterStatus(ctx, []string{}, cmdCtx) + err := sandboxClusterStatus(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) }) t.Run("Sandbox status with running sandbox", func(t *testing.T) { - ctx := context.Background() - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + s := testutils.Setup() + ctx := s.Ctx mockDocker := &mocks.Docker{} mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{ { @@ -37,7 +33,7 @@ func TestSandboxStatus(t *testing.T) { }, }, nil) docker.Client = mockDocker - err := sandboxClusterStatus(ctx, []string{}, cmdCtx) + err := sandboxClusterStatus(ctx, []string{}, s.CmdCtx) assert.Nil(t, err) }) } diff --git a/cmd/sandbox/teardown_test.go b/cmd/sandbox/teardown_test.go index 224c905ae1..d95b12221d 100644 --- a/cmd/sandbox/teardown_test.go +++ b/cmd/sandbox/teardown_test.go @@ -3,14 +3,13 @@ package sandbox import ( "context" "fmt" - "io" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/pkg/configutil" "github.com/flyteorg/flytectl/pkg/util" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - "github.com/docker/docker/api/types" "github.com/flyteorg/flytectl/pkg/docker" "github.com/flyteorg/flytectl/pkg/docker/mocks" @@ -52,13 +51,12 @@ func TestTearDownFunc(t *testing.T) { func TestTearDownClusterFunc(t *testing.T) { _ = util.SetupFlyteDir() _ = util.WriteIntoFile([]byte("data"), configutil.FlytectlConfig) - mockOutStream := new(io.Writer) - ctx := context.Background() - cmdCtx := cmdCore.NewCommandContext(nil, *mockOutStream) + s := testutils.Setup() + ctx := s.Ctx mockDocker := &mocks.Docker{} mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return(containers, nil) mockDocker.OnContainerRemove(ctx, mock.Anything, types.ContainerRemoveOptions{Force: true}).Return(nil) docker.Client = mockDocker - err := teardownSandboxCluster(ctx, []string{}, cmdCtx) + err := teardownSandboxCluster(ctx, []string{}, s.CmdCtx) assert.Nil(t, err) } diff --git a/cmd/testutils/test_utils.go b/cmd/testutils/test_utils.go index c04be45a52..86577b1323 100644 --- a/cmd/testutils/test_utils.go +++ b/cmd/testutils/test_utils.go @@ -10,11 +10,15 @@ import ( "strings" "testing" + "github.com/flyteorg/flytectl/pkg/ext" + + "github.com/flyteorg/flyteidl/clients/go/admin/mocks" + + "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/flyteorg/flytectl/cmd/config" cmdCore "github.com/flyteorg/flytectl/cmd/core" extMocks "github.com/flyteorg/flytectl/pkg/ext/mocks" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) @@ -22,51 +26,83 @@ const projectValue = "dummyProject" const domainValue = "dummyDomain" const output = "json" -var ( - reader *os.File - writer *os.File - Err error - Ctx context.Context - MockClient *mocks.AdminServiceClient - FetcherExt *extMocks.AdminFetcherExtInterface - UpdaterExt *extMocks.AdminUpdaterExtInterface - DeleterExt *extMocks.AdminDeleterExtInterface - MockOutStream io.Writer - CmdCtx cmdCore.CommandContext - stdOut *os.File - stderr *os.File -) +type TestStruct struct { + Reader *os.File + Writer *os.File + Err error + Ctx context.Context + MockClient *admin.Clientset + MockAdminClient *mocks.AdminServiceClient + FetcherExt *extMocks.AdminFetcherExtInterface + UpdaterExt *extMocks.AdminUpdaterExtInterface + DeleterExt *extMocks.AdminDeleterExtInterface + MockOutStream io.Writer + CmdCtx cmdCore.CommandContext + StdOut *os.File + Stderr *os.File +} -func Setup() { - Ctx = context.Background() - reader, writer, Err = os.Pipe() - if Err != nil { - panic(Err) +func Setup() (s TestStruct) { + s.Ctx = context.Background() + s.Reader, s.Writer, s.Err = os.Pipe() + if s.Err != nil { + panic(s.Err) + } + s.StdOut = os.Stdout + s.Stderr = os.Stderr + os.Stdout = s.Writer + os.Stderr = s.Writer + log.SetOutput(s.Writer) + s.MockClient = admin.InitializeMockClientset() + s.FetcherExt = new(extMocks.AdminFetcherExtInterface) + s.UpdaterExt = new(extMocks.AdminUpdaterExtInterface) + s.DeleterExt = new(extMocks.AdminDeleterExtInterface) + s.FetcherExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.UpdaterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.DeleterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.MockAdminClient = s.MockClient.AdminClient().(*mocks.AdminServiceClient) + fetcher := &ext.AdminFetcherExtClient{ + AdminClient: s.MockAdminClient, } - stdOut = os.Stdout - stderr = os.Stderr - os.Stdout = writer - os.Stderr = writer - log.SetOutput(writer) - MockClient = new(mocks.AdminServiceClient) - FetcherExt = new(extMocks.AdminFetcherExtInterface) - UpdaterExt = new(extMocks.AdminUpdaterExtInterface) - DeleterExt = new(extMocks.AdminDeleterExtInterface) - FetcherExt.OnAdminServiceClient().Return(MockClient) - UpdaterExt.OnAdminServiceClient().Return(MockClient) - DeleterExt.OnAdminServiceClient().Return(MockClient) - MockOutStream = writer - CmdCtx = cmdCore.NewCommandContextWithExt(MockClient, FetcherExt, UpdaterExt, DeleterExt, MockOutStream) + s.MockOutStream = s.Writer + s.CmdCtx = cmdCore.NewCommandContextWithExt(s.MockClient, fetcher, s.UpdaterExt, s.DeleterExt, s.MockOutStream) config.GetConfig().Project = projectValue config.GetConfig().Domain = domainValue config.GetConfig().Output = output + + return s +} + +func SetupWithExt() (s TestStruct) { + s.Ctx = context.Background() + s.Reader, s.Writer, s.Err = os.Pipe() + if s.Err != nil { + panic(s.Err) + } + s.StdOut = os.Stdout + s.Stderr = os.Stderr + os.Stdout = s.Writer + os.Stderr = s.Writer + log.SetOutput(s.Writer) + s.MockClient = admin.InitializeMockClientset() + s.FetcherExt = new(extMocks.AdminFetcherExtInterface) + s.UpdaterExt = new(extMocks.AdminUpdaterExtInterface) + s.DeleterExt = new(extMocks.AdminDeleterExtInterface) + s.FetcherExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.UpdaterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.DeleterExt.OnAdminServiceClient().Return(s.MockClient.AdminClient()) + s.MockAdminClient = s.MockClient.AdminClient().(*mocks.AdminServiceClient) + s.MockOutStream = s.Writer + s.CmdCtx = cmdCore.NewCommandContextWithExt(s.MockClient, s.FetcherExt, s.UpdaterExt, s.DeleterExt, s.MockOutStream) + config.GetConfig().Project = projectValue + config.GetConfig().Domain = domainValue + config.GetConfig().Output = output + + return s } // TearDownAndVerify TODO: Change this to verify log lines from context -func TearDownAndVerify(t *testing.T, expectedLog string) { - writer.Close() - os.Stdout = stdOut - os.Stderr = stderr +func TearDownAndVerify(t *testing.T, reader io.Reader, expectedLog string) { var buf bytes.Buffer if _, err := io.Copy(&buf, reader); err == nil { assert.Equal(t, sanitizeString(expectedLog), sanitizeString(buf.String())) diff --git a/cmd/update/execution_test.go b/cmd/update/execution_test.go index 2f7e5423ba..35ab591212 100644 --- a/cmd/update/execution_test.go +++ b/cmd/update/execution_test.go @@ -12,60 +12,50 @@ import ( "github.com/stretchr/testify/mock" ) -func UpdateExecutionSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestExecutionUpdate(t *testing.T) { - testutils.Setup() - UpdateExecutionSetup() - args = []string{"execution1"} + s := testutils.Setup() + args := []string{"execution1"} // Activate execution.UConfig.Activate = true - mockClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(&admin.ExecutionUpdateResponse{}, nil) - assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) + s.MockAdminClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(&admin.ExecutionUpdateResponse{}, nil) + assert.Nil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) // Archive execution.UConfig.Activate = false execution.UConfig.Archive = true - assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) + assert.Nil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) // Reset execution.UConfig.Activate = false execution.UConfig.Archive = false // Dry run execution.UConfig.DryRun = true - assert.Nil(t, updateExecutionFunc(ctx, args, cmdCtx)) - mockClient.AssertNotCalled(t, "UpdateExecution", mock.Anything) + assert.Nil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) + s.MockAdminClient.AssertNotCalled(t, "UpdateExecution", mock.Anything) // Reset execution.UConfig.DryRun = false } func TestExecutionUpdateValidationFailure(t *testing.T) { - testutils.Setup() - UpdateExecutionSetup() - args = []string{"execution1"} + s := testutils.Setup() + args := []string{"execution1"} execution.UConfig.Activate = true execution.UConfig.Archive = true - assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) + assert.NotNil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) // Reset execution.UConfig.Activate = false execution.UConfig.Archive = false } func TestExecutionUpdateFail(t *testing.T) { - testutils.Setup() - UpdateExecutionSetup() - args = []string{"execution1"} - mockClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{"execution1"} + s.MockAdminClient.OnUpdateExecutionMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) } func TestExecutionUpdateInvalidArgs(t *testing.T) { - testutils.Setup() - UpdateExecutionSetup() - args = []string{} - assert.NotNil(t, updateExecutionFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{} + assert.NotNil(t, updateExecutionFunc(s.Ctx, args, s.CmdCtx)) } diff --git a/cmd/update/launch_plan_meta.go b/cmd/update/launch_plan_meta.go index c3efa3b254..9efa37533e 100644 --- a/cmd/update/launch_plan_meta.go +++ b/cmd/update/launch_plan_meta.go @@ -32,18 +32,20 @@ Usage ` ) -func updateLPMetaFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { - project := config.GetConfig().Project - domain := config.GetConfig().Domain - if len(args) != 1 { - return fmt.Errorf(clierrors.ErrLPNotPassed) +func getUpdateLPMetaFunc(namedEntityConfig *NamedEntityConfig) func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + return func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + project := config.GetConfig().Project + domain := config.GetConfig().Domain + if len(args) != 1 { + return fmt.Errorf(clierrors.ErrLPNotPassed) + } + name := args[0] + err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_LAUNCH_PLAN, cmdCtx) + if err != nil { + fmt.Printf(clierrors.ErrFailedLPUpdate, name, err) + return err + } + fmt.Printf("updated metadata successfully on %v", name) + return nil } - name := args[0] - err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_LAUNCH_PLAN, cmdCtx) - if err != nil { - fmt.Printf(clierrors.ErrFailedLPUpdate, name, err) - return err - } - fmt.Printf("updated metadata successfully on %v", name) - return nil } diff --git a/cmd/update/launch_plan_meta_test.go b/cmd/update/launch_plan_meta_test.go index 0427964fc6..f0119b9eb1 100644 --- a/cmd/update/launch_plan_meta_test.go +++ b/cmd/update/launch_plan_meta_test.go @@ -11,34 +11,25 @@ import ( "github.com/stretchr/testify/mock" ) -func UpdateLPMetaSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestLPMetaUpdate(t *testing.T) { - testutils.Setup() - UpdateLPMetaSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"task1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) - assert.Nil(t, updateLPMetaFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + namedEntityConfig := &NamedEntityConfig{} + args := []string{"task1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) + assert.Nil(t, getUpdateLPMetaFunc(namedEntityConfig)(s.Ctx, args, s.CmdCtx)) } func TestLPMetaUpdateFail(t *testing.T) { - testutils.Setup() - UpdateLPMetaSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"task1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + namedEntityConfig := &NamedEntityConfig{} + args := []string{"task1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, getUpdateTaskFunc(namedEntityConfig)(s.Ctx, args, s.CmdCtx)) } func TestLPMetaUpdateInvalidArgs(t *testing.T) { - testutils.Setup() - UpdateLPMetaSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{} - assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + namedEntityConfig := &NamedEntityConfig{} + args := []string{} + assert.NotNil(t, getUpdateTaskFunc(namedEntityConfig)(s.Ctx, args, s.CmdCtx)) } diff --git a/cmd/update/launch_plan_test.go b/cmd/update/launch_plan_test.go index 3ef074277b..0e5010c5cf 100644 --- a/cmd/update/launch_plan_test.go +++ b/cmd/update/launch_plan_test.go @@ -12,34 +12,25 @@ import ( "github.com/stretchr/testify/mock" ) -func UpdateLPSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestLPUpdate(t *testing.T) { - testutils.Setup() - UpdateLPSetup() + s := testutils.Setup() launchplan.UConfig = &launchplan.UpdateConfig{Version: "v1", Archive: true} - args = []string{"lp1"} - mockClient.OnUpdateLaunchPlanMatch(mock.Anything, mock.Anything).Return(&admin.LaunchPlanUpdateResponse{}, nil) - assert.Nil(t, updateLPFunc(ctx, args, cmdCtx)) + args := []string{"lp1"} + s.MockAdminClient.OnUpdateLaunchPlanMatch(mock.Anything, mock.Anything).Return(&admin.LaunchPlanUpdateResponse{}, nil) + assert.Nil(t, updateLPFunc(s.Ctx, args, s.CmdCtx)) } func TestLPUpdateFail(t *testing.T) { - testutils.Setup() - UpdateLPSetup() + s := testutils.Setup() launchplan.UConfig = &launchplan.UpdateConfig{Version: "v1", Archive: true} - args = []string{"task1"} - mockClient.OnUpdateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, updateLPFunc(ctx, args, cmdCtx)) + args := []string{"task1"} + s.MockAdminClient.OnUpdateLaunchPlanMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, updateLPFunc(s.Ctx, args, s.CmdCtx)) } func TestLPUpdateInvalidArgs(t *testing.T) { - testutils.Setup() - UpdateLPSetup() + s := testutils.Setup() launchplan.UConfig = &launchplan.UpdateConfig{Version: "v1", Archive: true, Activate: true} - args = []string{} - assert.NotNil(t, updateLPFunc(ctx, args, cmdCtx)) + args := []string{} + assert.NotNil(t, updateLPFunc(s.Ctx, args, s.CmdCtx)) } diff --git a/cmd/update/matchable_cluster_resource_attribute_test.go b/cmd/update/matchable_cluster_resource_attribute_test.go index d091125cdc..19c9257d69 100644 --- a/cmd/update/matchable_cluster_resource_attribute_test.go +++ b/cmd/update/matchable_cluster_resource_attribute_test.go @@ -5,90 +5,85 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config/subcommand/clusterresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updateClusterResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient clusterresourceattribute.DefaultUpdateConfig = &clusterresourceattribute.AttrUpdateConfig{} } func TestUpdateClusterResourceAttributes(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() - err = updateClusterResourceAttributesFunc(ctx, args, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for cluster resource attribute"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successfully updated project domain attribute", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateClusterResourceAttributesFunc(ctx, args, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed to update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateClusterResourceAttributesFunc(ctx, args, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successfully updated workflow attribute", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateClusterResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed to update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_cluster_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateClusterResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updateClusterResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updateClusterResourceAttributeSetup() clusterresourceattribute.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updateClusterResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateClusterResourceAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/matchable_execution_cluster_label_test.go b/cmd/update/matchable_execution_cluster_label_test.go index 0a84237cc0..500c082673 100644 --- a/cmd/update/matchable_execution_cluster_label_test.go +++ b/cmd/update/matchable_execution_cluster_label_test.go @@ -5,90 +5,85 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionclusterlabel" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updateExecutionClusterLabelSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionclusterlabel.DefaultUpdateConfig = &executionclusterlabel.AttrUpdateConfig{} } func TestExecutionClusterLabel(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() - err = updateExecutionClusterLabelFunc(ctx, args, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for execution cluster label"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateExecutionClusterLabelFunc(ctx, args, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateExecutionClusterLabelFunc(ctx, args, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateExecutionClusterLabelFunc(ctx, nil, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, nil, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_execution_cluster_label.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateExecutionClusterLabelFunc(ctx, nil, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updateExecutionClusterLabelFunc(ctx, nil, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updateExecutionClusterLabelSetup() executionclusterlabel.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updateExecutionClusterLabelFunc(ctx, nil, cmdCtx) + err := updateExecutionClusterLabelFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/matchable_execution_queue_attribute_test.go b/cmd/update/matchable_execution_queue_attribute_test.go index f0751b32da..4ba42eadc2 100644 --- a/cmd/update/matchable_execution_queue_attribute_test.go +++ b/cmd/update/matchable_execution_queue_attribute_test.go @@ -5,90 +5,85 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config/subcommand/executionqueueattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updateExecutionQueueAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient executionqueueattribute.DefaultUpdateConfig = &executionqueueattribute.AttrUpdateConfig{} } func TestExecutionQueueAttributes(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() - err = updateExecutionQueueAttributesFunc(ctx, args, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for execution queue attribute"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateExecutionQueueAttributesFunc(ctx, args, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateExecutionQueueAttributesFunc(ctx, args, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateExecutionQueueAttributesFunc(ctx, nil, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_execution_queue_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateExecutionQueueAttributesFunc(ctx, nil, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updateExecutionQueueAttributesFunc(ctx, nil, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updateExecutionQueueAttributeSetup() executionqueueattribute.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updateExecutionQueueAttributesFunc(ctx, nil, cmdCtx) + err := updateExecutionQueueAttributesFunc(s.Ctx, nil, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/matchable_plugin_override_test.go b/cmd/update/matchable_plugin_override_test.go index 8f59d1e1e4..644144a29c 100644 --- a/cmd/update/matchable_plugin_override_test.go +++ b/cmd/update/matchable_plugin_override_test.go @@ -5,90 +5,85 @@ import ( "testing" pluginoverride "github.com/flyteorg/flytectl/cmd/config/subcommand/plugin_override" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updatePluginOverrideSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient pluginoverride.DefaultUpdateConfig = &pluginoverride.AttrUpdateConfig{} } func TestPluginOverride(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() - err = updatePluginOverridesFunc(ctx, args, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for plugin override"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update project domain attribute", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_plugin_override.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updatePluginOverridesFunc(ctx, args, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed update project domain attribute", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_plugin_override.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updatePluginOverridesFunc(ctx, args, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update workflow attribute", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_plugin_override.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updatePluginOverridesFunc(ctx, nil, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed update workflow attribute", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_plugin_override.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updatePluginOverridesFunc(ctx, nil, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updatePluginOverridesFunc(ctx, nil, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updatePluginOverrideSetup() pluginoverride.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updatePluginOverridesFunc(ctx, nil, cmdCtx) + err := updatePluginOverridesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/matchable_task_resource_attribute_test.go b/cmd/update/matchable_task_resource_attribute_test.go index e91f6476d9..39f1cffc9b 100644 --- a/cmd/update/matchable_task_resource_attribute_test.go +++ b/cmd/update/matchable_task_resource_attribute_test.go @@ -5,90 +5,85 @@ import ( "testing" "github.com/flyteorg/flytectl/cmd/config/subcommand/taskresourceattribute" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updateTaskResourceAttributeSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient taskresourceattribute.DefaultUpdateConfig = &taskresourceattribute.AttrUpdateConfig{} } func TestUpdateTaskResourceAttributes(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() - err = updateTaskResourceAttributesFunc(ctx, args, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for task resource attribute"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_task_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateTaskResourceAttributesFunc(ctx, args, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_task_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateTaskResourceAttributesFunc(ctx, args, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_task_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateTaskResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_task_attribute.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateTaskResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updateTaskResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updateTaskResourceAttributeSetup() taskresourceattribute.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updateTaskResourceAttributesFunc(ctx, nil, cmdCtx) + err := updateTaskResourceAttributesFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/matchable_workflow_execution_config_test.go b/cmd/update/matchable_workflow_execution_config_test.go index 8afcfda1bf..9b9ba63001 100644 --- a/cmd/update/matchable_workflow_execution_config_test.go +++ b/cmd/update/matchable_workflow_execution_config_test.go @@ -6,90 +6,85 @@ import ( "github.com/flyteorg/flytectl/cmd/config/subcommand/workflowexecutionconfig" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) func updateWorkflowExecutionConfigSetup() { - ctx = u.Ctx - cmdCtx = u.CmdCtx - mockClient = u.MockClient workflowexecutionconfig.DefaultUpdateConfig = &workflowexecutionconfig.AttrUpdateConfig{} } func TestWorkflowExecutionConfigs(t *testing.T) { t.Run("no input file for update", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() - err = updateWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("attrFile is mandatory while calling update for workflow execution config"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development`) }) t.Run("failed update project domain attribute", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = "testdata/valid_project_domain_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateProjectDomainAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateWorkflowExecutionConfigFunc(ctx, args, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("successful update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) - err = updateWorkflowExecutionConfigFunc(ctx, nil, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - tearDownAndVerify(t, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) + tearDownAndVerify(t, s.Writer, `Updated attributes from flytectldemo project and domain development and workflow core.control_flow.run_merge_sort.merge_sort`) }) t.Run("failed update workflow attribute", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = "testdata/valid_workflow_workflow_execution_config.yaml" // No args implying project domain attribute deletion - u.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, + s.UpdaterExt.OnUpdateWorkflowAttributesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(fmt.Errorf("failed to update attributes")) - err = updateWorkflowExecutionConfigFunc(ctx, nil, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("failed to update attributes"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("non existent file", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = testDataNonExistentFile - err = updateWorkflowExecutionConfigFunc(ctx, nil, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("unable to read from testdata/non-existent-file yaml file"), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) t.Run("invalid update file", func(t *testing.T) { - setup() + s := setup() updateWorkflowExecutionConfigSetup() workflowexecutionconfig.DefaultUpdateConfig.AttrFile = testDataInvalidAttrFile - err = updateWorkflowExecutionConfigFunc(ctx, nil, cmdCtx) + err := updateWorkflowExecutionConfigFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf("error unmarshaling JSON: while decoding JSON: json: unknown field \"InvalidDomain\""), err) - tearDownAndVerify(t, ``) + tearDownAndVerify(t, s.Writer, ``) }) } diff --git a/cmd/update/named_entity.go b/cmd/update/named_entity.go index 25d537f380..c7644f4907 100644 --- a/cmd/update/named_entity.go +++ b/cmd/update/named_entity.go @@ -24,9 +24,9 @@ type NamedEntityConfig struct { DryRun bool `json:"dryRun" pflag:",execute command without making any modifications."` } -func (n NamedEntityConfig) UpdateNamedEntity(ctx context.Context, name string, project string, domain string, rsType core.ResourceType, cmdCtx cmdCore.CommandContext) error { - archiveProject := n.Archive - activateProject := n.Activate +func (cfg NamedEntityConfig) UpdateNamedEntity(ctx context.Context, name string, project string, domain string, rsType core.ResourceType, cmdCtx cmdCore.CommandContext) error { + archiveProject := cfg.Archive + activateProject := cfg.Activate if activateProject == archiveProject && activateProject { return fmt.Errorf(clierrors.ErrInvalidStateUpdate) } @@ -36,7 +36,7 @@ func (n NamedEntityConfig) UpdateNamedEntity(ctx context.Context, name string, p } else if archiveProject { nameEntityState = admin.NamedEntityState_NAMED_ENTITY_ARCHIVED } - if namedEntityConfig.DryRun { + if cfg.DryRun { logger.Infof(ctx, "skipping UpdateNamedEntity request (dryRun)") } else { _, err := cmdCtx.AdminClient().UpdateNamedEntity(ctx, &admin.NamedEntityUpdateRequest{ @@ -47,7 +47,7 @@ func (n NamedEntityConfig) UpdateNamedEntity(ctx context.Context, name string, p Name: name, }, Metadata: &admin.NamedEntityMetadata{ - Description: n.Description, + Description: cfg.Description, State: nameEntityState, }, }) diff --git a/cmd/update/named_entity_test.go b/cmd/update/named_entity_test.go index 9c322f1840..4e0086d7c6 100644 --- a/cmd/update/named_entity_test.go +++ b/cmd/update/named_entity_test.go @@ -12,37 +12,28 @@ import ( "github.com/stretchr/testify/assert" ) -func NamedEntitySetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestNamedEntity(t *testing.T) { - testutils.Setup() - NamedEntitySetup() - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) + s := testutils.Setup() + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) namedEntityConfig = &NamedEntityConfig{Archive: false, Activate: true, Description: "named entity description"} - assert.Nil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", - core.ResourceType_WORKFLOW, cmdCtx)) + assert.Nil(t, namedEntityConfig.UpdateNamedEntity(s.Ctx, "namedEntity", "project", "domain", + core.ResourceType_WORKFLOW, s.CmdCtx)) namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: false, Description: "named entity description"} - assert.Nil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", - core.ResourceType_WORKFLOW, cmdCtx)) + assert.Nil(t, namedEntityConfig.UpdateNamedEntity(s.Ctx, "namedEntity", "project", "domain", + core.ResourceType_WORKFLOW, s.CmdCtx)) } func TestNamedEntityValidationFailure(t *testing.T) { - testutils.Setup() - NamedEntitySetup() - namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} - assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", - core.ResourceType_WORKFLOW, cmdCtx)) + s := testutils.Setup() + namedEntityConfig := &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} + assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(s.Ctx, "namedEntity", "project", "domain", + core.ResourceType_WORKFLOW, s.CmdCtx)) } func TestNamedEntityFailure(t *testing.T) { - testutils.Setup() - NamedEntitySetup() - namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", - core.ResourceType_WORKFLOW, cmdCtx)) + s := testutils.Setup() + namedEntityConfig := &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(s.Ctx, "namedEntity", "project", "domain", + core.ResourceType_WORKFLOW, s.CmdCtx)) } diff --git a/cmd/update/project_test.go b/cmd/update/project_test.go index db1f52c7cd..d33ce6e374 100644 --- a/cmd/update/project_test.go +++ b/cmd/update/project_test.go @@ -9,7 +9,6 @@ import ( "github.com/flyteorg/flytectl/clierrors" "github.com/flyteorg/flytectl/cmd/config" - u "github.com/flyteorg/flytectl/cmd/testutils" "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" "github.com/stretchr/testify/assert" @@ -18,13 +17,10 @@ import ( const projectValue = "dummyProject" var ( - args []string projectUpdateRequest *admin.Project ) func updateProjectSetup() { - mockClient = u.MockClient - cmdCtx = u.CmdCtx projectUpdateRequest = &admin.Project{ Id: projectValue, State: admin.Project_ACTIVE, @@ -37,7 +33,7 @@ func modifyProjectFlags(archiveProject *bool, newArchiveVal bool, activateProjec } func TestActivateProjectFunc(t *testing.T) { - setup() + s := setup() updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue @@ -50,15 +46,15 @@ func TestActivateProjectFunc(t *testing.T) { }, State: admin.Project_ACTIVE, } - mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, nil) - err = updateProjectsFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnUpdateProjectMatch(s.Ctx, projectUpdateRequest).Return(nil, nil) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "UpdateProject", ctx, projectUpdateRequest) - tearDownAndVerify(t, "Project dummyProject updated\n") + s.MockAdminClient.AssertCalled(t, "UpdateProject", s.Ctx, projectUpdateRequest) + tearDownAndVerify(t, s.Writer, "Project dummyProject updated\n") } func TestActivateProjectFuncWithError(t *testing.T) { - setup() + s := setup() updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue @@ -71,15 +67,15 @@ func TestActivateProjectFuncWithError(t *testing.T) { }, State: admin.Project_ACTIVE, } - mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, errors.New("Error Updating Project")) - err = updateProjectsFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnUpdateProjectMatch(s.Ctx, projectUpdateRequest).Return(nil, errors.New("Error Updating Project")) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - mockClient.AssertCalled(t, "UpdateProject", ctx, projectUpdateRequest) - tearDownAndVerify(t, "Project dummyProject failed to update due to Error Updating Project\n") + s.MockAdminClient.AssertCalled(t, "UpdateProject", s.Ctx, projectUpdateRequest) + tearDownAndVerify(t, s.Writer, "Project dummyProject failed to update due to Error Updating Project\n") } func TestArchiveProjectFunc(t *testing.T) { - setup() + s := setup() updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig = &project.ConfigProject{} @@ -93,15 +89,15 @@ func TestArchiveProjectFunc(t *testing.T) { }, State: admin.Project_ARCHIVED, } - mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, nil) - err = updateProjectsFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnUpdateProjectMatch(s.Ctx, projectUpdateRequest).Return(nil, nil) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "UpdateProject", ctx, projectUpdateRequest) - tearDownAndVerify(t, "Project dummyProject updated\n") + s.MockAdminClient.AssertCalled(t, "UpdateProject", s.Ctx, projectUpdateRequest) + tearDownAndVerify(t, s.Writer, "Project dummyProject updated\n") } func TestArchiveProjectFuncWithError(t *testing.T) { - setup() + s := setup() updateProjectSetup() project.DefaultProjectConfig.Name = projectValue project.DefaultProjectConfig.Labels = map[string]string{} @@ -114,32 +110,32 @@ func TestArchiveProjectFuncWithError(t *testing.T) { }, State: admin.Project_ARCHIVED, } - mockClient.OnUpdateProjectMatch(ctx, projectUpdateRequest).Return(nil, errors.New("Error Updating Project")) - err = updateProjectsFunc(ctx, args, cmdCtx) + s.MockAdminClient.OnUpdateProjectMatch(s.Ctx, projectUpdateRequest).Return(nil, errors.New("Error Updating Project")) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) - mockClient.AssertCalled(t, "UpdateProject", ctx, projectUpdateRequest) - tearDownAndVerify(t, "Project dummyProject failed to update"+ + s.MockAdminClient.AssertCalled(t, "UpdateProject", s.Ctx, projectUpdateRequest) + tearDownAndVerify(t, s.Writer, "Project dummyProject failed to update"+ " due to Error Updating Project\n") } func TestEmptyProjectInput(t *testing.T) { - setup() + s := setup() updateProjectSetup() config.GetConfig().Project = "" modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true) - err = updateProjectsFunc(ctx, args, cmdCtx) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf(clierrors.ErrProjectNotPassed), err) } func TestInvalidInput(t *testing.T) { - setup() + s := setup() updateProjectSetup() config.GetConfig().Project = projectValue project.DefaultProjectConfig.Name = projectValue modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), true) - err = updateProjectsFunc(ctx, args, cmdCtx) + err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx) assert.NotNil(t, err) assert.Equal(t, fmt.Errorf(clierrors.ErrInvalidStateUpdate), err) - tearDownAndVerify(t, "") + tearDownAndVerify(t, s.Writer, "") } diff --git a/cmd/update/task_meta.go b/cmd/update/task_meta.go index 80f2b6c7b0..40d4ee4410 100644 --- a/cmd/update/task_meta.go +++ b/cmd/update/task_meta.go @@ -32,18 +32,22 @@ Usage ` ) -func updateTaskFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { - project := config.GetConfig().Project - domain := config.GetConfig().Domain - if len(args) != 1 { - return fmt.Errorf(clierrors.ErrTaskNotPassed) +func getUpdateTaskFunc(namedEntityConfig *NamedEntityConfig) func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + return func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + project := config.GetConfig().Project + domain := config.GetConfig().Domain + if len(args) != 1 { + return fmt.Errorf(clierrors.ErrTaskNotPassed) + } + + name := args[0] + err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_TASK, cmdCtx) + if err != nil { + fmt.Printf(clierrors.ErrFailedTaskUpdate, name, err) + return err + } + + fmt.Printf("updated metadata successfully on %v", name) + return nil } - name := args[0] - err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_TASK, cmdCtx) - if err != nil { - fmt.Printf(clierrors.ErrFailedTaskUpdate, name, err) - return err - } - fmt.Printf("updated metadata successfully on %v", name) - return nil } diff --git a/cmd/update/task_meta_test.go b/cmd/update/task_meta_test.go index 250f7f9fde..e121cbe8bd 100644 --- a/cmd/update/task_meta_test.go +++ b/cmd/update/task_meta_test.go @@ -11,34 +11,21 @@ import ( "github.com/stretchr/testify/mock" ) -func UpdateTaskSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestTaskUpdate(t *testing.T) { - testutils.Setup() - UpdateTaskSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"task1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) - assert.Nil(t, updateTaskFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{"task1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) + assert.Nil(t, getUpdateTaskFunc(&NamedEntityConfig{})(s.Ctx, args, s.CmdCtx)) } func TestTaskUpdateFail(t *testing.T) { - testutils.Setup() - UpdateWorkflowSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"workflow1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{"workflow1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, getUpdateTaskFunc(&NamedEntityConfig{})(s.Ctx, args, s.CmdCtx)) } func TestTaskUpdateInvalidArgs(t *testing.T) { - testutils.Setup() - UpdateWorkflowSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{} - assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + assert.NotNil(t, getUpdateTaskFunc(&NamedEntityConfig{})(s.Ctx, []string{}, s.CmdCtx)) } diff --git a/cmd/update/update.go b/cmd/update/update.go index 7f48226b0c..23c69ac608 100644 --- a/cmd/update/update.go +++ b/cmd/update/update.go @@ -39,15 +39,15 @@ func CreateUpdateCommand() *cobra.Command { updateResourcesFuncs := map[string]cmdCore.CommandEntry{ "launchplan": {CmdFunc: updateLPFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: launchplan.UConfig, Short: updateLPShort, Long: updateLPLong}, - "launchplan-meta": {CmdFunc: updateLPMetaFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, + "launchplan-meta": {CmdFunc: getUpdateLPMetaFunc(namedEntityConfig), Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, Short: updateLPMetaShort, Long: updateLPMetaLong}, "project": {CmdFunc: updateProjectsFunc, Aliases: []string{}, ProjectDomainNotRequired: true, PFlagProvider: project.DefaultProjectConfig, Short: projectShort, Long: projectLong}, "execution": {CmdFunc: updateExecutionFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: execution.UConfig, Short: updateExecutionShort, Long: updateExecutionLong}, - "task-meta": {CmdFunc: updateTaskFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, + "task-meta": {CmdFunc: getUpdateTaskFunc(namedEntityConfig), Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, Short: updateTaskShort, Long: updateTaskLong}, - "workflow-meta": {CmdFunc: updateWorkflowFunc, Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, + "workflow-meta": {CmdFunc: getUpdateWorkflowFunc(namedEntityConfig), Aliases: []string{}, ProjectDomainNotRequired: false, PFlagProvider: namedEntityConfig, Short: updateWorkflowShort, Long: updateWorkflowLong}, "task-resource-attribute": {CmdFunc: updateTaskResourceAttributesFunc, Aliases: []string{}, PFlagProvider: taskresourceattribute.DefaultUpdateConfig, Short: taskResourceAttributesShort, Long: taskResourceAttributesLong, ProjectDomainNotRequired: true}, diff --git a/cmd/update/update_test.go b/cmd/update/update_test.go index b289b0a4cd..b17bae11e8 100644 --- a/cmd/update/update_test.go +++ b/cmd/update/update_test.go @@ -1,24 +1,13 @@ package update import ( - "context" "sort" "testing" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" - "github.com/stretchr/testify/assert" ) -var ( - err error - ctx context.Context - mockClient *mocks.AdminServiceClient - cmdCtx cmdCore.CommandContext -) - const ( testDataNonExistentFile = "testdata/non-existent-file" testDataInvalidAttrFile = "testdata/invalid_attribute.yaml" diff --git a/cmd/update/workflow_meta.go b/cmd/update/workflow_meta.go index f84c1e87e4..5db98b44de 100644 --- a/cmd/update/workflow_meta.go +++ b/cmd/update/workflow_meta.go @@ -32,18 +32,20 @@ Usage ` ) -func updateWorkflowFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { - project := config.GetConfig().Project - domain := config.GetConfig().Domain - if len(args) != 1 { - return fmt.Errorf(clierrors.ErrWorkflowNotPassed) +func getUpdateWorkflowFunc(namedEntityConfig *NamedEntityConfig) func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + return func(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { + project := config.GetConfig().Project + domain := config.GetConfig().Domain + if len(args) != 1 { + return fmt.Errorf(clierrors.ErrWorkflowNotPassed) + } + name := args[0] + err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_WORKFLOW, cmdCtx) + if err != nil { + fmt.Printf(clierrors.ErrFailedWorkflowUpdate, name, err) + return err + } + fmt.Printf("updated metadata successfully on %v", name) + return nil } - name := args[0] - err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_WORKFLOW, cmdCtx) - if err != nil { - fmt.Printf(clierrors.ErrFailedWorkflowUpdate, name, err) - return err - } - fmt.Printf("updated metadata successfully on %v", name) - return nil } diff --git a/cmd/update/workflow_meta_test.go b/cmd/update/workflow_meta_test.go index d6b5ba06ad..7c7a1fc78e 100644 --- a/cmd/update/workflow_meta_test.go +++ b/cmd/update/workflow_meta_test.go @@ -11,34 +11,21 @@ import ( "github.com/stretchr/testify/mock" ) -func UpdateWorkflowSetup() { - ctx = testutils.Ctx - cmdCtx = testutils.CmdCtx - mockClient = testutils.MockClient -} - func TestWorkflowUpdate(t *testing.T) { - testutils.Setup() - UpdateWorkflowSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"workflow1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) - assert.Nil(t, updateWorkflowFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{"workflow1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) + assert.Nil(t, getUpdateWorkflowFunc(&NamedEntityConfig{})(s.Ctx, args, s.CmdCtx)) } func TestWorkflowUpdateFail(t *testing.T) { - testutils.Setup() - UpdateWorkflowSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{"workflow1"} - mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) - assert.NotNil(t, updateWorkflowFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + args := []string{"workflow1"} + s.MockAdminClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) + assert.NotNil(t, getUpdateWorkflowFunc(&NamedEntityConfig{})(s.Ctx, args, s.CmdCtx)) } func TestWorkflowUpdateInvalidArgs(t *testing.T) { - testutils.Setup() - UpdateWorkflowSetup() - namedEntityConfig = &NamedEntityConfig{} - args = []string{} - assert.NotNil(t, updateWorkflowFunc(ctx, args, cmdCtx)) + s := testutils.Setup() + assert.NotNil(t, getUpdateWorkflowFunc(&NamedEntityConfig{})(s.Ctx, []string{}, s.CmdCtx)) } diff --git a/cmd/upgrade/upgrade_test.go b/cmd/upgrade/upgrade_test.go index 473621bb9e..5d4ac283ef 100644 --- a/cmd/upgrade/upgrade_test.go +++ b/cmd/upgrade/upgrade_test.go @@ -1,20 +1,18 @@ package upgrade import ( - "io" "sort" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + "github.com/flyteorg/flytectl/pkg/githubutil" "github.com/flyteorg/flytectl/pkg/util" "github.com/flyteorg/flytectl/pkg/platformutil" - "github.com/flyteorg/flyteidl/clients/go/admin/mocks" stdlibversion "github.com/flyteorg/flytestdlib/version" - "context" - cmdCore "github.com/flyteorg/flytectl/cmd/core" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" @@ -111,16 +109,12 @@ func TestSelfUpgrade(t *testing.T) { githubutil.FlytectlReleaseConfig.OverrideExecutable = tempExt goos = platformutil.Linux t.Run("Successful upgrade", func(t *testing.T) { - ctx := context.Background() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := testutils.Setup() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = version - assert.Nil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.Nil(t, selfUpgrade(s.Ctx, []string{}, s.CmdCtx)) }) } @@ -129,16 +123,12 @@ func TestSelfUpgradeError(t *testing.T) { githubutil.FlytectlReleaseConfig.OverrideExecutable = tempExt goos = platformutil.Linux t.Run("Successful upgrade", func(t *testing.T) { - ctx := context.Background() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := testutils.Setup() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = "v" - assert.NotNil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.NotNil(t, selfUpgrade(s.Ctx, []string{}, s.CmdCtx)) }) } @@ -148,53 +138,41 @@ func TestSelfUpgradeRollback(t *testing.T) { githubutil.FlytectlReleaseConfig.OverrideExecutable = tempExt goos = platformutil.Linux t.Run("Successful rollback", func(t *testing.T) { - ctx := context.Background() + s := testutils.Setup() var args = []string{rollBackSubCommand} - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = version - assert.Nil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx)) }) t.Run("Successful rollback failed", func(t *testing.T) { - ctx := context.Background() + s := testutils.Setup() var args = []string{rollBackSubCommand} - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = "v100.0.0" - assert.NotNil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.NotNil(t, selfUpgrade(s.Ctx, args, s.CmdCtx)) }) t.Run("Successful rollback for windows", func(t *testing.T) { - ctx := context.Background() + s := testutils.Setup() var args = []string{rollBackSubCommand} - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = version goos = platformutil.Windows - assert.Nil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx)) }) t.Run("Successful rollback for windows", func(t *testing.T) { - ctx := context.Background() + s := testutils.Setup() var args = []string{rollBackSubCommand} - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = version githubutil.FlytectlReleaseConfig.OverrideExecutable = "/" - assert.Nil(t, selfUpgrade(ctx, args, cmdCtx)) + assert.Nil(t, selfUpgrade(s.Ctx, args, s.CmdCtx)) }) } diff --git a/cmd/version/version_test.go b/cmd/version/version_test.go index 0be22c97c2..991d50765e 100644 --- a/cmd/version/version_test.go +++ b/cmd/version/version_test.go @@ -8,6 +8,10 @@ import ( "sort" "testing" + "github.com/flyteorg/flytectl/cmd/testutils" + + admin2 "github.com/flyteorg/flyteidl/clients/go/admin" + "github.com/spf13/cobra" cmdCore "github.com/flyteorg/flytectl/cmd/core" @@ -53,47 +57,38 @@ func TestVersionCommand(t *testing.T) { func TestVersionCommandFunc(t *testing.T) { ctx := context.Background() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := testutils.Setup() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = testVersion - mockClient.OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, nil) - err := getVersion(ctx, args, cmdCtx) + s.MockClient.AdminClient().(*mocks.AdminServiceClient).OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, nil) + err := getVersion(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetVersion", ctx, versionRequest) + s.MockClient.AdminClient().(*mocks.AdminServiceClient).AssertCalled(t, "GetVersion", ctx, versionRequest) } func TestVersionCommandFuncError(t *testing.T) { ctx := context.Background() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := testutils.Setup() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = "v" - mockClient.OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, nil) - err := getVersion(ctx, args, cmdCtx) + s.MockClient.AdminClient().(*mocks.AdminServiceClient).OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, nil) + err := getVersion(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetVersion", ctx, versionRequest) + s.MockClient.AdminClient().(*mocks.AdminServiceClient).AssertCalled(t, "GetVersion", ctx, versionRequest) } func TestVersionCommandFuncErr(t *testing.T) { ctx := context.Background() - var args []string - mockClient := new(mocks.AdminServiceClient) - mockOutStream := new(io.Writer) - cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) + s := testutils.Setup() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = testVersion - mockClient.OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, errors.New("error")) - err := getVersion(ctx, args, cmdCtx) + s.MockAdminClient.OnGetVersionMatch(ctx, versionRequest).Return(versionResponse, errors.New("error")) + err := getVersion(s.Ctx, []string{}, s.CmdCtx) assert.Nil(t, err) - mockClient.AssertCalled(t, "GetVersion", ctx, versionRequest) + s.MockAdminClient.AssertCalled(t, "GetVersion", ctx, versionRequest) } func TestVersionUtilFunc(t *testing.T) { @@ -102,19 +97,21 @@ func TestVersionUtilFunc(t *testing.T) { stdlibversion.Version = testVersion t.Run("Error in getting control plan version", func(t *testing.T) { ctx := context.Background() - mockClient := new(mocks.AdminServiceClient) + mockClient := admin2.InitializeMockClientset() + adminClient := mockClient.AdminClient().(*mocks.AdminServiceClient) mockOutStream := new(io.Writer) cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) - mockClient.OnGetVersionMatch(ctx, &admin.GetVersionRequest{}).Return(nil, fmt.Errorf("error")) + adminClient.OnGetVersionMatch(ctx, &admin.GetVersionRequest{}).Return(nil, fmt.Errorf("error")) err := getControlPlaneVersion(ctx, cmdCtx) assert.NotNil(t, err) }) t.Run("Failed in getting version", func(t *testing.T) { ctx := context.Background() - mockClient := new(mocks.AdminServiceClient) + mockClient := admin2.InitializeMockClientset() + adminClient := mockClient.AdminClient().(*mocks.AdminServiceClient) mockOutStream := new(io.Writer) cmdCtx := cmdCore.NewCommandContext(mockClient, *mockOutStream) - mockClient.OnGetVersionMatch(ctx, &admin.GetVersionRequest{}).Return(nil, fmt.Errorf("error")) + adminClient.OnGetVersionMatch(ctx, &admin.GetVersionRequest{}).Return(nil, fmt.Errorf("error")) err := getVersion(ctx, []string{}, cmdCtx) assert.Nil(t, err) }) diff --git a/go.mod b/go.mod index 695533b176..dcadd78d31 100644 --- a/go.mod +++ b/go.mod @@ -9,12 +9,13 @@ require ( github.com/docker/docker v20.10.7+incompatible github.com/docker/go-connections v0.4.0 github.com/enescakir/emoji v1.0.0 - github.com/flyteorg/flyteidl v0.24.6 - github.com/flyteorg/flytestdlib v0.4.14 + github.com/flyteorg/flyteidl v0.24.10 + github.com/flyteorg/flytestdlib v0.4.16 github.com/ghodss/yaml v1.0.0 github.com/go-ozzo/ozzo-validation/v4 v4.3.0 github.com/golang/protobuf v1.5.0 github.com/google/go-github/v42 v42.0.0 + github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.2.0 github.com/hashicorp/go-version v1.3.0 github.com/kataras/tablewriter v0.0.0-20180708051242-e063d29b7c23 @@ -44,10 +45,15 @@ require ( sigs.k8s.io/yaml v1.2.0 ) +require golang.org/x/text v0.3.7 + require ( cloud.google.com/go v0.75.0 // indirect cloud.google.com/go/storage v1.12.0 // indirect - github.com/Azure/azure-sdk-for-go v51.0.0+incompatible // indirect + github.com/Azure/azure-sdk-for-go v62.3.0+incompatible // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 // indirect + github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest/autorest v0.11.17 // indirect github.com/Azure/go-autorest/autorest/adal v0.9.10 // indirect @@ -71,19 +77,19 @@ require ( github.com/dustin/go-humanize v1.0.0 // indirect github.com/evanphx/json-patch v4.9.0+incompatible // indirect github.com/fatih/color v1.10.0 // indirect + github.com/flyteorg/stow v0.3.1 // indirect github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/go-logr/logr v0.4.0 // indirect github.com/godbus/dbus/v5 v5.0.4 // indirect + github.com/gofrs/uuid v4.2.0+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/google/go-cmp v0.5.6 // indirect - github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/googleapis/gax-go/v2 v2.0.5 // indirect github.com/googleapis/gnostic v0.4.1 // indirect github.com/gorilla/mux v1.8.0 // indirect - github.com/graymeta/stow v0.2.7 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect @@ -116,7 +122,6 @@ require ( github.com/prometheus/procfs v0.6.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect - github.com/satori/go.uuid v1.2.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/spf13/afero v1.5.1 // indirect github.com/spf13/cast v1.3.1 // indirect @@ -125,15 +130,14 @@ require ( github.com/stretchr/objx v0.3.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect go.opencensus.io v0.22.6 // indirect - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5 // indirect - golang.org/x/mod v0.4.1 // indirect - golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect - golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect + golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect + golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect + golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect - golang.org/x/text v0.3.5 // indirect golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect - golang.org/x/tools v0.1.0 // indirect + golang.org/x/tools v0.1.10 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/api v0.38.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/go.sum b/go.sum index 5402048521..357cec6285 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,15 @@ cloud.google.com/go/storage v1.12.0/go.mod h1:fFLk2dp2oAhDz8QFKwqrjdJvxSp/W2g7ni dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v32.5.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v51.0.0+incompatible h1:p7blnyJSjJqf5jflHbSGhIhEpXIgIFmYZNg5uwqweso= github.com/Azure/azure-sdk-for-go v51.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go v62.3.0+incompatible h1:Ctfsn9UoA/BB4HMYQlbPPgNXdX0tZ4tmb85+KFb2+RE= +github.com/Azure/azure-sdk-for-go v62.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1 h1:qoVeMsc9/fh/yhxVaA0obYjVH/oI/ihrOoMwsLS9KSA= +github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3 h1:E+m3SkZCN0Bf5q7YdTs5lSm2CYY3CK4spn5OmUIiQtk= +github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0 h1:Px2UA+2RvSSvv+RvJNuUB6n7rs5Wsel4dXLe90Um2n4= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v10.8.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= @@ -310,8 +317,9 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 github.com/disiqueira/gotree v1.0.0 h1:en5wk87n7/Jyk6gVME3cx3xN9KmUCstJ1IjHr4Se4To= github.com/disiqueira/gotree v1.0.0/go.mod h1:7CwL+VWsWAU95DovkdRZAtA7YbtHwGk+tLV/kNi8niU= github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= -github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= +github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI= +github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= github.com/docker/distribution v0.0.0-20190905152932-14b96e55d84c/go.mod h1:0+TTO4EOBfRPhZXAeF1Vu+W3hHZ8eLp8PgKVZlcvtFY= github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= @@ -356,11 +364,13 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/flyteorg/flyteidl v0.24.6 h1:n2796X9Sw7mNDtXWwsJr84DLQpz8Cptvb7LptfJLxag= -github.com/flyteorg/flyteidl v0.24.6/go.mod h1:576W2ViEyjTpT+kEVHAGbrTP3HARNUZ/eCwrNPmdx9U= +github.com/flyteorg/flyteidl v0.24.10 h1:fCYpfp5fxKbhRMSkP0Hdw5lOPBTItLU1A3WA1Lc7sEU= +github.com/flyteorg/flyteidl v0.24.10/go.mod h1:vHSugApgS3hRITIafzQDU8DZD/W8wFRfFcgaFU35Dww= github.com/flyteorg/flytestdlib v0.3.13/go.mod h1:Tz8JCECAbX6VWGwFT6cmEQ+RJpZ/6L9pswu3fzWs220= -github.com/flyteorg/flytestdlib v0.4.14 h1:qpPwvJ+DqM1fI/y5uPKAP8p8VONz8oRp9Fz0jFl/5aI= -github.com/flyteorg/flytestdlib v0.4.14/go.mod h1:fv1ar34LJLMTaf0tbfetisLykUlARi7rP+NQTUn6QQs= +github.com/flyteorg/flytestdlib v0.4.16 h1:r4dCPUOqoE9xCAhOw9KDB7O6cBoCxyEtepIWYcj93H0= +github.com/flyteorg/flytestdlib v0.4.16/go.mod h1:WA5Y4hrcgD0ybGOKJVOQ4sP8q7NLRV+S5SWOlH0axgM= +github.com/flyteorg/stow v0.3.1 h1:cBMbWl03Gsy5KoA5mutUYTuYpqtT7Pb8+ANGCLnmFEs= +github.com/flyteorg/stow v0.3.1/go.mod h1:HBld7ud0i4khMHwJjkO8v+NSP7ddKa/ruhf4I8fliaA= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= @@ -408,6 +418,8 @@ github.com/godbus/dbus v0.0.0-20190422162347-ade71ed3457e/go.mod h1:bBOAhwG1umN6 github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0= +github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= github.com/gogo/googleapis v1.2.0/go.mod h1:Njal3psf3qN6dwBtQfUmBZh2ybovJ0tlu3o/AC7HYjU= github.com/gogo/googleapis v1.4.0/go.mod h1:5YRNX2z1oM5gXdAkurHa942MDgEJyk02w4OecKY87+c= @@ -514,7 +526,6 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/graymeta/stow v0.2.7 h1:b31cB1Ylw/388sYSZxnmpjT2QxC21AaQ8fRnUtE13b4= github.com/graymeta/stow v0.2.7/go.mod h1:JAs139Zr29qfsecy7b+h9DRsWXbFbsd7LCrbCDYI84k= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= @@ -611,6 +622,7 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= @@ -700,7 +712,6 @@ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ github.com/ncw/swift v1.0.49/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks= github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= @@ -840,7 +851,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= @@ -940,6 +950,7 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yvasiyarov/go-metrics v0.0.0-20140926110328-57bccd1ccd43/go.mod h1:aX5oPXxHm3bOH+xeAttToC8pqch2ScQN/JoXYupl6xs= github.com/yvasiyarov/gorelic v0.0.0-20141212073537-a9bba5b9ab50/go.mod h1:NUSPSUX/bi6SeDMUh6brw0nXpxHnc96TguQh0+r/ssA= github.com/yvasiyarov/newrelic_platform_go v0.0.0-20140908184405-b21fdbd4370f/go.mod h1:GlGEuHIJweS1mbCqG+7vt2nvWLzLLnRHbXz5JKd/Qbg= @@ -986,8 +997,9 @@ golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1021,8 +1033,9 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.1 h1:Kvvh58BN8Y9/lBi7hTekvtMpm07eUZ0ck5pRHpsMWrY= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= +golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1064,6 +1077,7 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -1071,8 +1085,11 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f h1:OfiFi4JbukWwe3lzw+xunroH1mnC1e2Gy5cxNJApiSY= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 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= @@ -1093,6 +1110,7 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1170,10 +1188,11 @@ golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= 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= @@ -1185,8 +1204,10 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3 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.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 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= @@ -1256,8 +1277,9 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= +golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -1389,8 +1411,9 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20141024133853-64131543e789/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/pkg/configutil/version.yaml b/pkg/configutil/version.yaml new file mode 100644 index 0000000000..2f492d603a --- /dev/null +++ b/pkg/configutil/version.yaml @@ -0,0 +1,8 @@ +admin: + # For GRPC endpoints you might want to use dns:///flyte.myexample.com + endpoint: dns:///localhost:30081 + authType: Pkce + insecure: true +logger: + show-source: true + level: 0 \ No newline at end of file diff --git a/pkg/docker/docker_util.go b/pkg/docker/docker_util.go index cf8f96a2c6..3b6be1c91c 100644 --- a/pkg/docker/docker_util.go +++ b/pkg/docker/docker_util.go @@ -104,7 +104,9 @@ func GetSandboxPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, e } // PullDockerImage will Pull docker image -func PullDockerImage(ctx context.Context, cli Docker, image string, pullPolicy sandboxConfig.ImagePullPolicy) error { +func PullDockerImage(ctx context.Context, cli Docker, image string, pullPolicy sandboxConfig.ImagePullPolicy, + imagePullOptions sandboxConfig.ImagePullOptions) error { + if pullPolicy == sandboxConfig.ImagePullPolicyAlways || pullPolicy == sandboxConfig.ImagePullPolicyIfNotPresent { if pullPolicy == sandboxConfig.ImagePullPolicyIfNotPresent { imageSummary, err := cli.ImageList(ctx, types.ImageListOptions{}) @@ -119,7 +121,11 @@ func PullDockerImage(ctx context.Context, cli Docker, image string, pullPolicy s } } } - r, err := cli.ImagePull(ctx, image, types.ImagePullOptions{}) + + r, err := cli.ImagePull(ctx, image, types.ImagePullOptions{ + RegistryAuth: imagePullOptions.RegistryAuth, + Platform: imagePullOptions.Platform, + }) if err != nil { return err } diff --git a/pkg/docker/docker_util_test.go b/pkg/docker/docker_util_test.go index 1915722640..a5124fb2bf 100644 --- a/pkg/docker/docker_util_test.go +++ b/pkg/docker/docker_util_test.go @@ -17,21 +17,15 @@ import ( "github.com/stretchr/testify/mock" "github.com/docker/docker/api/types" - cmdCore "github.com/flyteorg/flytectl/cmd/core" - u "github.com/flyteorg/flytectl/cmd/testutils" - "github.com/stretchr/testify/assert" ) var ( - cmdCtx cmdCore.CommandContext containers []types.Container imageName = "cr.flyte.org/flyteorg/flyte-sandbox" ) func setupSandbox() { - mockAdminClient := u.MockClient - cmdCtx = cmdCore.NewCommandContext(mockAdminClient, u.MockOutStream) err := os.MkdirAll(f.FilePathJoin(f.UserHomeDir(), ".flyte"), os.ModePerm) if err != nil { fmt.Println(err) @@ -110,7 +104,7 @@ func TestPullDockerImage(t *testing.T) { context := context.Background() // Verify the attributes mockDocker.OnImagePullMatch(context, mock.Anything, types.ImagePullOptions{}).Return(os.Stdin, nil) - err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyAlways) + err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyAlways, sandboxConfig.ImagePullOptions{}) assert.Nil(t, err) }) @@ -120,7 +114,7 @@ func TestPullDockerImage(t *testing.T) { context := context.Background() // Verify the attributes mockDocker.OnImagePullMatch(context, mock.Anything, types.ImagePullOptions{}).Return(os.Stdin, fmt.Errorf("error")) - err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyAlways) + err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyAlways, sandboxConfig.ImagePullOptions{}) assert.NotNil(t, err) }) @@ -131,7 +125,7 @@ func TestPullDockerImage(t *testing.T) { // Verify the attributes mockDocker.OnImagePullMatch(context, mock.Anything, types.ImagePullOptions{}).Return(os.Stdin, nil) mockDocker.OnImageListMatch(context, types.ImageListOptions{}).Return([]types.ImageSummary{}, nil) - err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyIfNotPresent) + err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyIfNotPresent, sandboxConfig.ImagePullOptions{}) assert.Nil(t, err) }) @@ -139,7 +133,7 @@ func TestPullDockerImage(t *testing.T) { setupSandbox() mockDocker := &mocks.Docker{} context := context.Background() - err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyNever) + err := PullDockerImage(context, mockDocker, "nginx:latest", sandboxConfig.ImagePullPolicyNever, sandboxConfig.ImagePullOptions{}) assert.Nil(t, err) }) } diff --git a/pkg/githubutil/githubutil.go b/pkg/githubutil/githubutil.go index b948fe880d..d36fe78800 100644 --- a/pkg/githubutil/githubutil.go +++ b/pkg/githubutil/githubutil.go @@ -8,6 +8,9 @@ import ( "runtime" "strings" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "github.com/flyteorg/flytectl/pkg/util" "github.com/flyteorg/flytestdlib/logger" @@ -131,7 +134,7 @@ func getFlytectlAssetName() string { } else if arch == platformutil.ArchX86 { arch = platformutil.Archi386 } - return fmt.Sprintf("flytectl_%s_%s.tar.gz", strings.Title(runtime.GOOS), arch.String()) + return fmt.Sprintf("flytectl_%s_%s.tar.gz", cases.Title(language.English).String(runtime.GOOS), arch.String()) } // CheckVersionExist returns the provided version release if version exist in repository diff --git a/pkg/githubutil/githubutil_test.go b/pkg/githubutil/githubutil_test.go index 70f383034d..5de7709940 100644 --- a/pkg/githubutil/githubutil_test.go +++ b/pkg/githubutil/githubutil_test.go @@ -6,6 +6,9 @@ import ( "strings" "testing" + "golang.org/x/text/cases" + "golang.org/x/text/language" + stdlibversion "github.com/flyteorg/flytestdlib/version" "github.com/flyteorg/flytectl/pkg/platformutil" @@ -99,7 +102,7 @@ func TestGetAssetsFromRelease(t *testing.T) { func TestGetAssetsName(t *testing.T) { t.Run("Get Assets name", func(t *testing.T) { - expected := fmt.Sprintf("flytectl_%s_386.tar.gz", strings.Title(runtime.GOOS)) + expected := fmt.Sprintf("flytectl_%s_386.tar.gz", cases.Title(language.English).String(runtime.GOOS)) arch = platformutil.Arch386 assert.Equal(t, expected, getFlytectlAssetName()) }) diff --git a/pkg/util/version.yaml b/pkg/util/version.yaml new file mode 100755 index 0000000000..e69de29bb2