Skip to content

Commit

Permalink
feat: cd event emiiter (#3806)
Browse files Browse the repository at this point in the history
* feat: cd event emiiter

* fix: lintt

* fix: change cd events mapping

* feat: add cdevents env vars

* feat: send cd event for scraper

* fix: detect mime type

* fix: test type

* fix: unit tests

* fix: error message

* fix: add source field

* fix: typo

* fix: add error

* fix: check for empty namespace

* feat: map test types for cd event

* feat: map test types for cd event

* fixL change notifying about files

* fix: double file opening

* fix: remove duplicated notification

* feat: unit test for event listener

* feat: cd event loader test

* feat: cd event integration test

* fix: unit test for extractor

* fix: minio integrattion test

* feat: extractor integration tests

* fix: int tests

* fix: int test

* fix: int test

* fix: int test

* fix: int test

* fix: run tests in parallel

* fix: unit tests
  • Loading branch information
vsukhin committed May 18, 2023
1 parent 4416fa0 commit 04dac8b
Show file tree
Hide file tree
Showing 37 changed files with 1,450 additions and 51 deletions.
3 changes: 3 additions & 0 deletions cmd/api-server/main.go
Expand Up @@ -315,6 +315,7 @@ func main() {
clientset,
cfg.TestkubeRegistry,
cfg.TestkubePodStartTimeout,
clusterId,
)
if err != nil {
ui.ExitOnError("Creating executor client", err)
Expand All @@ -338,6 +339,7 @@ func main() {
testsClientV3,
cfg.TestkubeRegistry,
cfg.TestkubePodStartTimeout,
clusterId,
)
if err != nil {
ui.ExitOnError("Creating container executor", err)
Expand Down Expand Up @@ -389,6 +391,7 @@ func main() {
storageClient,
cfg.GraphqlPort,
artifactStorage,
cfg.CDEventsTarget,
)

if mode == common.ModeAgent {
Expand Down
9 changes: 9 additions & 0 deletions go.mod
Expand Up @@ -6,13 +6,16 @@ require (
github.com/99designs/gqlgen v0.17.27
github.com/Masterminds/semver v1.5.0
github.com/adhocore/gronx v1.1.2
github.com/cdevents/sdk-go v0.3.0
github.com/cli/cli/v2 v2.20.2
github.com/cloudevents/sdk-go/v2 v2.14.0
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/creasty/defaults v1.7.0
github.com/denisbrodbeck/machineid v1.0.1
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0
github.com/fasthttp/websocket v1.5.0
github.com/fluxcd/pkg/apis/event v0.2.0
github.com/gabriel-vasile/mimetype v1.4.2
github.com/gofiber/adaptor/v2 v2.1.29
github.com/gofiber/fiber/v2 v2.39.0
github.com/gofiber/websocket/v2 v2.1.1
Expand Down Expand Up @@ -77,6 +80,9 @@ require (
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/golang-jwt/jwt/v4 v4.4.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
Expand All @@ -91,6 +97,7 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lithammer/fuzzysearch v1.1.5 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -106,8 +113,10 @@ require (
github.com/nats-io/nats-server/v2 v2.8.4 // indirect
github.com/nats-io/nkeys v0.3.0 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/package-url/packageurl-go v0.1.0 // indirect
github.com/pquerna/cachecontrol v0.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
github.com/segmentio/backo-go v1.0.1 // indirect
github.com/shurcooL/githubv4 v0.0.0-20220922232305-70b4d362a8cb // indirect
Expand Down
25 changes: 25 additions & 0 deletions go.sum
Expand Up @@ -111,6 +111,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=
github.com/briandowns/spinner v1.19.0/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/cdevents/sdk-go v0.3.0 h1:YHb47qIVi3qV+HmkyW3e0gqCQaqKW0rnL4EejSDuMFs=
github.com/cdevents/sdk-go v0.3.0/go.mod h1:8EFl9VDZkxEmO/sr06Phzr501OiU6B5d04+eYpf1tF0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand All @@ -132,6 +134,8 @@ github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5
github.com/cli/shurcooL-graphql v0.0.2 h1:rwP5/qQQ2fM0TzkUTwtt6E2LbIYf6R+39cUXTa04NYk=
github.com/cli/shurcooL-graphql v0.0.2/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudevents/sdk-go/v2 v2.14.0 h1:Nrob4FwVgi5L4tV9lhjzZcjYqFVyJzsA56CwPaPfv6s=
github.com/cloudevents/sdk-go/v2 v2.14.0/go.mod h1:xDmKfzNjM8gBvjaF8ijFjM1VYOVUEeUfapHMUX1T5To=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
Expand Down Expand Up @@ -184,6 +188,8 @@ github.com/fluxcd/pkg/apis/event v0.2.0 h1:cmAtkZfoEaNVYegI4SFM8XstdRAil3O9AoP+8
github.com/fluxcd/pkg/apis/event v0.2.0/go.mod h1:OyzKqs90J+MK7rQaEOFMMCkALpPkfmxlkabgyY2wSFQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
Expand All @@ -208,6 +214,14 @@ github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTr
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
Expand Down Expand Up @@ -369,6 +383,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB
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/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -379,6 +394,8 @@ github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4H
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubeshop/testkube-operator v1.10.8-0.20230504145001-42249450d65a h1:hBHA3iMgIO9dqa+8aNQ/6NhgV9RFLWAo36Eo7VRVD/4=
github.com/kubeshop/testkube-operator v1.10.8-0.20230504145001-42249450d65a/go.mod h1:6Rs8MugOzaMcthGzobf6GBlRzbOFiK/GJiuYN6MCfEw=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down Expand Up @@ -462,6 +479,8 @@ github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
github.com/otiai10/mint v1.4.0 h1:umwcf7gbpEwf7WFzqmWwSv0CzbeMsae2u9ZvpP8j2q4=
github.com/otiai10/mint v1.4.0/go.mod h1:gifjb2MYOoULtKLqUAEILUG/9KONW6f7YsJ6vQLTlFI=
github.com/package-url/packageurl-go v0.1.0 h1:efWBc98O/dBZRg1pw2xiDzovnlMjCa9NPnfaiBduh8I=
github.com/package-url/packageurl-go v0.1.0/go.mod h1:C/ApiuWpmbpni4DIOECf6WCjFUZV7O1Fx7VAzrZHgBw=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -516,12 +535,16 @@ github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9AmsA2Bj/iv+s4JHE=
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0=
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899/go.mod h1:oejLrk1Y/5zOF+c/aHtXqn3TFlzzbAgPWg8zBiAHDas=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo=
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
Expand Down Expand Up @@ -636,6 +659,7 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
Expand Down Expand Up @@ -785,6 +809,7 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
12 changes: 12 additions & 0 deletions internal/app/api/v1/server.go
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/pkg/errors"

"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/repository/config"

"github.com/kubeshop/testkube/pkg/version"
Expand All @@ -35,6 +36,7 @@ import (
testkubeclientset "github.com/kubeshop/testkube-operator/pkg/clientset/versioned"
"github.com/kubeshop/testkube/internal/app/api/metrics"
"github.com/kubeshop/testkube/pkg/event"
"github.com/kubeshop/testkube/pkg/event/kind/cdevent"
"github.com/kubeshop/testkube/pkg/event/kind/slack"
"github.com/kubeshop/testkube/pkg/event/kind/webhook"
ws "github.com/kubeshop/testkube/pkg/event/kind/websocket"
Expand Down Expand Up @@ -77,6 +79,7 @@ func NewTestkubeAPI(
storage storage.Client,
graphqlPort string,
artifactsStorage storage.ArtifactsStorage,
cdeventsTarget string,
) TestkubeAPI {

var httpConfig server.Config
Expand Down Expand Up @@ -125,6 +128,15 @@ func NewTestkubeAPI(
s.Events.Loader.Register(s.WebsocketLoader)
s.Events.Loader.Register(s.slackLoader)

if cdeventsTarget != "" {
cdeventLoader, err := cdevent.NewCDEventLoader(cdeventsTarget, clusterId, namespace, testkube.AllEventTypes)
if err == nil {
s.Events.Loader.Register(cdeventLoader)
} else {
s.Log.Debug("cdevents init error", "error", err.Error())
}
}

s.InitEnvs()
s.InitRoutes()

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Expand Up @@ -58,6 +58,7 @@ type Config struct {
GraphqlPort string `envconfig:"TESTKUBE_GRAPHQL_PORT" default:"8070"`
TestkubeRegistry string `envconfig:"TESTKUBE_REGISTRY" default:""`
TestkubePodStartTimeout time.Duration `envconfig:"TESTKUBE_POD_START_TIMEOUT" default:"30m"`
CDEventsTarget string `envconfig:"CDEVENTS_TARGET" default:""`
}

func Get() (*Config, error) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/v1/testkube/model_execution_extended.go
Expand Up @@ -188,3 +188,11 @@ func (e Execution) IsTimeout() bool {

return *e.ExecutionResult.Status == TIMEOUT_ExecutionStatus
}

func (e Execution) IsPassed() bool {
if e.ExecutionResult == nil {
return true
}

return *e.ExecutionResult.Status == PASSED_ExecutionStatus
}
8 changes: 8 additions & 0 deletions pkg/api/v1/testkube/model_test_suite_execution_extended.go
Expand Up @@ -135,3 +135,11 @@ func (e *TestSuiteExecution) IsPassed() bool {
func (e *TestSuiteExecution) IsFailed() bool {
return *e.Status == FAILED_TestSuiteExecutionStatus
}

func (e *TestSuiteExecution) IsAborted() bool {
return *e.Status == ABORTED_TestSuiteExecutionStatus
}

func (e *TestSuiteExecution) IsTimeout() bool {
return *e.Status == TIMEOUT_TestSuiteExecutionStatus
}
31 changes: 29 additions & 2 deletions pkg/cloud/data/artifact/scraper_integration_test.go
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/kubeshop/testkube/pkg/utils/test"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

Expand Down Expand Up @@ -82,7 +83,20 @@ func TestCloudScraper_ArchiveFilesystemExtractor_Integration(t *testing.T) {
Execute(gomock.Any(), cloudscraper.CmdScraperPutObjectSignedURL, gomock.Eq(req2)).
Return([]byte(`{"URL":"`+testServer.URL+`/dummy"}`), nil)

s := scraper.NewExtractLoadScraper(extractor, cloudLoader)
// given
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := cloudevents.NewEventFromHTTPRequest(r)
// then
assert.NoError(t, err)
})

svr := httptest.NewServer(testHandler)
defer svr.Close()

client, err := cloudevents.NewClientHTTP(cloudevents.WithTarget(svr.URL))
assert.NoError(t, err)

s := scraper.NewExtractLoadScraper(extractor, cloudLoader, client, "")
execution := testkube.Execution{
Id: "my-execution-id",
TestName: "my-test",
Expand Down Expand Up @@ -168,7 +182,20 @@ func TestCloudScraper_RecursiveFilesystemExtractor_Integration(t *testing.T) {
Execute(gomock.Any(), cloudscraper.CmdScraperPutObjectSignedURL, gomock.Eq(req3)).
Return([]byte(`{"URL":"`+testServer.URL+`/dummy"}`), nil)

s := scraper.NewExtractLoadScraper(extractor, cloudLoader)
// given
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := cloudevents.NewEventFromHTTPRequest(r)
// then
assert.NoError(t, err)
})

svr := httptest.NewServer(testHandler)
defer svr.Close()

client, err := cloudevents.NewClientHTTP(cloudevents.WithTarget(svr.URL))
assert.NoError(t, err)

s := scraper.NewExtractLoadScraper(extractor, cloudLoader, client, "")
execution := testkube.Execution{
Id: "my-execution-id",
TestName: "my-test",
Expand Down
4 changes: 4 additions & 0 deletions pkg/envs/variables.go
Expand Up @@ -22,6 +22,8 @@ type Params struct {
DataDir string // RUNNER_DATADIR
GitUsername string // RUNNER_GITUSERNAME
GitToken string // RUNNER_GITTOKEN
ClusterID string `envconfig:"RUNNER_CLUSTERID"` // RUNNER_CLUSTERID
CDEventsTarget string `envconfig:"RUNNER_CDEVENTS_TARGET"` // RUNNER_CDEVENTS_TARGET
CloudMode bool `envconfig:"RUNNER_CLOUD_MODE"` // RUNNER_CLOUD_MODE
CloudAPIKey string `envconfig:"RUNNER_CLOUD_API_KEY"` // RUNNER_CLOUD_API_KEY
CloudAPITLSInsecure bool `envconfig:"RUNNER_CLOUD_API_TLS_INSECURE"` // RUNNER_CLOUD_API_TLS_INSECURE
Expand Down Expand Up @@ -56,6 +58,8 @@ func printParams(params Params) {
output.PrintLogf("RUNNER_GITUSERNAME=\"%s\"", params.GitUsername)
printSensitiveParam("RUNNER_GITTOKEN", params.GitToken)
output.PrintLogf("RUNNER_DATADIR=\"%s\"", params.DataDir)
output.PrintLogf("RUNNER_CLUSTERID=\"%s\"", params.ClusterID)
output.PrintLogf("RUNNER_CDEVENTS_TARGET=\"%s\"", params.CDEventsTarget)
output.PrintLogf("RUNNER_CLOUD_MODE=\"%t\"", params.CloudMode)
output.PrintLogf("RUNNER_CLOUD_API_TLS_INSECURE=\"%t\"", params.CloudAPITLSInsecure)
output.PrintLogf("RUNNER_CLOUD_API_URL=\"%s\"", params.CloudAPIURL)
Expand Down
2 changes: 1 addition & 1 deletion pkg/event/emitter.go
Expand Up @@ -170,7 +170,7 @@ func (e *Emitter) notifyHandler(l common.Listener) bus.Handler {
log := e.Log.With("listen-on", l.Events(), "queue-group", l.Name(), "selector", l.Selector(), "metadata", l.Metadata())
return func(event testkube.Event) error {
if event.Valid(l.Selector(), l.Events()) {
l.Notify(event)
log.Infow("notification result", l.Notify(event))
log.Infow("listener notified", event.Log()...)
} else {
log.Infow("dropping event not matching selector or type", event.Log()...)
Expand Down

0 comments on commit 04dac8b

Please sign in to comment.