From 62340b0c6d256becdb68d99822bcfe2f7cee75ce Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 10:22:06 +0100 Subject: [PATCH 1/6] feat: new executor data struct --- build/kube/executor.yaml | 5 ++--- cmd/agent/main.go | 2 +- go.mod | 2 +- go.sum | 33 ++++++++++++++++----------------- pkg/runner/runner.go | 38 ++++++++++++++++++++++++++++++++++++-- pkg/runner/runner_test.go | 6 +++--- 6 files changed, 59 insertions(+), 27 deletions(-) diff --git a/build/kube/executor.yaml b/build/kube/executor.yaml index 8d6aa1d..37b24d5 100644 --- a/build/kube/executor.yaml +++ b/build/kube/executor.yaml @@ -7,6 +7,5 @@ spec: executor_type: job image: kubeshop/testkube-example-executor:0.0.1 # pass your repository and tag types: - - example/test - volume_mount_path: /mnt/artifacts-storage - volume_quantity: 10Gix + - example/test + features: [] diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 90b52a6..9772078 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -4,7 +4,7 @@ import ( "os" "github.com/kubeshop/testkube-executor-example/pkg/runner" - "github.com/kubeshop/testkube/pkg/runner/agent" + "github.com/kubeshop/testkube/pkg/executor/agent" ) func main() { diff --git a/go.mod b/go.mod index 793b351..48cc339 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/kubeshop/testkube-executor-example go 1.16 require ( - github.com/kubeshop/testkube v0.6.9 + github.com/kubeshop/testkube v0.9.11 github.com/stretchr/testify v1.7.0 ) diff --git a/go.sum b/go.sum index 008d769..b706621 100644 --- a/go.sum +++ b/go.sum @@ -65,9 +65,6 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= -github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= -github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84 h1:cutFptzj+ospnc1PETUqcSVTH3VQ44Bi0rpt3nE9gvo= -github.com/bclicn/color v0.0.0-20180711051946-108f2023dc84/go.mod h1:Va9ap1qxjAWkIVaW1E9rH0aNgE8SDI5A4n8Ds8P0fAA= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -110,6 +107,7 @@ github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8 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= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= +github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:90Ly+6UfUypEF6vvvW5rQIv9opIL8CbmW9FT20LDQoY= github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= @@ -150,7 +148,6 @@ github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8 github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= @@ -178,9 +175,8 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofiber/adaptor/v2 v2.1.7/go.mod h1:NBpdr07Y7j7A2dnZ/7LMqhyXCKDOaPe8f5/M5mRvWKk= -github.com/gofiber/fiber/v2 v2.13.0/go.mod h1:oZTLWqYnqpMMuF922SjGbsYZsdpE1MCfh416HNdweIM= -github.com/gofiber/fiber/v2 v2.14.0/go.mod h1:oZTLWqYnqpMMuF922SjGbsYZsdpE1MCfh416HNdweIM= +github.com/gofiber/adaptor/v2 v2.1.14/go.mod h1:s2KVIM9tgTFdbHFd2yUefy80BMIGjU1w3jc3Umk9ZM8= +github.com/gofiber/fiber/v2 v2.22.0/go.mod h1:MR1usVH3JHYRyQwMe2eZXRSZHRX38fkV+A7CPB+DlDQ= github.com/gofiber/utils v0.1.2/go.mod h1:pacRFtghAE3UoknMOUiXh2Io/nLWSUHtQCi/3QASsOc= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -256,6 +252,8 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg= github.com/googleapis/gnostic v0.5.5/go.mod h1:7+EbHbldMins07ALC74bsA81Ovc97DwqyJO1AENw9kA= +github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= +github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -295,8 +293,6 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -315,8 +311,8 @@ github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -331,9 +327,9 @@ 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= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kubeshop/testkube v0.6.9 h1:YkfaEgJ0ftJr/Y5ED1iQxa3RpsSXscITOgypHdkGDzI= -github.com/kubeshop/testkube v0.6.9/go.mod h1:G79sK3a6UGXJmExW4qkl/FOV/DNSFC3c0ueOg8wG3BA= -github.com/kubeshop/testkube-operator v0.6.0/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo= +github.com/kubeshop/testkube v0.9.11 h1:dY6whwQY+dZh7+VEXBKe8M2Kq7Zk8TSPm+9KPZ/+Eqk= +github.com/kubeshop/testkube v0.9.11/go.mod h1:XyJeZgKe5RBtk3M50jmptEwi7aCLTnfNPjN8kyBQ54k= +github.com/kubeshop/testkube-operator v0.9.7/go.mod h1:P1LXcaJEt1eVVrdRlDZip9mNHEP7cN64USQ6u/aCOeo= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -484,12 +480,14 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= +github.com/valyala/fasthttp v1.31.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= +github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c/go.mod h1:UrdRz5enIKZ63MEE3IF9l2/ebyx59GyGgPi+tICQdmM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -504,8 +502,8 @@ go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489/go.mod h1:yVHk9ub3C go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= -go.mongodb.org/mongo-driver v1.5.4 h1:NPIBF/lxEcKNfWwoCJRX8+dMVwecWf9q3qUJkuh75oM= -go.mongodb.org/mongo-driver v1.5.4/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw= +go.mongodb.org/mongo-driver v1.7.4 h1:sllcioag8Mec0LYkftYWq+cKNPIR4Kqq3iv9ZXY0g/E= +go.mongodb.org/mongo-driver v1.7.4/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -705,6 +703,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 h1:JWgyZ1qgdTaF3N3oxC+MdTV7qvEEgHo3otj+HB5CM7Q= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/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= diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 5618b02..0d29043 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -2,10 +2,14 @@ package runner import ( "fmt" + "io/fs" "io/ioutil" "net/http" + "os" + "path/filepath" "github.com/kubeshop/testkube/pkg/api/v1/testkube" + "github.com/kubeshop/testkube/pkg/executor/output" ) func NewRunner() *ExampleRunner { @@ -17,8 +21,34 @@ type ExampleRunner struct { } func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.ExecutionResult, err error) { - // ScriptContent will have URI - uri := execution.ScriptContent + + // Our test data will be simple string with url inside we can get it as execution.Content.Data + // but for more sophi + + // execution.Content could have git repo data + // we're also passing content files/directories as mounted volume in directory + path := os.Getenv("RUNNER_DATADIR") + + // let's print content of passed volume + output.PrintEvent("path:", path) + filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + d, err := ioutil.ReadFile(path) + if err != nil { + return err + } + output.PrintEvent("- file: ", path, string(d)) + return nil + + }) + + output.PrintLog("some log message from executor") + + // e.g. Cypress test is stored in Git repo so Testkube will checkout it automatically + // and allow you to use it easily + uri := execution.Content.Data resp, err := http.Get(uri) if err != nil { return result, err @@ -40,5 +70,9 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu // else we'll return error to simplify example err = fmt.Errorf("invalid status code %d, (uri:%s)", resp.StatusCode, uri) + + // TODO remove - debug + // time.Sleep(time.Hour) + return result.Err(err), nil } diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 71ca792..a22b42f 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -12,7 +12,7 @@ func TestRun(t *testing.T) { t.Run("successful result", func(t *testing.T) { runner := NewRunner() res, err := runner.Run(testkube.Execution{ - ScriptContent: "https://testkube.io", + Content: testkube.NewStringTestContent("https://testkube.io"), }) assert.NoError(t, err) @@ -22,7 +22,7 @@ func TestRun(t *testing.T) { t.Run("failed 404 result", func(t *testing.T) { runner := NewRunner() res, err := runner.Run(testkube.Execution{ - ScriptContent: "https://testkube.io/some-non-existing-uri-blablablabl", + Content: testkube.NewStringTestContent("https://testkube.io/some-non-existing-uri-blablablabl"), }) assert.NoError(t, err) @@ -33,7 +33,7 @@ func TestRun(t *testing.T) { t.Run("network connection issues returns errors", func(t *testing.T) { runner := NewRunner() _, err := runner.Run(testkube.Execution{ - ScriptContent: "blabla://non-existing-uri", + Content: testkube.NewStringTestContent("blabla://non-existing-uri"), }) assert.Error(t, err) From 1966e7c7ba70f5b827fbe9140f1ff52eda504c2a Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 10:22:54 +0100 Subject: [PATCH 2/6] feat: added Vlad as Codeowner --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 93104fb..99f017e 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -3,4 +3,4 @@ docs/* @olensmar img/* @olensmar api/* @olensmar -* @exu @nicufk @jasmingacic @fog1985 +* @exu @nicufk @jasmingacic @vsukhin From acf105474be6d6bde8e4eba194ef1a3dab9de21d Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 11:43:28 +0100 Subject: [PATCH 3/6] added more commentrs to runner --- Makefile | 9 ++++++--- build/kube/executor.yaml | 2 +- pkg/runner/runner.go | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7967783..45aa045 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,17 @@ .PHONY: test cover -NAME ?= template +NAME ?= testkube-executor-example run: - EXECUTOR_PORT=8082 go run cmd/agent/main.go + go run cmd/agent/main.go mongo-dev: docker run -p 27017:27017 mongo docker-build: - docker build -t kubeshop/$(NAME)-runner -f build/agent/Dockerfile . + docker build --platform=linux/amd64 -t kubeshop/$(NAME):latest -f build/agent/Dockerfile . + +docker-push: + docker push kubeshop/$(NAME):latest install-swagger-codegen-mac: brew install swagger-codegen diff --git a/build/kube/executor.yaml b/build/kube/executor.yaml index 37b24d5..525a964 100644 --- a/build/kube/executor.yaml +++ b/build/kube/executor.yaml @@ -5,7 +5,7 @@ metadata: namespace: testkube spec: executor_type: job - image: kubeshop/testkube-example-executor:0.0.1 # pass your repository and tag + image: kubeshop/testkube-executor-example:latest # pass your repository and tag types: - example/test features: [] diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 0d29043..81a11d0 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -7,6 +7,8 @@ import ( "net/http" "os" "path/filepath" + "strings" + "time" "github.com/kubeshop/testkube/pkg/api/v1/testkube" "github.com/kubeshop/testkube/pkg/executor/output" @@ -48,7 +50,7 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu // e.g. Cypress test is stored in Git repo so Testkube will checkout it automatically // and allow you to use it easily - uri := execution.Content.Data + uri := strings.TrimSuffix(execution.Content.Data, "\n") // newline on the end is not needed :) resp, err := http.Get(uri) if err != nil { return result, err @@ -60,6 +62,9 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu return result, err } + // TODO remove - debug + time.Sleep(time.Hour) + // if get is successful return success result if resp.StatusCode == 200 { return testkube.ExecutionResult{ @@ -71,8 +76,5 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu // else we'll return error to simplify example err = fmt.Errorf("invalid status code %d, (uri:%s)", resp.StatusCode, uri) - // TODO remove - debug - // time.Sleep(time.Hour) - return result.Err(err), nil } From 88f6ad4b4317a5a17bf6cd70bb41c4622d3ccfef Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 11:47:26 +0100 Subject: [PATCH 4/6] added examples file --- examples/test-definition-file | 1 + pkg/runner/runner.go | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 examples/test-definition-file diff --git a/examples/test-definition-file b/examples/test-definition-file new file mode 100644 index 0000000..1f87d2b --- /dev/null +++ b/examples/test-definition-file @@ -0,0 +1 @@ +http://google.pl diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 81a11d0..378b3f9 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -50,7 +50,12 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu // e.g. Cypress test is stored in Git repo so Testkube will checkout it automatically // and allow you to use it easily + // we can create test like below: + // $ echo "http://google.pl" | kubectl testkube tests create --name example-google-test --type example/test uri := strings.TrimSuffix(execution.Content.Data, "\n") // newline on the end is not needed :) + + // other way to get data could be load it from Git e.g. file in git repo + resp, err := http.Get(uri) if err != nil { return result, err From 48d13d79b3080b6ecf49ae6ea518e3b794e89caf Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 11:53:48 +0100 Subject: [PATCH 5/6] fix: removed debug sleep --- examples/test-definition-file | 2 +- pkg/runner/runner.go | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/test-definition-file b/examples/test-definition-file index 1f87d2b..dcff48b 100644 --- a/examples/test-definition-file +++ b/examples/test-definition-file @@ -1 +1 @@ -http://google.pl +https://httpstat.us/200 \ No newline at end of file diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 378b3f9..6a7595f 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" "strings" - "time" "github.com/kubeshop/testkube/pkg/api/v1/testkube" "github.com/kubeshop/testkube/pkg/executor/output" @@ -51,10 +50,12 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu // e.g. Cypress test is stored in Git repo so Testkube will checkout it automatically // and allow you to use it easily // we can create test like below: - // $ echo "http://google.pl" | kubectl testkube tests create --name example-google-test --type example/test + // $ echo "https://httpstat.us/200" | kubectl testkube tests create --name example-google-test --type example/test uri := strings.TrimSuffix(execution.Content.Data, "\n") // newline on the end is not needed :) // other way to get data could be load it from Git e.g. file in git repo + // if test will be created using git file content (like this one example with uri stored in file https://github.com/kubeshop/testkube-executor-example/blob/88f6ad4b4317a5a17bf6cd70bb41c4622d3ccfef/examples/test-definition-file) + // Testkube will automatically map this dir/file to directory defined in the RUNNER_DATADIR env variable resp, err := http.Get(uri) if err != nil { @@ -67,9 +68,6 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu return result, err } - // TODO remove - debug - time.Sleep(time.Hour) - // if get is successful return success result if resp.StatusCode == 200 { return testkube.ExecutionResult{ From 771d32cee42aa465a35efff595b1afb78d80acb0 Mon Sep 17 00:00:00 2001 From: Jacek Wysocki Date: Wed, 23 Feb 2022 12:54:53 +0100 Subject: [PATCH 6/6] fix: added error handling --- pkg/runner/runner.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 6a7595f..db6fbf6 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -31,8 +31,8 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu path := os.Getenv("RUNNER_DATADIR") // let's print content of passed volume - output.PrintEvent("path:", path) - filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { + output.PrintEvent("found files in:", path) + err = filepath.Walk(path, func(path string, info fs.FileInfo, err error) error { if err != nil { return err } @@ -40,23 +40,31 @@ func (r *ExampleRunner) Run(execution testkube.Execution) (result testkube.Execu if err != nil { return err } - output.PrintEvent("- file: ", path, string(d)) + output.PrintEvent("- ", path, string(d)) return nil }) + if err != nil { + return result, err + } + output.PrintLog("some log message from executor") // e.g. Cypress test is stored in Git repo so Testkube will checkout it automatically // and allow you to use it easily // we can create test like below: - // $ echo "https://httpstat.us/200" | kubectl testkube tests create --name example-google-test --type example/test + // $ echo "https://httpstat.us/200" | kubectl testkube tests create --name example-test --type example/test uri := strings.TrimSuffix(execution.Content.Data, "\n") // newline on the end is not needed :) // other way to get data could be load it from Git e.g. file in git repo // if test will be created using git file content (like this one example with uri stored in file https://github.com/kubeshop/testkube-executor-example/blob/88f6ad4b4317a5a17bf6cd70bb41c4622d3ccfef/examples/test-definition-file) + // e.g. + // $ kubectl testkube tests create --name example-test-git --type example/test --git-uri https://github.com/kubeshop/testkube-executor-example.git --git-path examples/test-definition-file --git-branch jacek/fix/custom-executor-example-update // Testkube will automatically map this dir/file to directory defined in the RUNNER_DATADIR env variable + // so you'll need to handle it here (if it's not handled by your test framework already e.g. Cypress runs in root level of test project) + // below is test our test against passed URI status code resp, err := http.Get(uri) if err != nil { return result, err