diff --git a/Gopkg.lock b/Gopkg.lock index cdf68c5578..5c7489e7bf 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -3,7 +3,6 @@ [[projects]] branch = "master" - digest = "1:ce6b6155cb0e2a5cda58a7b3ba130d10642ce178715dc1925c54c449cefbfc1a" name = "cloud.google.com/go" packages = [ "compute/metadata", @@ -12,73 +11,57 @@ "internal/version", "pubsub", "pubsub/apiv1", - "pubsub/internal/distribution", + "pubsub/internal/distribution" ] - pruneopts = "UT" - revision = "f52f9bc132541d2aa914f42100c36d10b1ef7e0c" + revision = "88dee6a1ef5aea45e2fadf8f96c828c78b02a958" [[projects]] - digest = "1:ed77032e4241e3b8329c9304d66452ed196e795876e14be677a546f36b94e67a" name = "github.com/DataDog/zstd" packages = ["."] - pruneopts = "UT" revision = "c7161f8c63c045cbc7ca051dcc969dd0e4054de2" version = "v1.3.5" [[projects]] branch = "master" - digest = "1:dc648facc1e7aac5086f749c84c9b9263345c08161fadd9cf92ae3309c9fcaa6" name = "github.com/Knetic/govaluate" packages = ["."] - pruneopts = "UT" revision = "9aa49832a739dcd78a5542ff189fb82c3e423116" [[projects]] - digest = "1:a2682518d905d662d984ef9959984ef87cecb777d379bfa9d9fe40e78069b3e4" name = "github.com/PuerkitoBio/purell" packages = ["."] - pruneopts = "UT" revision = "44968752391892e1b0d0b821ee79e9a85fa13049" version = "v1.1.1" [[projects]] branch = "master" - digest = "1:c739832d67eb1e9cc478a19cc1a1ccd78df0397bf8a32978b759152e205f644b" name = "github.com/PuerkitoBio/urlesc" packages = ["."] - pruneopts = "UT" revision = "de5bf2ad457846296e2031421a34e2568e304e35" [[projects]] - digest = "1:82a18170c9c41e36939cb5d26da1546b2cfa786aa030a978d3bf183519849230" name = "github.com/Shopify/sarama" packages = ["."] - pruneopts = "UT" revision = "4602b5a8c6e826f9e0737865818dd43b2339a092" version = "v1.21.0" [[projects]] branch = "master" - digest = "1:797da30d559e1fbc24acfe026226cfb49f129216fb65db1fa6b786f2ace0cc2c" name = "github.com/adlio/trello" packages = ["."] - pruneopts = "UT" revision = "b0faddb69566d3b80c1b70aa6daf2677b3f7a551" [[projects]] - digest = "1:4b9792d4bd04b67ce23f3d8a896df2f3ae49e1574ea2722501959f2b86f35002" name = "github.com/argoproj/argo" packages = [ "pkg/apis/workflow", - "pkg/apis/workflow/v1alpha1", + "pkg/apis/workflow/v1alpha1" ] - pruneopts = "UT" revision = "0a928e93dac6d8522682931a0a68c52add310cdb" version = "v2.2.1" [[projects]] branch = "master" - digest = "1:654cc015a408af83d8cd3c565eb3c49aba07221ff326ac1949eb184fdb99c3ae" name = "github.com/aws/aws-sdk-go" packages = [ "aws", @@ -111,87 +94,69 @@ "private/protocol/xml/xmlutil", "service/sns", "service/sqs", - "service/sts", + "service/sts" ] - pruneopts = "UT" - revision = "cd51eb5a317c3157da5e303c9909681db757f585" + revision = "06b6ff7a2d1360d3504c1ad6e7d3d073e1bc4619" [[projects]] - digest = "1:357f4baa5f50bb2a9d9d01600c8dadebf1cb890b59b53a4c810301fc7bf3736c" name = "github.com/colinmarc/hdfs" packages = [ ".", "protocol/hadoop_common", "protocol/hadoop_hdfs", - "rpc", + "rpc" ] - pruneopts = "UT" revision = "48eb8d6c34a97ffc73b406356f0f2e1c569b42a5" [[projects]] - digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" name = "github.com/davecgh/go-spew" packages = ["spew"] - pruneopts = "UT" revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" version = "v1.1.1" [[projects]] - digest = "1:6f9339c912bbdda81302633ad7e99a28dfa5a639c864061f1929510a9a64aa74" name = "github.com/dustin/go-humanize" packages = ["."] - pruneopts = "UT" revision = "9f541cc9db5d55bce703bd99987c9d5cb8eea45e" version = "v1.0.0" [[projects]] - digest = "1:1f0c7ab489b407a7f8f9ad16c25a504d28ab461517a971d341388a56156c1bd7" name = "github.com/eapache/go-resiliency" packages = ["breaker"] - pruneopts = "UT" revision = "ea41b0fad31007accc7f806884dcdf3da98b79ce" version = "v1.1.0" [[projects]] branch = "master" - digest = "1:79f16588b5576b1b3cd90e48d2374cc9a1a8776862d28d8fd0f23b0e15534967" name = "github.com/eapache/go-xerial-snappy" packages = ["."] - pruneopts = "UT" revision = "776d5712da21bc4762676d614db1d8a64f4238b0" [[projects]] - digest = "1:444b82bfe35c83bbcaf84e310fb81a1f9ece03edfed586483c869e2c046aef69" name = "github.com/eapache/queue" packages = ["."] - pruneopts = "UT" revision = "44cc805cf13205b55f69e14bcb69867d1ae92f98" version = "v1.1.0" [[projects]] - digest = "1:184008c955d6a3226b700c13ed0e875a7a051a759618f9bccba9b5c99f17faa5" name = "github.com/eclipse/paho.mqtt.golang" packages = [ ".", - "packets", + "packets" ] - pruneopts = "UT" revision = "36d01c2b4cbeb3d2a12063e4880ce30800af9560" version = "v1.1.1" [[projects]] - digest = "1:8ee7b41ace3ba875c17e38ba7780e7cf0d29882338637861e9f13f04f60ecc5c" name = "github.com/emicklei/go-restful" packages = [ ".", - "log", + "log" ] - pruneopts = "UT" revision = "85d198d05a92d31823b852b4a5928114912e8949" version = "v2.9.0" [[projects]] - digest = "1:b498b36dbb2b306d1c5205ee5236c9e60352be8f9eea9bf08186723a9f75b4f3" name = "github.com/emirpasic/gods" packages = [ "containers", @@ -199,62 +164,48 @@ "lists/arraylist", "trees", "trees/binaryheap", - "utils", + "utils" ] - pruneopts = "UT" revision = "1615341f118ae12f353cc8a983f35b584342c9b3" version = "v1.12.0" [[projects]] branch = "master" - digest = "1:95647ba546edaa23b88c7be3fbe378f355c9fab70f1c7e27d62698a939f5294f" name = "github.com/fsnotify/fsnotify" packages = ["."] - pruneopts = "UT" - revision = "11844c0959f6fff69ba325d097fce35bd85a8e93" + revision = "1485a34d5d5723fea214f5710708e19a831720e4" [[projects]] branch = "master" - digest = "1:08188cf7ce7027b22e88cc23da27f17349a0ba7746271a60cbe0a70266c2346f" name = "github.com/ghodss/yaml" packages = ["."] - pruneopts = "UT" revision = "25d852aebe32c875e9c044af3eef9c7dc6bc777f" [[projects]] - digest = "1:953a2628e4c5c72856b53f5470ed5e071c55eccf943d798d42908102af2a610f" name = "github.com/go-openapi/jsonpointer" packages = ["."] - pruneopts = "UT" revision = "ef5f0afec364d3b9396b7b77b43dbe26bf1f8004" version = "v0.18.0" [[projects]] - digest = "1:81210e0af657a0fb3638932ec68e645236bceefa4c839823db0c4d918f080895" name = "github.com/go-openapi/jsonreference" packages = ["."] - pruneopts = "UT" revision = "8483a886a90412cd6858df4ea3483dce9c8e35a3" version = "v0.18.0" [[projects]] - digest = "1:08656ef9c5a45ddccb7f206ca2d67e12e9fcda4122a83dc0544b5c967267cefa" name = "github.com/go-openapi/spec" packages = ["."] - pruneopts = "UT" revision = "5b6cdde3200976e3ecceb2868706ee39b6aff3e4" version = "v0.18.0" [[projects]] - digest = "1:0005186c6608dd542239ac8e4f4f1e2e7c24d493e999113c46b93332f0362fc0" name = "github.com/go-openapi/swag" packages = ["."] - pruneopts = "UT" revision = "1d29f06aebd59ccdf11ae04aa0334ded96e2d909" version = "v0.18.0" [[projects]] - digest = "1:b9faadd7c7214340381f24f8f97d4c6d6b5d7d5eeddc30c14c3b06045a821bde" name = "github.com/gogo/protobuf" packages = [ "gogoproto", @@ -284,23 +235,18 @@ "protoc-gen-gogofast", "sortkeys", "vanity", - "vanity/command", + "vanity/command" ] - pruneopts = "UT" revision = "ba06b47c162d49f2af050fb4c75bcbc86a159d5c" version = "v1.2.1" [[projects]] branch = "master" - digest = "1:1ba1d79f2810270045c328ae5d674321db34e3aae468eb4233883b473c5c0467" name = "github.com/golang/glog" packages = ["."] - pruneopts = "UT" revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" [[projects]] - branch = "master" - digest = "1:2de4d7f2c3cb21a81f945547031d6a4fd3c6bc9230c2c7dc620394868bb44888" name = "github.com/golang/protobuf" packages = [ "proto", @@ -314,193 +260,150 @@ "ptypes/any", "ptypes/duration", "ptypes/empty", - "ptypes/timestamp", + "ptypes/timestamp" ] - pruneopts = "UT" revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30" + version = "v1.3.1" [[projects]] - digest = "1:e4f5819333ac698d294fe04dbf640f84719658d5c7ce195b10060cc37292ce79" name = "github.com/golang/snappy" packages = ["."] - pruneopts = "UT" revision = "2a8bb927dd31d8daada140a5d09578521ce5c36a" version = "v0.0.1" [[projects]] - digest = "1:a848ff8a9a04616f385520da14d031468ad24e4a9a38f84241d92bd045593251" name = "github.com/google/go-github" packages = ["github"] - pruneopts = "UT" revision = "50be09d24ee31a2b0868265e76c24b9545a6eb7a" [[projects]] - digest = "1:a63cff6b5d8b95638bfe300385d93b2a6d9d687734b863da8e09dc834510a690" name = "github.com/google/go-querystring" packages = ["query"] - pruneopts = "UT" revision = "44c6ddd0a2342c386950e880b658017258da92fc" version = "v1.0.0" [[projects]] branch = "master" - digest = "1:3ee90c0d94da31b442dde97c99635aaafec68d0b8a3c12ee2075c6bdabeec6bb" name = "github.com/google/gofuzz" packages = ["."] - pruneopts = "UT" revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" [[projects]] - digest = "1:856bd1e35f6da8ce5671a5df09d0e89bf01e9b74b3dabb6d097d39b3813801e1" name = "github.com/googleapis/gax-go" packages = ["v2"] - pruneopts = "UT" - revision = "c8a15bac9b9fe955bd9f900272f9a306465d28cf" - version = "v2.0.3" + revision = "beaecbbdd8af86aa3acf14180d53828ce69400b2" + version = "v2.0.4" [[projects]] - digest = "1:65c4414eeb350c47b8de71110150d0ea8a281835b1f386eacaa3ad7325929c21" name = "github.com/googleapis/gnostic" packages = [ "OpenAPIv2", "compiler", - "extensions", + "extensions" ] - pruneopts = "UT" revision = "7c663266750e7d82587642f65e60bc4083f1f84e" version = "v0.2.0" [[projects]] branch = "master" - digest = "1:f14d1b50e0075fb00177f12a96dd7addf93d1e2883c25befd17285b779549795" name = "github.com/gopherjs/gopherjs" packages = ["js"] - pruneopts = "UT" revision = "847fc94819f9d5a4e7154e2203b36f6dbace6f48" [[projects]] - digest = "1:7b5c6e2eeaa9ae5907c391a91c132abfd5c9e8a784a341b5625e750c67e6825d" name = "github.com/gorilla/websocket" packages = ["."] - pruneopts = "UT" revision = "66b9c49e59c6c48f0ffce28c2d8b8a5678502c6d" version = "v1.4.0" [[projects]] - digest = "1:f14364057165381ea296e49f8870a9ffce2b8a95e34d6ae06c759106aaef428c" name = "github.com/hashicorp/go-uuid" packages = ["."] - pruneopts = "UT" revision = "4f571afc59f3043a65f8fe6bf46d887b10a01d43" version = "v1.0.1" [[projects]] - digest = "1:d15ee511aa0f56baacc1eb4c6b922fa1c03b38413b6be18166b996d82a0156ea" name = "github.com/hashicorp/golang-lru" packages = [ ".", - "simplelru", + "simplelru" ] - pruneopts = "UT" revision = "7087cb70de9f7a8bc0a10c375cb0d2280a8edf9c" version = "v0.5.1" [[projects]] branch = "master" - digest = "1:0778dc7fce1b4669a8bfa7ae506ec1f595b6ab0f8989c1c0d22a8ca1144e9972" name = "github.com/howeyc/gopass" packages = ["."] - pruneopts = "UT" revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8" [[projects]] - digest = "1:a0cefd27d12712af4b5018dc7046f245e1e3b5760e2e848c30b171b570708f9b" name = "github.com/imdario/mergo" packages = ["."] - pruneopts = "UT" revision = "7c29201646fa3de8506f701213473dd407f19646" version = "v0.3.7" [[projects]] branch = "master" - digest = "1:62fe3a7ea2050ecbd753a71889026f83d73329337ada66325cbafd5dea5f713d" name = "github.com/jbenet/go-context" packages = ["io"] - pruneopts = "UT" revision = "d14ea06fba99483203c19d92cfcd13ebe73135f4" [[projects]] branch = "master" - digest = "1:ae221758bdddd57f5c76f4ee5e4110af32ee62583c46299094697f8f127e63da" name = "github.com/jcmturner/gofork" packages = [ "encoding/asn1", - "x/crypto/pbkdf2", + "x/crypto/pbkdf2" ] - pruneopts = "UT" revision = "2aebee971930cd0dd525873330952ab7df5ac95c" [[projects]] - digest = "1:bb81097a5b62634f3e9fec1014657855610c82d19b9a40c17612e32651e35dca" name = "github.com/jmespath/go-jmespath" packages = ["."] - pruneopts = "UT" revision = "c2b33e84" [[projects]] branch = "master" - digest = "1:3daa28dd53624e04229a3499b6bb547b4c467d488e8293b1fc9d67a922713896" name = "github.com/joncalhoun/qson" packages = ["."] - pruneopts = "UT" revision = "8a9cab3a62b1b693e7dfa590a215dc6217552803" [[projects]] - digest = "1:3e551bbb3a7c0ab2a2bf4660e7fcad16db089fdcfbb44b0199e62838038623ea" name = "github.com/json-iterator/go" packages = ["."] - pruneopts = "UT" - revision = "1624edc4454b8682399def8740d46db5e4362ba4" - version = "v1.1.5" + revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29" + version = "v1.1.6" [[projects]] - digest = "1:4b63210654b1f2b664f74ec434a1bb1cb442b3d75742cc064a10808d1cca6361" name = "github.com/jtolds/gls" packages = ["."] - pruneopts = "UT" revision = "b4936e06046bbecbb94cae9c18127ebe510a2cb9" version = "v4.20" [[projects]] - digest = "1:ae5f4d0779a45e2cb3075d8b3ece6c623e171407f4aac83521392ff06d188871" name = "github.com/kevinburke/ssh_config" packages = ["."] - pruneopts = "UT" revision = "81db2a75821ed34e682567d48be488a1c3121088" version = "0.5" [[projects]] - digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de" name = "github.com/konsorten/go-windows-terminal-sequences" packages = ["."] - pruneopts = "UT" revision = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e" version = "v1.0.2" [[projects]] branch = "master" - digest = "1:84a5a2b67486d5d67060ac393aa255d05d24ed5ee41daecd5635ec22657b6492" name = "github.com/mailru/easyjson" packages = [ "buffer", "jlexer", - "jwriter", + "jwriter" ] - pruneopts = "UT" - revision = "6243d8e04c3f819e79757e8bc3faa15c3cb27003" + revision = "1de009706dbeb9d05f18586f0735fcdb7c524481" [[projects]] - digest = "1:523ffd935398ef4979acbf085e52c624a82f49643bc6dadbe5ea824904cd49be" name = "github.com/minio/minio-go" packages = [ ".", @@ -508,285 +411,238 @@ "pkg/encrypt", "pkg/s3signer", "pkg/s3utils", - "pkg/set", + "pkg/set" ] - pruneopts = "UT" - revision = "59af836a7e6d99cbefa093475fbde0a4552d483f" - version = "v6.0.19" + revision = "5df22878d3cdee48fbb086449268b1a465147c7d" + version = "v6.0.20" [[projects]] - digest = "1:5d231480e1c64a726869bc4142d270184c419749d34f167646baa21008eb0a79" name = "github.com/mitchellh/go-homedir" packages = ["."] - pruneopts = "UT" revision = "af06845cf3004701891bf4fdb884bfe4920b3727" version = "v1.1.0" [[projects]] - digest = "1:33422d238f147d247752996a26574ac48dcf472976eda7f5134015f06bf16563" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe" + version = "v1.1.2" + +[[projects]] name = "github.com/modern-go/concurrent" packages = ["."] - pruneopts = "UT" revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" version = "1.0.3" [[projects]] - digest = "1:e32bdbdb7c377a07a9a46378290059822efdce5c8d96fe71940d87cb4f918855" name = "github.com/modern-go/reflect2" packages = ["."] - pruneopts = "UT" revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" version = "1.0.1" [[projects]] - digest = "1:2ca73053216eb11c8eea2855c8099ad82773638522f91cc0542ec9759163ff3c" name = "github.com/nats-io/go-nats" packages = [ ".", "encoders/builtin", - "util", + "util" ] - pruneopts = "UT" revision = "70fe06cee50d4b6f98248d9675fb55f2a3aa7228" version = "v1.7.2" [[projects]] - branch = "master" - digest = "1:2b25e23b79eae544e51411619beb9e32d6a7e70d8ef7ae48b453d3991626d0e3" name = "github.com/nats-io/go-nats-streaming" packages = [ ".", - "pb", + "pb" ] - pruneopts = "UT" - revision = "82824caf82d8e87d762226c5060006dfbd97107f" + revision = "4366d43a0648b4997ed32080f937e8702ab86c48" + version = "v0.4.2" [[projects]] - digest = "1:0b5d91120efc54504bc253fda90b08c4be88cd78a4023ef60019e95bb0cdc136" name = "github.com/nats-io/nkeys" packages = ["."] - pruneopts = "UT" revision = "1546a3320a8f195a5b5c84aef8309377c2e411d5" version = "v0.0.2" [[projects]] - digest = "1:c3cd663f2f30b92536b9f290ac85c6310dae36a14cb8961553ae9ccf0d85ae41" name = "github.com/nats-io/nuid" packages = ["."] - pruneopts = "UT" revision = "289cccf02c178dc782430d534e3c1f5b72af807f" version = "v1.0.0" [[projects]] branch = "master" - digest = "1:6dd624a8671468c160bae2737e8f4976741cb76b86c15153242097e1b3e36a0e" name = "github.com/nlopes/slack" packages = [ ".", "slackevents", - "slackutilsx", + "slackutilsx" ] - pruneopts = "UT" revision = "71a00675abf36a35bb4ff7c0fdd3172c9b191b23" [[projects]] - digest = "1:b2ee62e09bec113cf086d2ce0769efcc7bf79481aba8373fd8f7884e94df3462" name = "github.com/pelletier/go-buffruneio" packages = ["."] - pruneopts = "UT" revision = "c37440a7cf42ac63b919c752ca73a85067e05992" version = "v0.2.0" [[projects]] - digest = "1:d4c88b5ad20151a96c1e5a55547a944b6af623aa315f69ee0d172b00f95d27fb" name = "github.com/pierrec/lz4" packages = [ ".", - "internal/xxh32", + "internal/xxh32" ] - pruneopts = "UT" revision = "062282ea0dcff40c9fb8525789eef9644b1fbd6e" version = "v2.1.0" [[projects]] - digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b" name = "github.com/pkg/errors" packages = ["."] - pruneopts = "UT" revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" version = "v0.8.1" [[projects]] - digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" name = "github.com/pmezard/go-difflib" packages = ["difflib"] - pruneopts = "UT" revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" [[projects]] branch = "master" - digest = "1:d38f81081a389f1466ec98192cf9115a82158854d6f01e1c23e2e7554b97db71" name = "github.com/rcrowley/go-metrics" packages = ["."] - pruneopts = "UT" revision = "3113b8401b8a98917cde58f8bbd42a1b1c03b1fd" [[projects]] - digest = "1:ed615c5430ecabbb0fb7629a182da65ecee6523900ac1ac932520860878ffcad" name = "github.com/robfig/cron" packages = ["."] - pruneopts = "UT" revision = "b41be1df696709bb6395fe435af20370037c0b4c" version = "v1.1" [[projects]] - digest = "1:9be615b2a72fc4a99e623c6776cce3afe3451741c34ea1805ea4a9b58604b9df" name = "github.com/rs/zerolog" packages = [ ".", "internal/cbor", - "internal/json", + "internal/json" ] - pruneopts = "UT" revision = "6d6350a51143b5c0d0a6a3b736ee2b41315f7269" version = "v1.12.0" [[projects]] - digest = "1:274f67cb6fed9588ea2521ecdac05a6d62a8c51c074c1fccc6a49a40ba80e925" name = "github.com/satori/go.uuid" packages = ["."] - pruneopts = "UT" revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" version = "v1.2.0" [[projects]] - digest = "1:d917313f309bda80d27274d53985bc65651f81a5b66b820749ac7f8ef061fd04" name = "github.com/sergi/go-diff" packages = ["diffmatchpatch"] - pruneopts = "UT" revision = "1744e2970ca51c86172c8190fadad617561ed6e7" version = "v1.0.0" [[projects]] - digest = "1:e4c72127d910a96daf869a44f3dd563b86dbe6931a172863a0e99c5ff04b59e4" name = "github.com/sirupsen/logrus" packages = ["."] - pruneopts = "UT" revision = "dae0fa8d5b0c810a8ab733fbd5510c7cae84eca4" version = "v1.4.0" [[projects]] - digest = "1:cc1c574c9cb5e99b123888c12b828e2d19224ab6c2244bda34647f230bf33243" name = "github.com/smartystreets/assertions" packages = [ ".", "internal/go-render/render", - "internal/oglematchers", + "internal/oglematchers" ] - pruneopts = "UT" revision = "7678a5452ebea5b7090a6b163f844c133f523da2" version = "1.8.3" [[projects]] - digest = "1:a3e081e593ee8e3b0a9af6a5dcac964c67a40c4f2034b5345b2ad78d05920728" name = "github.com/smartystreets/goconvey" packages = [ "convey", "convey/gotest", - "convey/reporting", + "convey/reporting" ] - pruneopts = "UT" revision = "9e8dc3f972df6c8fcc0375ef492c24d0bb204857" version = "1.6.3" [[projects]] - digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2" name = "github.com/spf13/pflag" packages = ["."] - pruneopts = "UT" revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" [[projects]] - digest = "1:e4ed0afd67bf7be353921665cdac50834c867ff1bba153efc0745b755a7f5905" name = "github.com/src-d/gcfg" packages = [ ".", "scanner", "token", - "types", + "types" ] - pruneopts = "UT" revision = "1ac3a1ac202429a54835fe8408a92880156b489d" version = "v1.4.0" [[projects]] branch = "master" - digest = "1:baa0e36ba787113501e02a40cd45e3d17b216285bbaa3dabbc1b26e626ab4a39" name = "github.com/streadway/amqp" packages = ["."] - pruneopts = "UT" - revision = "61ee40d2027bce731de63888bdbf60a72ea173d2" + revision = "14f78b41ce6da3d698c2ef2cc8c0ea7ce9e26688" + +[[projects]] + name = "github.com/stretchr/objx" + packages = ["."] + revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c" + version = "v0.1.1" [[projects]] - digest = "1:972c2427413d41a1e06ca4897e8528e5a1622894050e2f527b38ddf0f343f759" name = "github.com/stretchr/testify" - packages = ["assert"] - pruneopts = "UT" + packages = [ + "assert", + "mock" + ] revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" version = "v1.3.0" [[projects]] - digest = "1:7df351557a6d5c30804e7d6f7ed87f2fccb0619c08fcc84869a93f22bec96c11" name = "github.com/tidwall/gjson" packages = ["."] - pruneopts = "UT" revision = "eee0b6226f0d1db2675a176fdfaa8419bcad4ca8" version = "v1.2.1" [[projects]] - digest = "1:8453ddbed197809ee8ca28b06bd04e127bec9912deb4ba451fea7a1eca578328" name = "github.com/tidwall/match" packages = ["."] - pruneopts = "UT" revision = "33827db735fff6510490d69a8622612558a557ed" version = "v1.0.1" [[projects]] branch = "master" - digest = "1:88611438dc87bda5862e2d12d8e901bac8ebfd4a9034a896d2f69835360439a7" name = "github.com/tidwall/pretty" packages = ["."] - pruneopts = "UT" revision = "65a9db5fad5105a89e17f38adcc9878685be6d78" [[projects]] - digest = "1:b70c951ba6fdeecfbd50dabe95aa5e1b973866ae9abbece46ad60348112214f2" name = "github.com/tidwall/sjson" packages = ["."] - pruneopts = "UT" revision = "25fb082a20e29e83fb7b7ef5f5919166aad1f084" version = "v1.0.4" [[projects]] - digest = "1:4819c884cfecb14c05d2bb631b249c308539f811a3b1f2b2a99a38ce5ee0cd8c" name = "github.com/xanzy/go-gitlab" packages = ["."] - pruneopts = "UT" - revision = "ecd7ce0de62a071b909aca86854d251e95497b90" - version = "v0.16.0" + revision = "be70cf752294cc5c6ee89a18d6ba0caca08aa5c7" + version = "v0.16.1" [[projects]] - digest = "1:172f94a6b3644a8f9e6b5e5b7fc9fe1e42d424f52a0300b2e7ab1e57db73f85d" name = "github.com/xanzy/ssh-agent" packages = ["."] - pruneopts = "UT" revision = "6a3e2ff9e7c564f36873c2e36413f634534f1c44" version = "v0.2.1" [[projects]] - digest = "1:1381b8539f9abce35487c1df5619c42d6920073a98aab88b68f33a4c8a0c7acc" name = "go.opencensus.io" packages = [ ".", @@ -803,15 +659,13 @@ "trace", "trace/internal", "trace/propagation", - "trace/tracestate", + "trace/tracestate" ] - pruneopts = "UT" revision = "f305e5c4e2cf345eba88de13d10de1126fa45a61" version = "v0.19.1" [[projects]] branch = "master" - digest = "1:7efe22127f18ed47cffc2d564f09d18695ac5396352e6a41be197b5d3ae6ee23" name = "golang.org/x/crypto" packages = [ "argon2", @@ -834,14 +688,12 @@ "ssh", "ssh/agent", "ssh/knownhosts", - "ssh/terminal", + "ssh/terminal" ] - pruneopts = "UT" - revision = "c2843e01d9a2bc60bb26ad24e09734fdc2d9ec58" + revision = "a1f597ede03a7bef967a422b5b3a5bd08805a01e" [[projects]] branch = "master" - digest = "1:75634c8443f7435a3d0c5e936d5935b48523c831130b60d67d42df8a1dfd6c14" name = "golang.org/x/net" packages = [ "context", @@ -855,50 +707,42 @@ "proxy", "publicsuffix", "trace", - "websocket", + "websocket" ] - pruneopts = "UT" - revision = "d8887717615a059821345a5c23649351b52a1c0b" + revision = "9f648a60d9775ef5c977e7669d1673a7a67bef33" [[projects]] branch = "master" - digest = "1:5e9f22cf754ab20a5dff0ae04b12516b112c5b81cd44dccccde148865084d730" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "UT" revision = "e64efc72b421e893cbf63f17ba2221e7d6d0b0f3" [[projects]] branch = "master" - digest = "1:04a5b0e4138f98eef79ce12a955a420ee358e9f787044cc3a553ac3c3ade997e" name = "golang.org/x/sync" packages = [ "errgroup", - "semaphore", + "semaphore" ] - pruneopts = "UT" revision = "e225da77a7e68af35c70ccbf71af2b83e6acac3c" [[projects]] branch = "master" - digest = "1:426092407910bee4a539be5d377abbaf629bae216c8eb2f80409c8cbe2647508" name = "golang.org/x/sys" packages = [ "cpu", "unix", - "windows", + "windows" ] - pruneopts = "UT" revision = "fead79001313d15903fb4605b4a1b781532cd93e" [[projects]] - digest = "1:0c56024909189aee3364b7f21a95a27459f718aa7c199a5c111c36cfffd9eaef" name = "golang.org/x/text" packages = [ "collate", @@ -915,23 +759,19 @@ "unicode/cldr", "unicode/norm", "unicode/rangetable", - "width", + "width" ] - pruneopts = "UT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" - digest = "1:9fdc2b55e8e0fafe4b41884091e51e77344f7dc511c5acedcfd98200003bff90" name = "golang.org/x/time" packages = ["rate"] - pruneopts = "UT" revision = "9d24e82272b4f38b78bc8cff74fa936d31ccd8ef" [[projects]] branch = "master" - digest = "1:e46d8e20161401a9cf8765dfa428494a3492a0b56fe114156b7da792bf41ba78" name = "golang.org/x/tools" packages = [ "go/ast/astutil", @@ -945,13 +785,11 @@ "internal/fastwalk", "internal/gopathwalk", "internal/module", - "internal/semver", + "internal/semver" ] - pruneopts = "UT" - revision = "5c2858a9cfe5880270ceee8da4391f3c44612b47" + revision = "1286b2016bb195031cab5657d3244bc996b3f2dd" [[projects]] - digest = "1:2e81813e8e072aa700e101369890e55539729d817d32dbc3fab228d6b40c4d83" name = "google.golang.org/api" packages = [ "googleapi/transport", @@ -962,14 +800,12 @@ "transport", "transport/grpc", "transport/http", - "transport/http/internal/propagation", + "transport/http/internal/propagation" ] - pruneopts = "UT" - revision = "19e022d8cf43ce81f046bae8cc18c5397cc7732f" - version = "v0.1.0" + revision = "e742f5a8defa1f9f5d723dfa04c962e680dc33f0" + version = "v0.2.0" [[projects]] - digest = "1:c4eaa5f79d36f76ef4bd0c4f96e36bc1b7b5a359528d1267f0cb7a5d58b7b5bb" name = "google.golang.org/appengine" packages = [ ".", @@ -983,28 +819,24 @@ "internal/socket", "internal/urlfetch", "socket", - "urlfetch", + "urlfetch" ] - pruneopts = "UT" revision = "e9657d882bb81064595ca3b56cbe2546bbabf7b1" version = "v1.4.0" [[projects]] branch = "master" - digest = "1:7ba623745e0f553da646f5f7c1338fa271c91c4be1cf1a9978369216f7be0c5b" name = "google.golang.org/genproto" packages = [ "googleapis/api/annotations", "googleapis/iam/v1", "googleapis/pubsub/v1", "googleapis/rpc/status", - "protobuf/field_mask", + "protobuf/field_mask" ] - pruneopts = "UT" revision = "5fe7a883aa19554f42890211544aa549836af7b7" [[projects]] - digest = "1:9153ffce82afcac3bf963f2aac8df53a34859e293e7329b00ef42eea00fe100f" name = "google.golang.org/grpc" packages = [ ".", @@ -1038,46 +870,36 @@ "resolver/passthrough", "stats", "status", - "tap", + "tap" ] - pruneopts = "UT" revision = "2fdaae294f38ed9a121193c51ec99fecd3b13eb7" version = "v1.19.0" [[projects]] - digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" name = "gopkg.in/inf.v0" packages = ["."] - pruneopts = "UT" revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" version = "v0.9.1" [[projects]] - digest = "1:d37c61a335d13bc49b3f90e9e13c8686e4548839b69c58549e727afb2245c454" name = "gopkg.in/ini.v1" packages = ["."] - pruneopts = "UT" revision = "c85607071cf08ca1adaf48319cd1aa322e81d8c1" version = "v1.42.0" [[projects]] - digest = "1:c902038ee2d6f964d3b9f2c718126571410c5d81251cbab9fe58abd37803513c" name = "gopkg.in/jcmturner/aescts.v1" packages = ["."] - pruneopts = "UT" revision = "f6abebb3171c4c1b1fea279cb7c7325020a26290" version = "v1.0.1" [[projects]] - digest = "1:a1a3e185c03d79a7452d5d5b4c91be4cc433f55e6ed3a35233d852c966e39013" name = "gopkg.in/jcmturner/dnsutils.v1" packages = ["."] - pruneopts = "UT" revision = "13eeb8d49ffb74d7a75784c35e4d900607a3943c" version = "v1.0.1" [[projects]] - digest = "1:653c1ef9be253f28c38612cc0fb0571dd440a3d61a97f82e6205d53942a7b4a9" name = "gopkg.in/jcmturner/gokrb5.v5" packages = [ "asn1tools", @@ -1110,36 +932,30 @@ "messages", "mstypes", "pac", - "types", + "types" ] - pruneopts = "UT" revision = "32ba44ca5b42f17a4a9f33ff4305e70665a1bc0f" version = "v5.3.0" [[projects]] - digest = "1:917e312d1c83bac01db5771433a141f7e4754df0ebe83d2e8edc821320aff849" name = "gopkg.in/jcmturner/rpc.v0" packages = ["ndr"] - pruneopts = "UT" revision = "4480c480c9cd343b54b0acb5b62261cbd33d7adf" version = "v0.0.2" [[projects]] - digest = "1:866df945fc92cd221d2b384dca7de5f3131a6113b9f72a7a8019ae5046abe828" name = "gopkg.in/src-d/go-billy.v4" packages = [ ".", "helper/chroot", "helper/polyfill", "osfs", - "util", + "util" ] - pruneopts = "UT" revision = "982626487c60a5252e7d0b695ca23fb0fa2fd670" version = "v4.3.0" [[projects]] - digest = "1:44801e4be7066a82dc7a7f608d31f99c5c0f5a65a0215b37401a5657ce52940d" name = "gopkg.in/src-d/go-git.v4" packages = [ ".", @@ -1182,31 +998,25 @@ "utils/merkletrie/filesystem", "utils/merkletrie/index", "utils/merkletrie/internal/frame", - "utils/merkletrie/noder", + "utils/merkletrie/noder" ] - pruneopts = "UT" revision = "db6c41c156481962abf9a55a324858674c25ab08" version = "v4.10.0" [[projects]] - digest = "1:78d374b493e747afa9fbb2119687e3740a7fb8d0ebabddfef0a012593aaecbb3" name = "gopkg.in/warnings.v0" packages = ["."] - pruneopts = "UT" revision = "ec4a0fea49c7b46c2aeb0b51aac55779c607e52b" version = "v0.1.2" [[projects]] - digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" name = "gopkg.in/yaml.v2" packages = ["."] - pruneopts = "UT" revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" version = "v2.2.2" [[projects]] branch = "release-1.10" - digest = "1:6ba59e3d220d8f97e1b5e76e20f3f8ef994e8fb43b12fffe404fefbb86249c9a" name = "k8s.io/api" packages = [ "admissionregistration/v1alpha1", @@ -1236,14 +1046,12 @@ "settings/v1alpha1", "storage/v1", "storage/v1alpha1", - "storage/v1beta1", + "storage/v1beta1" ] - pruneopts = "UT" revision = "c89978d5f86d7427bef2fc7752732c8c60b1d188" [[projects]] branch = "release-1.10" - digest = "1:84da4ce0ecdb4438fcd265025c4439685f6cb81550e9b8021bf67bfdb98585e7" name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -1283,14 +1091,12 @@ "pkg/util/yaml", "pkg/version", "pkg/watch", - "third_party/forked/golang/reflect", + "third_party/forked/golang/reflect" ] - pruneopts = "UT" revision = "d49e237a2683fa6dc43a86c7b1b766e0219fb6e7" [[projects]] branch = "release-7.0" - digest = "1:7336dcb25cac9940ac84ea6c59c4c36d1b6b6ca4a3aba38d6d8c74bc53699a40" name = "k8s.io/client-go" packages = [ "discovery", @@ -1443,14 +1249,12 @@ "util/homedir", "util/integer", "util/retry", - "util/workqueue", + "util/workqueue" ] - pruneopts = "UT" revision = "36368dede29baa5ecd253416d70ddc0c76bde69b" [[projects]] branch = "release-1.10" - digest = "1:34dc31e1809c951ca635f1e593088b43ad347ba379121b631961bf22737884bb" name = "k8s.io/code-generator" packages = [ "cmd/client-gen", @@ -1477,13 +1281,11 @@ "cmd/openapi-gen", "cmd/openapi-gen/args", "pkg/util", - "third_party/forked/golang/reflect", + "third_party/forked/golang/reflect" ] - pruneopts = "T" revision = "edc41f23fa918716df540b1486477d62237010e4" [[projects]] - digest = "1:a9f99f1c11620be972d49d2e4e296031a5fbc168ada49a9e618d9b35f751f119" name = "k8s.io/gengo" packages = [ "args", @@ -1494,130 +1296,31 @@ "generator", "namer", "parser", - "types", + "types" ] - pruneopts = "T" revision = "b90029ef6cd877cb3f422d75b3a07707e3aac6b7" [[projects]] - digest = "1:72fd56341405f53c745377e0ebc4abeff87f1a048e0eea6568a20212650f5a82" name = "k8s.io/klog" packages = ["."] - pruneopts = "UT" revision = "71442cd4037d612096940ceb0f3fec3f7fff66e0" version = "v0.2.0" [[projects]] branch = "master" - digest = "1:64b9d42751d0965263661eb9d07be8ee56ab5df05e27a5f092d42e6fa3b37b08" name = "k8s.io/kube-openapi" packages = [ "cmd/openapi-gen/args", "pkg/common", "pkg/generators", "pkg/generators/rules", - "pkg/util/sets", + "pkg/util/sets" ] - pruneopts = "UT" revision = "15615b16d372105f0c69ff47dfe7402926a65aaa" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "cloud.google.com/go/pubsub", - "github.com/Knetic/govaluate", - "github.com/Shopify/sarama", - "github.com/adlio/trello", - "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1", - "github.com/aws/aws-sdk-go/aws", - "github.com/aws/aws-sdk-go/aws/credentials", - "github.com/aws/aws-sdk-go/aws/session", - "github.com/aws/aws-sdk-go/service/sns", - "github.com/aws/aws-sdk-go/service/sqs", - "github.com/colinmarc/hdfs", - "github.com/eclipse/paho.mqtt.golang", - "github.com/fsnotify/fsnotify", - "github.com/ghodss/yaml", - "github.com/go-openapi/spec", - "github.com/gogo/protobuf/proto", - "github.com/gogo/protobuf/protoc-gen-gofast", - "github.com/gogo/protobuf/protoc-gen-gogofast", - "github.com/gogo/protobuf/sortkeys", - "github.com/golang/glog", - "github.com/golang/protobuf/proto", - "github.com/golang/protobuf/protoc-gen-go", - "github.com/google/go-github/github", - "github.com/joncalhoun/qson", - "github.com/minio/minio-go", - "github.com/nats-io/go-nats", - "github.com/nats-io/go-nats-streaming", - "github.com/nlopes/slack/slackevents", - "github.com/pkg/errors", - "github.com/robfig/cron", - "github.com/rs/zerolog", - "github.com/satori/go.uuid", - "github.com/sirupsen/logrus", - "github.com/smartystreets/goconvey/convey", - "github.com/streadway/amqp", - "github.com/stretchr/testify/assert", - "github.com/tidwall/gjson", - "github.com/tidwall/sjson", - "github.com/xanzy/go-gitlab", - "golang.org/x/crypto/ssh", - "google.golang.org/api/option", - "google.golang.org/grpc", - "google.golang.org/grpc/connectivity", - "gopkg.in/jcmturner/gokrb5.v5/client", - "gopkg.in/jcmturner/gokrb5.v5/config", - "gopkg.in/jcmturner/gokrb5.v5/credentials", - "gopkg.in/jcmturner/gokrb5.v5/keytab", - "gopkg.in/src-d/go-git.v4", - "gopkg.in/src-d/go-git.v4/config", - "gopkg.in/src-d/go-git.v4/plumbing", - "gopkg.in/src-d/go-git.v4/plumbing/transport", - "gopkg.in/src-d/go-git.v4/plumbing/transport/http", - "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh", - "k8s.io/api/core/v1", - "k8s.io/apimachinery/pkg/api/errors", - "k8s.io/apimachinery/pkg/api/meta", - "k8s.io/apimachinery/pkg/apis/meta/v1", - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured", - "k8s.io/apimachinery/pkg/fields", - "k8s.io/apimachinery/pkg/labels", - "k8s.io/apimachinery/pkg/runtime", - "k8s.io/apimachinery/pkg/runtime/schema", - "k8s.io/apimachinery/pkg/runtime/serializer", - "k8s.io/apimachinery/pkg/selection", - "k8s.io/apimachinery/pkg/types", - "k8s.io/apimachinery/pkg/util/intstr", - "k8s.io/apimachinery/pkg/util/wait", - "k8s.io/apimachinery/pkg/watch", - "k8s.io/client-go/discovery", - "k8s.io/client-go/discovery/fake", - "k8s.io/client-go/dynamic", - "k8s.io/client-go/dynamic/fake", - "k8s.io/client-go/informers", - "k8s.io/client-go/informers/core/v1", - "k8s.io/client-go/kubernetes", - "k8s.io/client-go/kubernetes/fake", - "k8s.io/client-go/kubernetes/scheme", - "k8s.io/client-go/rest", - "k8s.io/client-go/testing", - "k8s.io/client-go/tools/cache", - "k8s.io/client-go/tools/clientcmd", - "k8s.io/client-go/util/flowcontrol", - "k8s.io/client-go/util/workqueue", - "k8s.io/code-generator/cmd/client-gen", - "k8s.io/code-generator/cmd/deepcopy-gen", - "k8s.io/code-generator/cmd/defaulter-gen", - "k8s.io/code-generator/cmd/go-to-protobuf", - "k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo", - "k8s.io/code-generator/cmd/informer-gen", - "k8s.io/code-generator/cmd/lister-gen", - "k8s.io/code-generator/cmd/openapi-gen", - "k8s.io/gengo/examples/deepcopy-gen", - "k8s.io/kube-openapi/pkg/common", - ] + inputs-digest = "c293ab2c7a55af4a7da20b9f2d4944243d7405988de952dc92bed3596dc25205" solver-name = "gps-cdcl" solver-version = 1 diff --git a/README.md b/README.md index 6eccaab7e2..b973b76379 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![slack](https://img.shields.io/badge/slack-argoproj-brightgreen.svg?logo=slack)](https://argoproj.github.io/community/join-slack) [![Build Status](https://travis-ci.org/argoproj/argo-events.svg?branch=master)](https://travis-ci.org/argoproj/argo-events) [![Coverage Status](https://coveralls.io/repos/github/argoproj/argo-events/badge.svg)](https://coveralls.io/github/argoproj/argo-events) -[![GoDoc](https://godoc.org/github.com/argoproj/argo-events?status.svg)](https://godoc.org/github.com/argoproj/argo-events/pkg/apis) +[![GoDoc](https://godoc.org/github.com/argoproj/argo-events?status.svg)](https://godoc.org/github.com/argoproj/argo-events/pkg/apis) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
diff --git a/common/util.go b/common/util.go index 66c6f6168f..7dea2bf5c9 100644 --- a/common/util.go +++ b/common/util.go @@ -44,8 +44,8 @@ func DefaultServiceName(serviceName string) string { return fmt.Sprintf("%s-svc", serviceName) } -// DefaultGatewayConfigurationName returns a formulated name for a gateway configuration -func DefaultGatewayConfigurationName(gatewayName string, configurationName string) string { +// DefaultEventSourceName returns a formulated name for a gateway configuration +func DefaultEventSourceName(gatewayName string, configurationName string) string { return fmt.Sprintf("%s:%s", gatewayName, configurationName) } @@ -88,6 +88,12 @@ func SendErrorResponse(writer http.ResponseWriter, response string) { writer.Write([]byte(response)) } +// SendInternalErrorResponse sends http internal error response +func SendInternalErrorResponse(writer http.ResponseWriter, response string) { + writer.WriteHeader(http.StatusInternalServerError) + writer.Write([]byte(response)) +} + // LoggerConf returns standard logging configuration func LoggerConf() zerolog.ConsoleWriter { output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339} diff --git a/common/util_test.go b/common/util_test.go index 622d959fb8..7d3592b875 100644 --- a/common/util_test.go +++ b/common/util_test.go @@ -17,9 +17,10 @@ limitations under the License. package common import ( - "testing" - + "fmt" "github.com/smartystreets/goconvey/convey" + "net/http" + "testing" "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" @@ -27,6 +28,24 @@ import ( "k8s.io/client-go/kubernetes/fake" ) +type fakeHttpWriter struct { + header int + payload []byte +} + +func (f *fakeHttpWriter) Header() http.Header { + return http.Header{} +} + +func (f *fakeHttpWriter) Write(body []byte) (int, error) { + f.payload = body + return len(body), nil +} + +func (f *fakeHttpWriter) WriteHeader(status int) { + f.header = status +} + func TestGetObjectHash(t *testing.T) { convey.Convey("Given a value, hash it", t, func() { hash, err := GetObjectHash(&corev1.Pod{}) @@ -47,6 +66,36 @@ func TestDefaultConfigMapName(t *testing.T) { assert.Equal(t, "sensor-controller-configmap", res) } +func TestDefaultServiceName(t *testing.T) { + convey.Convey("Given a service, get the default name", t, func() { + convey.So(DefaultServiceName("default"), convey.ShouldEqual, fmt.Sprintf("%s-svc", "default")) + }) +} + +func TestDefaultNatsQueueName(t *testing.T) { + convey.Convey("Given a nats queue, get the default name", t, func() { + convey.So(DefaultNatsQueueName("default"), convey.ShouldEqual, "default-queue") + }) +} + +func TestHTTPMethods(t *testing.T) { + convey.Convey("Given a http write", t, func() { + convey.Convey("Write a success response", func() { + f := &fakeHttpWriter{} + SendSuccessResponse(f, "hello") + convey.So(string(f.payload), convey.ShouldEqual, "hello") + convey.So(f.header, convey.ShouldEqual, http.StatusOK) + }) + + convey.Convey("Write a failure response", func() { + f := &fakeHttpWriter{} + SendErrorResponse(f, "failure") + convey.So(string(f.payload), convey.ShouldEqual, "failure") + convey.So(f.header, convey.ShouldEqual, http.StatusBadRequest) + }) + }) +} + func TestServerResourceForGroupVersionKind(t *testing.T) { convey.Convey("Given a k8s client", t, func() { fakeClient := fake.NewSimpleClientset() diff --git a/controllers/gateway/state_test.go b/controllers/gateway/state_test.go new file mode 100644 index 0000000000..cced645eb9 --- /dev/null +++ b/controllers/gateway/state_test.go @@ -0,0 +1,44 @@ +package gateway + +import ( + "testing" + + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/pkg/client/gateway/clientset/versioned/fake" + "github.com/smartystreets/goconvey/convey" +) + +func TestPersistUpdates(t *testing.T) { + convey.Convey("Given a gateway resource", t, func() { + namespace := "argo-events" + client := fake.NewSimpleClientset() + logger := common.GetLoggerContext(common.LoggerConf()).Logger() + gw, err := getGateway() + convey.So(err, convey.ShouldBeNil) + + convey.Convey("Create the gateway", func() { + gw, err = client.ArgoprojV1alpha1().Gateways(namespace).Create(gw) + convey.So(err, convey.ShouldBeNil) + convey.So(gw, convey.ShouldNotBeNil) + + gw.ObjectMeta.Labels = map[string]string{ + "default": "default", + } + + convey.Convey("Update the gateway", func() { + updatedGw, err := PersistUpdates(client, gw, &logger) + convey.So(err, convey.ShouldBeNil) + convey.So(updatedGw, convey.ShouldNotEqual, gw) + convey.So(updatedGw.Labels, convey.ShouldResemble, gw.Labels) + + updatedGw.Labels["new"] = "new" + + convey.Convey("Reapply the gateway", func() { + err := ReapplyUpdates(client, updatedGw) + convey.So(err, convey.ShouldBeNil) + convey.So(len(updatedGw.Labels), convey.ShouldEqual, 2) + }) + }) + }) + }) +} diff --git a/docs/gateway-protocol.md b/docs/gateway-protocol.md index b6869dd737..81933fdf58 100644 --- a/docs/gateway-protocol.md +++ b/docs/gateway-protocol.md @@ -3,7 +3,7 @@ ## Table of Contents -- [github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1/generated.proto](#github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1/generated.proto) +- [pkg/apis/gateway/v1alpha1/generated.proto](#pkg/apis/gateway/v1alpha1/generated.proto) - [Gateway](#github.com.argoproj.argo_events.pkg.apis.gateway.v1alpha1.Gateway) - [GatewayList](#github.com.argoproj.argo_events.pkg.apis.gateway.v1alpha1.GatewayList) - [GatewayNotificationWatcher](#github.com.argoproj.argo_events.pkg.apis.gateway.v1alpha1.GatewayNotificationWatcher) @@ -22,10 +22,10 @@ - +
-## github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1/generated.proto +## pkg/apis/gateway/v1alpha1/generated.proto diff --git a/docs/sensor-protocol.md b/docs/sensor-protocol.md index ce1015269d..8ca4d083d8 100644 --- a/docs/sensor-protocol.md +++ b/docs/sensor-protocol.md @@ -3,7 +3,7 @@ ## Table of Contents -- [github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1/generated.proto](#github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1/generated.proto) +- [pkg/apis/sensor/v1alpha1/generated.proto](#pkg/apis/sensor/v1alpha1/generated.proto) - [ArtifactLocation](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.ArtifactLocation) - [ConfigmapArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.ConfigmapArtifact) - [DataFilter](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.DataFilter) @@ -11,6 +11,9 @@ - [EventDependency](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.EventDependency) - [EventDependencyFilter](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.EventDependencyFilter) - [FileArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.FileArtifact) + - [GitArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitArtifact) + - [GitCreds](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitCreds) + - [GitRemoteConfig](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitRemoteConfig) - [GroupVersionKind](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GroupVersionKind) - [NodeStatus](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.NodeStatus) - [ResourceObject](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.ResourceObject) @@ -36,10 +39,10 @@ - + -## github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1/generated.proto +## pkg/apis/sensor/v1alpha1/generated.proto @@ -56,6 +59,7 @@ ArtifactLocation describes the source location for an external artifact | file | [FileArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.FileArtifact) | optional | | | url | [URLArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.URLArtifact) | optional | | | configmap | [ConfigmapArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.ConfigmapArtifact) | optional | | +| git | [GitArtifact](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitArtifact) | optional | | @@ -165,6 +169,61 @@ FileArtifact contains information about an artifact in a filesystem + + +### GitArtifact +GitArtifact contains information about an artifact stored in git + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| url | [string](#string) | optional | Git URL | +| cloneDirectory | [string](#string) | optional | Directory to clone the repository. We clone complete directory because GitArtifact is not limited to any specific Git service providers. Hence we don't use any specific git provider client. | +| creds | [GitCreds](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitCreds) | optional | Creds contain reference to git username and password +optional | +| namespace | [string](#string) | optional | Namespace where creds are stored. +optional | +| sshKeyPath | [string](#string) | optional | SSHKeyPath is path to your ssh key path. Use this if you don't want to provide username and password. ssh key path must be mounted in sensor pod. +optional | +| filePath | [string](#string) | optional | Path to file that contains trigger resource definition | +| branch | [string](#string) | optional | Branch to use to pull trigger resource +optional | +| tag | [string](#string) | optional | Tag to use to pull trigger resource +optional | +| remote | [GitRemoteConfig](#github.com.argoproj.argo_events.pkg.apis.sensor.v1alpha1.GitRemoteConfig) | optional | Git remote to manage set of tracked repositories. Defaults to "origin". Refer https://git-scm.com/docs/git-remote +optional | + + + + + + + + +### GitCreds +GitCreds contain reference to git username and password + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| username | [k8s.io.api.core.v1.SecretKeySelector](#k8s.io.api.core.v1.SecretKeySelector) | optional | | +| password | [k8s.io.api.core.v1.SecretKeySelector](#k8s.io.api.core.v1.SecretKeySelector) | optional | | + + + + + + + + +### GitRemoteConfig + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| name | [string](#string) | optional | Name of the remote to fetch from. | +| urls | [string](#string) | repeated | URLs the URLs of a remote repository. It must be non-empty. Fetch will always use the first URL, while push will use all of them. | + + + + + + ### GroupVersionKind diff --git a/gateways/common/aws.go b/gateways/common/aws.go new file mode 100644 index 0000000000..e9b6fd8769 --- /dev/null +++ b/gateways/common/aws.go @@ -0,0 +1,50 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "github.com/argoproj/argo-events/store" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/session" + corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/kubernetes" +) + +// GetAWSCreds reads credential stored in Kubernetes secrets and return it. +func GetAWSCreds(client kubernetes.Interface, namespace string, access *corev1.SecretKeySelector, secret *corev1.SecretKeySelector) (*credentials.Credentials, error) { + accessKey, err := store.GetSecrets(client, namespace, access.Name, access.Key) + if err != nil { + return nil, err + } + secretKey, err := store.GetSecrets(client, namespace, secret.Name, secret.Key) + if err != nil { + return nil, err + } + + return credentials.NewStaticCredentialsFromCreds(credentials.Value{ + AccessKeyID: accessKey, + SecretAccessKey: secretKey, + }), nil +} + +func GetAWSSession(creds *credentials.Credentials, region string) (*session.Session, error) { + return session.NewSession(&aws.Config{ + Region: ®ion, + Credentials: creds, + }) +} diff --git a/gateways/common/aws_test.go b/gateways/common/aws_test.go new file mode 100644 index 0000000000..d57e6ba75d --- /dev/null +++ b/gateways/common/aws_test.go @@ -0,0 +1,78 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "testing" + + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" +) + +func TestAWS(t *testing.T) { + client := fake.NewSimpleClientset() + namespace := "test" + secretName := "test-secret" + accessKey := "YWNjZXNz" + secretKey := "c2VjcmV0" + LabelAccessKey := "access" + LabelSecretKey := "secret" + + convey.Convey("Given kubernetes secret that hold credentials, create AWS credential", t, func() { + secret, err := client.CoreV1().Secrets(namespace).Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: namespace, + }, + Data: map[string][]byte{ + LabelAccessKey: []byte(accessKey), + LabelSecretKey: []byte(secretKey), + }, + }) + + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + creds, err := GetAWSCreds(client, namespace, &corev1.SecretKeySelector{ + Key: LabelAccessKey, + LocalObjectReference: corev1.LocalObjectReference{ + Name: secretName, + }, + }, &corev1.SecretKeySelector{ + Key: LabelSecretKey, + LocalObjectReference: corev1.LocalObjectReference{ + Name: secretName, + }, + }) + + convey.So(err, convey.ShouldBeNil) + convey.So(creds, convey.ShouldNotBeNil) + + value, err := creds.Get() + convey.So(err, convey.ShouldBeNil) + convey.So(value.AccessKeyID, convey.ShouldEqual, accessKey) + convey.So(value.SecretAccessKey, convey.ShouldEqual, secretKey) + + convey.Convey("Get a new aws session", func() { + session, err := GetAWSSession(creds, "mock-region") + convey.So(err, convey.ShouldBeNil) + convey.So(session, convey.ShouldNotBeNil) + }) + }) +} diff --git a/gateways/common/fake.go b/gateways/common/fake.go new file mode 100644 index 0000000000..e57811ec3a --- /dev/null +++ b/gateways/common/fake.go @@ -0,0 +1,81 @@ +package common + +import ( + "context" + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/gateways" + "google.golang.org/grpc/metadata" + "net/http" +) + +var Hook = &Webhook{ + Endpoint: "/fake", + Port: "12000", + URL: "test-url", +} + +type FakeHttpWriter struct { + HeaderStatus int + Payload []byte +} + +func (f *FakeHttpWriter) Header() http.Header { + return http.Header{} +} + +func (f *FakeHttpWriter) Write(body []byte) (int, error) { + f.Payload = body + return len(body), nil +} + +func (f *FakeHttpWriter) WriteHeader(status int) { + f.HeaderStatus = status +} + +func GetFakeRouteConfig() *RouteConfig { + return &RouteConfig{ + Webhook: Hook, + EventSource: &gateways.EventSource{ + Name: "fake-event-source", + Data: "hello", + Id: "123", + }, + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + Configs: make(map[string]interface{}), + StartCh: make(chan struct{}), + } +} + +type FakeGRPCStream struct { + SentData *gateways.Event + Ctx context.Context +} + +func (f *FakeGRPCStream) Send(event *gateways.Event) error { + f.SentData = event + return nil +} + +func (f *FakeGRPCStream) SetHeader(metadata.MD) error { + return nil +} + +func (f *FakeGRPCStream) SendHeader(metadata.MD) error { + return nil +} + +func (f *FakeGRPCStream) SetTrailer(metadata.MD) { + return +} + +func (f *FakeGRPCStream) Context() context.Context { + return f.Ctx +} + +func (f *FakeGRPCStream) SendMsg(m interface{}) error { + return nil +} + +func (f *FakeGRPCStream) RecvMsg(m interface{}) error { + return nil +} diff --git a/gateways/common/validate_test.go b/gateways/common/validate_test.go new file mode 100644 index 0000000000..5f7f2e5271 --- /dev/null +++ b/gateways/common/validate_test.go @@ -0,0 +1,41 @@ +package common + +import ( + "fmt" + "github.com/ghodss/yaml" + "github.com/smartystreets/goconvey/convey" + "testing" +) + +type fakeEventSource struct { + Msg string `json:"msg"` +} + +func TestValidateGatewayEventSource(t *testing.T) { + convey.Convey("Given an event source, validate it", t, func() { + esStr := ` +msg: "hello" +` + es, err := ValidateGatewayEventSource(esStr, func(s string) (i interface{}, e error) { + t := &fakeEventSource{} + err := yaml.Unmarshal([]byte(esStr), t) + return t, err + }, func(i interface{}) error { + t, ok := i.(*fakeEventSource) + if !ok { + return fmt.Errorf("failed to cast to fake event source") + } + if t == nil { + return fmt.Errorf("event source cant be nil") + } + if t.Msg == "" { + return fmt.Errorf("msg can't be empty") + } + return nil + }) + + convey.So(err, convey.ShouldBeNil) + convey.So(es, convey.ShouldNotBeNil) + convey.So(es.IsValid, convey.ShouldEqual, true) + }) +} diff --git a/gateways/common/webhook.go b/gateways/common/webhook.go index 580cc6dbe9..b8f7578fcc 100644 --- a/gateways/common/webhook.go +++ b/gateways/common/webhook.go @@ -155,7 +155,7 @@ func (rc *RouteConfig) startHttpServer(helper *WebhookHelper) { } else { err = rc.Webhook.srv.ListenAndServeTLS(rc.Webhook.ServerCertPath, rc.Webhook.ServerKeyPath) } - rc.Log.Info().Str("event-source", rc.EventSource.Name).Str("port", rc.Webhook.Port).Msg("http server stopped") + rc.Log.Error().Err(err).Str("event-source", rc.EventSource.Name).Str("port", rc.Webhook.Port).Msg("http server stopped") if err != nil { errChan <- err } diff --git a/gateways/common/webhook_test.go b/gateways/common/webhook_test.go new file mode 100644 index 0000000000..d0c79c0b3a --- /dev/null +++ b/gateways/common/webhook_test.go @@ -0,0 +1,168 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package common + +import ( + "context" + "fmt" + "net/http" + "testing" + "time" + + "github.com/smartystreets/goconvey/convey" +) + +func TestDefaultPostActivate(t *testing.T) { + convey.Convey("Given a route configuration, default post activate should be a no-op", t, func() { + rc := GetFakeRouteConfig() + err := DefaultPostActivate(rc) + convey.So(err, convey.ShouldBeNil) + }) +} + +func TestDefaultPostStop(t *testing.T) { + convey.Convey("Given a route configuration, default post stop should be a no-op", t, func() { + rc := GetFakeRouteConfig() + err := DefaultPostStop(rc) + convey.So(err, convey.ShouldBeNil) + }) +} + +func TestProcessRoute(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + convey.Convey("Activate the route configuration", func() { + rc := GetFakeRouteConfig() + rc.Webhook.mux = http.NewServeMux() + + rc.PostActivate = DefaultPostActivate + rc.PostStop = DefaultPostStop + + ctx, cancel := context.WithCancel(context.Background()) + fgs := &FakeGRPCStream{ + Ctx: ctx, + } + + helper := NewWebhookHelper() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &Endpoint{ + DataCh: make(chan []byte), + } + helper.ActiveServers[rc.Webhook.Port] = &activeServer{ + errChan: make(chan error), + } + + errCh := make(chan error) + go func() { + <-helper.RouteDeactivateChan + }() + + go func() { + <-helper.RouteActivateChan + }() + go func() { + rc.StartCh <- struct{}{} + }() + go func() { + time.Sleep(3 * time.Second) + cancel() + }() + + go func() { + errCh <- ProcessRoute(rc, helper, fgs) + }() + + err := <-errCh + convey.So(err, convey.ShouldBeNil) + }) + }) +} + +func TestProcessRouteChannels(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + convey.Convey("Stop server stream", func() { + rc := GetFakeRouteConfig() + ctx, cancel := context.WithCancel(context.Background()) + fgs := &FakeGRPCStream{ + Ctx: ctx, + } + helper := NewWebhookHelper() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &Endpoint{ + DataCh: make(chan []byte), + } + helper.ActiveServers[rc.Webhook.Port] = &activeServer{ + errChan: make(chan error), + } + errCh := make(chan error) + go func() { + <-helper.RouteDeactivateChan + }() + go func() { + errCh <- rc.processChannels(helper, fgs) + }() + cancel() + err := <-errCh + convey.So(err, convey.ShouldBeNil) + }) + convey.Convey("Handle error", func() { + rc := GetFakeRouteConfig() + fgs := &FakeGRPCStream{ + Ctx: context.Background(), + } + helper := NewWebhookHelper() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &Endpoint{ + DataCh: make(chan []byte), + } + helper.ActiveServers[rc.Webhook.Port] = &activeServer{ + errChan: make(chan error), + } + errCh := make(chan error) + err := fmt.Errorf("error") + go func() { + helper.ActiveServers[rc.Webhook.Port].errChan <- err + }() + go func() { + errCh <- rc.processChannels(helper, fgs) + }() + newErr := <-errCh + convey.So(newErr.Error(), convey.ShouldEqual, err.Error()) + }) + }) +} + +func TestFormatWebhookEndpoint(t *testing.T) { + convey.Convey("Given a webhook endpoint, format it", t, func() { + convey.So(FormatWebhookEndpoint("hello"), convey.ShouldEqual, "/hello") + }) +} + +func TestValidateWebhook(t *testing.T) { + convey.Convey("Given a webhook, validate it", t, func() { + convey.So(ValidateWebhook(Hook), convey.ShouldBeNil) + }) +} + +func TestGenerateFormattedURL(t *testing.T) { + convey.Convey("Given a webhook, generate formatted URL", t, func() { + convey.So(GenerateFormattedURL(Hook), convey.ShouldEqual, "test-url/fake") + }) +} + +func TestNewWebhookHelper(t *testing.T) { + convey.Convey("Make sure webhook helper is not empty", t, func() { + helper := NewWebhookHelper() + convey.So(helper, convey.ShouldNotBeNil) + }) +} diff --git a/gateways/community/README.md b/gateways/community/README.md deleted file mode 100644 index 32ea89b366..0000000000 --- a/gateways/community/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# Community Gateways - -## How to set up gateways that run web server internally? -For any gateway that run web server internally, you need to create the gateway resource before creating gateway configmap. -Why? Because the `webhook` configuration in gateway configmap contains the `url` which the URL of the service that exposes the gateway pod, you need to have -the gateway pod and service running before you can create the configmap. - - ### Example - - Lets setup AWS SNS gateway, - - 1. Create the gateway resource, - ```bash - kubectl -n argo-events create -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/gateways/aws-sns.yaml - ``` - - Once the gateway resource is created, you should see the corresponding gateway pod and service being created. - Make sure the gateway service is being backed by the gateway pod. - - How to get the URL for that resolves to your service is up to you. You can use Ingress controller, Route (if your installation is on Openshift) or other means. - - 2. Create the gateway configmap. The gateway configmap basically contains the event source configurations. You need to put the URL of your service. - - ```bash - kubectl -n argo-events create -f ../../examples/gateway/aws-sns-gateway-configmap.yaml - ``` - - 3. Create the sensor. - - ```bash - kubectl -n argo-events create -f https://raw.githubusercontent.com/argoproj/argo-events/master/examples/sensors/aws-sns.yaml - ``` - - Now your setup is complete. diff --git a/gateways/community/aws-sns/config_test.go b/gateways/community/aws-sns/config_test.go new file mode 100644 index 0000000000..e1c07c570f --- /dev/null +++ b/gateways/community/aws-sns/config_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package aws_sns + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +hook: + endpoint: "/test" + port: "8080" + url: "myurl/test" +topicArn: "test-arn" +region: "us-east-1" +accessKey: + key: accesskey + name: sns +secretKey: + key: secretkey + name: sns +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a aws-sns event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*snsConfig) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/aws-sns/start.go b/gateways/community/aws-sns/start.go index 6cc067b5d0..7d1723e69b 100644 --- a/gateways/community/aws-sns/start.go +++ b/gateways/community/aws-sns/start.go @@ -24,10 +24,6 @@ import ( "github.com/argoproj/argo-events/common" "github.com/argoproj/argo-events/gateways" gwcommon "github.com/argoproj/argo-events/gateways/common" - "github.com/argoproj/argo-events/store" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" snslib "github.com/aws/aws-sdk-go/service/sns" "github.com/ghodss/yaml" ) @@ -65,7 +61,7 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g body, err := ioutil.ReadAll(request.Body) if err != nil { logger.Error().Err(err).Msg("failed to parse request body") - common.SendErrorResponse(writer, fmt.Sprintf("failed to parse request. err: %+v", err)) + common.SendErrorResponse(writer, "failed to parse request") return } @@ -73,6 +69,7 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g err = yaml.Unmarshal(body, &snspayload) if err != nil { logger.Error().Err(err).Msg("failed to convert request payload into snsConfig payload") + common.SendErrorResponse(writer, "failed to marshal request") return } @@ -87,6 +84,7 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g }) if err != nil { logger.Error().Err(err).Msg("failed to send confirmation response to amazon") + common.SendErrorResponse(writer, "failed to confirm subscription") return } rc.Configs[labelSubscriptionArn] = out.SubscriptionArn @@ -106,39 +104,24 @@ func (ese *SNSEventSourceExecutor) PostActivate(rc *gwcommon.RouteConfig) error Str("port", rc.Webhook.Port).Logger() sc := rc.Configs[labelSNSConfig].(*snsConfig) - // retrieve access key id and secret access key - accessKey, err := store.GetSecrets(ese.Clientset, ese.Namespace, sc.AccessKey.Name, sc.AccessKey.Key) - if err != nil { - logger.Error().Err(err).Msg("failed to retrieve access key") - return err - } - secretKey, err := store.GetSecrets(ese.Clientset, ese.Namespace, sc.SecretKey.Name, sc.SecretKey.Key) + + creds, err := gwcommon.GetAWSCreds(ese.Clientset, ese.Namespace, sc.AccessKey, sc.SecretKey) if err != nil { - logger.Error().Err(err).Msg("failed to retrieve secret key") - return err + logger.Error().Err(err).Msg("failed to get aws credentials") } - creds := credentials.NewStaticCredentialsFromCreds(credentials.Value{ - AccessKeyID: accessKey, - SecretAccessKey: secretKey, - }) - - formattedUrl := gwcommon.GenerateFormattedURL(sc.Hook) - - awsSession, err := session.NewSession(&aws.Config{ - Region: &sc.Region, - Credentials: creds, - HTTPClient: &http.Client{}, - }) + awsSession, err := gwcommon.GetAWSSession(creds, sc.Region) if err != nil { logger.Error().Err(err).Msg("failed to create new session") return err } + logger.Info().Msg("subscribing to sns topic") + snsSession := snslib.New(awsSession) rc.Configs[labelSNSSession] = snsSession + formattedUrl := gwcommon.GenerateFormattedURL(sc.Hook) - logger.Info().Msg("subscribing to snsConfig topic") if _, err := snsSession.Subscribe(&snslib.SubscribeInput{ Endpoint: &formattedUrl, Protocol: &snsProtocol, diff --git a/gateways/community/aws-sns/start_test.go b/gateways/community/aws-sns/start_test.go new file mode 100644 index 0000000000..46dd2f0c97 --- /dev/null +++ b/gateways/community/aws-sns/start_test.go @@ -0,0 +1,106 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package aws_sns + +import ( + "bytes" + "github.com/argoproj/argo-events/common" + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/aws/aws-sdk-go/aws/credentials" + snslib "github.com/aws/aws-sdk-go/service/sns" + "github.com/ghodss/yaml" + "github.com/smartystreets/goconvey/convey" + "io/ioutil" + "k8s.io/client-go/kubernetes/fake" + "net/http" + "testing" +) + +func TestAWSSNS(t *testing.T) { + convey.Convey("Given an route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + writer := &gwcommon.FakeHttpWriter{} + subscriptionArn := "arn://fake" + awsSession, err := gwcommon.GetAWSSession(credentials.NewStaticCredentialsFromCreds(credentials.Value{ + AccessKeyID: "access", + SecretAccessKey: "secret", + }), "mock-region") + + convey.So(err, convey.ShouldBeNil) + + snsSession := snslib.New(awsSession) + rc.Configs[labelSNSSession] = snsSession + rc.Configs[labelSubscriptionArn] = &subscriptionArn + + convey.Convey("handle the inactive route", func() { + RouteActiveHandler(writer, &http.Request{}, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + rc.Configs[labelSNSConfig] = ps.(*snsConfig) + + convey.Convey("handle the active route", func() { + payload := httpNotification{ + TopicArn: "arn://fake", + Token: "faketoken", + Type: messageTypeSubscriptionConfirmation, + } + + payloadBytes, err := yaml.Marshal(payload) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewBuffer(payloadBytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + convey.So(string(writer.Payload), convey.ShouldEqual, "failed to confirm subscription") + + go func() { + <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + }() + + payload.Type = messageTypeNotification + payloadBytes, err = yaml.Marshal(payload) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewBuffer(payloadBytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusOK) + }) + + convey.Convey("Run post activate", func() { + ese := SNSEventSourceExecutor{ + Namespace: "fake", + Clientset: fake.NewSimpleClientset(), + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + err := ese.PostActivate(rc) + convey.So(err, convey.ShouldNotBeNil) + }) + + convey.Convey("Run post stop", func() { + err = PostStop(rc) + convey.So(err, convey.ShouldNotBeNil) + }) + }) +} diff --git a/gateways/community/aws-sns/validate_test.go b/gateways/community/aws-sns/validate_test.go index 9fb2377895..85bfb39295 100644 --- a/gateways/community/aws-sns/validate_test.go +++ b/gateways/community/aws-sns/validate_test.go @@ -39,7 +39,6 @@ accessKey: secretKey: key: secretkey name: sns - ` invalidConfig = ` diff --git a/gateways/community/aws-sqs/config_test.go b/gateways/community/aws-sqs/config_test.go new file mode 100644 index 0000000000..5d6929dfe8 --- /dev/null +++ b/gateways/community/aws-sqs/config_test.go @@ -0,0 +1,45 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package aws_sqs + +import ( + "testing" + + "github.com/smartystreets/goconvey/convey" +) + +var es = ` +region: "us-east-1" +accessKey: + key: accesskey + name: sns +secretKey: + key: secretkey + name: sns +queue: "test-queue" +waitTimeSeconds: 10 +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a aws-sqs event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*sqs) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/aws-sqs/start.go b/gateways/community/aws-sqs/start.go index 68280e4c8a..df44dfdee4 100644 --- a/gateways/community/aws-sqs/start.go +++ b/gateways/community/aws-sqs/start.go @@ -18,10 +18,8 @@ package aws_sqs import ( "github.com/argoproj/argo-events/gateways" - "github.com/argoproj/argo-events/store" + gwcommon "github.com/argoproj/argo-events/gateways/common" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/credentials" - "github.com/aws/aws-sdk-go/aws/session" sqslib "github.com/aws/aws-sdk-go/service/sqs" ) @@ -48,26 +46,13 @@ func (ese *SQSEventSourceExecutor) StartEventSource(eventSource *gateways.EventS func (ese *SQSEventSourceExecutor) listenEvents(s *sqs, eventSource *gateways.EventSource, dataCh chan []byte, errorCh chan error, doneCh chan struct{}) { defer gateways.Recover(eventSource.Name) - // retrieve access key id and secret access key - accessKey, err := store.GetSecrets(ese.Clientset, ese.Namespace, s.AccessKey.Name, s.AccessKey.Key) - if err != nil { - errorCh <- err - return - } - secretKey, err := store.GetSecrets(ese.Clientset, ese.Namespace, s.SecretKey.Name, s.SecretKey.Key) + creds, err := gwcommon.GetAWSCreds(ese.Clientset, ese.Namespace, s.AccessKey, s.SecretKey) if err != nil { errorCh <- err return } - creds := credentials.NewStaticCredentialsFromCreds(credentials.Value{ - AccessKeyID: accessKey, - SecretAccessKey: secretKey, - }) - awsSession, err := session.NewSession(&aws.Config{ - Region: &s.Region, - Credentials: creds, - }) + awsSession, err := gwcommon.GetAWSSession(creds, s.Region) if err != nil { errorCh <- err return diff --git a/gateways/community/aws-sqs/start_test.go b/gateways/community/aws-sqs/start_test.go new file mode 100644 index 0000000000..499b311f5d --- /dev/null +++ b/gateways/community/aws-sqs/start_test.go @@ -0,0 +1,59 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package aws_sqs + +import ( + "testing" + + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/gateways" + "github.com/smartystreets/goconvey/convey" + "k8s.io/client-go/kubernetes/fake" +) + +func TestListenEvents(t *testing.T) { + convey.Convey("Given an event source, listen to events", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + + ese := &SQSEventSourceExecutor{ + Clientset: fake.NewSimpleClientset(), + Namespace: "fake", + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + + dataCh := make(chan []byte) + errorCh := make(chan error) + doneCh := make(chan struct{}, 1) + errorCh2 := make(chan error) + + go func() { + err := <-errorCh + errorCh2 <- err + }() + + ese.listenEvents(ps.(*sqs), &gateways.EventSource{ + Name: "fake", + Data: es, + Id: "1234", + }, dataCh, errorCh, doneCh) + + err = <-errorCh2 + convey.So(err, convey.ShouldNotBeNil) + }) +} diff --git a/gateways/community/gcp-pubsub/config_test.go b/gateways/community/gcp-pubsub/config_test.go new file mode 100644 index 0000000000..2eb280bf48 --- /dev/null +++ b/gateways/community/gcp-pubsub/config_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package pubsub + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +projectID: "1234" +topic: "test" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a gcp-pubsub event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*pubSubConfig) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/gcp-pubsub/start_test.go b/gateways/community/gcp-pubsub/start_test.go new file mode 100644 index 0000000000..ea21d8c23c --- /dev/null +++ b/gateways/community/gcp-pubsub/start_test.go @@ -0,0 +1,57 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package pubsub + +import ( + "context" + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/gateways" + "github.com/smartystreets/goconvey/convey" + "testing" +) + +func TestListenEvents(t *testing.T) { + convey.Convey("Given a pubsub event source, listen to events", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + psc := ps.(*pubSubConfig) + + ese := &GcpPubSubEventSourceExecutor{ + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + + dataCh := make(chan []byte) + errorCh := make(chan error) + doneCh := make(chan struct{}, 1) + errCh2 := make(chan error) + + go func() { + err := <-errorCh + errCh2 <- err + }() + + ese.listenEvents(context.Background(), psc, &gateways.EventSource{ + Name: "fake", + Data: es, + Id: "1234", + }, dataCh, errorCh, doneCh) + + err = <-errCh2 + convey.So(err, convey.ShouldNotBeNil) + }) +} diff --git a/gateways/community/github/config.go b/gateways/community/github/config.go index f38ee9e029..22a5610089 100644 --- a/gateways/community/github/config.go +++ b/gateways/community/github/config.go @@ -19,7 +19,6 @@ package github import ( "github.com/argoproj/argo-events/gateways/common" "github.com/ghodss/yaml" - "github.com/google/go-github/github" "github.com/rs/zerolog" corev1 "k8s.io/api/core/v1" "k8s.io/client-go/kubernetes" @@ -28,8 +27,6 @@ import ( // GithubEventSourceExecutor implements ConfigExecutor type GithubEventSourceExecutor struct { Log zerolog.Logger - // GitlabClient is client for gitlab api - GithubClient *github.Client // Clientset is kubernetes client Clientset kubernetes.Interface // Namespace where gateway is deployed diff --git a/gateways/community/github/config_test.go b/gateways/community/github/config_test.go new file mode 100644 index 0000000000..dde443535d --- /dev/null +++ b/gateways/community/github/config_test.go @@ -0,0 +1,46 @@ +/* +Copyright 2018 KompiTech GmbH + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package github + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +hook: + endpoint: "/push" + port: "12000" + url: "http://webhook-gateway-svc" +owner: "asd" +repository: "dsa" +events: +- PushEvents +apiToken: + key: accesskey + name: githab-access +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a github event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*githubConfig) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/github/start_test.go b/gateways/community/github/start_test.go new file mode 100644 index 0000000000..628de12ca2 --- /dev/null +++ b/gateways/community/github/start_test.go @@ -0,0 +1,105 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package github + +import ( + "bytes" + "io/ioutil" + "net/http" + "testing" + + "github.com/argoproj/argo-events/common" + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/ghodss/yaml" + "github.com/google/go-github/github" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" +) + +var ( + ese = &GithubEventSourceExecutor{ + Clientset: fake.NewSimpleClientset(), + Namespace: "fake", + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + + secretName = "githab-access" + accessKey = "YWNjZXNz" + LabelAccessKey = "accesskey" +) + +func TestGetCredentials(t *testing.T) { + convey.Convey("Given a kubernetes secret, get credentials", t, func() { + secret, err := ese.Clientset.CoreV1().Secrets(ese.Namespace).Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: ese.Namespace, + }, + Data: map[string][]byte{ + LabelAccessKey: []byte(accessKey), + }, + }) + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + creds, err := ese.getCredentials(ps.(*githubConfig).APIToken) + convey.So(err, convey.ShouldBeNil) + convey.So(creds, convey.ShouldNotBeNil) + convey.So(creds.secret, convey.ShouldEqual, "YWNjZXNz") + }) +} + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + convey.Convey("Inactive route should return error", func() { + writer := &gwcommon.FakeHttpWriter{} + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + pbytes, err := yaml.Marshal(ps.(*githubConfig)) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + + convey.Convey("Active route should return success", func() { + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + rc.Configs[labelWebhook] = &github.Hook{ + Config: make(map[string]interface{}), + } + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + rc.Configs[labelGithubConfig] = ps.(*githubConfig) + err = ese.PostActivate(rc) + convey.So(err, convey.ShouldNotBeNil) + }) + }) + }) +} diff --git a/gateways/community/gitlab/config_test.go b/gateways/community/gitlab/config_test.go new file mode 100644 index 0000000000..6f88cdef76 --- /dev/null +++ b/gateways/community/gitlab/config_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package gitlab + +import ( + "testing" + + "github.com/smartystreets/goconvey/convey" +) + +var es = ` +hook: + endpoint: "/push" + port: "12000" + url: "http://webhook-gateway-gateway-svc/push" +projectId: "28" +event: "PushEvents" +accessToken: + key: accesskey + name: gitlab-access +enableSSLVerification: false +gitlabBaseUrl: "http://gitlab.com/" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a gitlab event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*glab) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/gitlab/start_test.go b/gateways/community/gitlab/start_test.go new file mode 100644 index 0000000000..b75716ffdf --- /dev/null +++ b/gateways/community/gitlab/start_test.go @@ -0,0 +1,112 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package gitlab + +import ( + "bytes" + "io/ioutil" + "net/http" + "testing" + + "github.com/argoproj/argo-events/common" + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/ghodss/yaml" + "github.com/google/go-github/github" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" +) + +var ( + ese = &GitlabEventSourceExecutor{ + Clientset: fake.NewSimpleClientset(), + Namespace: "fake", + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + + secretName = "gitlab-access" + accessKey = "YWNjZXNz" + LabelAccessKey = "accesskey" +) + +func TestGetCredentials(t *testing.T) { + convey.Convey("Given a kubernetes secret, get credentials", t, func() { + secret, err := ese.Clientset.CoreV1().Secrets(ese.Namespace).Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: secretName, + Namespace: ese.Namespace, + }, + Data: map[string][]byte{ + LabelAccessKey: []byte(accessKey), + }, + }) + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + creds, err := ese.getCredentials(ps.(*glab).AccessToken) + convey.So(err, convey.ShouldBeNil) + convey.So(creds, convey.ShouldNotBeNil) + convey.So(creds.token, convey.ShouldEqual, "YWNjZXNz") + }) +} + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + convey.Convey("Inactive route should return error", func() { + writer := &gwcommon.FakeHttpWriter{} + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + pbytes, err := yaml.Marshal(ps.(*glab)) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + + convey.Convey("Active route should return success", func() { + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + rc.Configs[labelWebhook] = &github.Hook{ + Config: make(map[string]interface{}), + } + dataCh := make(chan []byte) + go func() { + resp := <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + dataCh <- resp + }() + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + + data := <-dataCh + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusOK) + convey.So(string(data), convey.ShouldEqual, string(pbytes)) + rc.Configs[labelGitlabConfig] = ps.(*glab) + err = ese.PostActivate(rc) + convey.So(err, convey.ShouldNotBeNil) + }) + }) + }) +} diff --git a/gateways/community/slack/config_test.go b/gateways/community/slack/config_test.go new file mode 100644 index 0000000000..d61fe38be9 --- /dev/null +++ b/gateways/community/slack/config_test.go @@ -0,0 +1,42 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package slack + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +hook: + endpoint: "/" + port: "8080" + url: "testurl" +token: + name: fake-token + key: fake +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a slack event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*slackConfig) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/slack/start.go b/gateways/community/slack/start.go index af614a726d..a1048b66c4 100644 --- a/gateways/community/slack/start.go +++ b/gateways/community/slack/start.go @@ -60,7 +60,7 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g var buf bytes.Buffer if _, err := buf.ReadFrom(request.Body); err != nil { logger.Error().Err(err).Msg("failed to parse request body") - common.SendErrorResponse(writer, fmt.Sprintf("failed to parse request. err: %+v", err)) + common.SendInternalErrorResponse(writer, fmt.Sprintf("failed to parse request. err: %+v", err)) return } @@ -68,14 +68,20 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g token := rc.Configs[labelSlackToken] eventsAPIEvent, e := slackevents.ParseEvent(json.RawMessage(body), slackevents.OptionVerifyToken(&slackevents.TokenComparator{VerificationToken: token.(string)})) if e != nil { - writer.WriteHeader(http.StatusInternalServerError) + response = "failed to extract event" + logger.Error().Msg(response) + common.SendInternalErrorResponse(writer, "failed to extract event") + return } if eventsAPIEvent.Type == slackevents.URLVerification { var r *slackevents.ChallengeResponse err := json.Unmarshal([]byte(body), &r) if err != nil { - writer.WriteHeader(http.StatusInternalServerError) + response = "failed to verify the challenge" + logger.Error().Msg(response) + common.SendInternalErrorResponse(writer, response) + return } writer.Header().Set("Content-Type", "text") writer.Write([]byte(r.Challenge)) @@ -84,8 +90,9 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g if eventsAPIEvent.Type == slackevents.CallbackEvent { data, err := json.Marshal(eventsAPIEvent.InnerEvent.Data) if err != nil { - logger.Error().Err(err).Msg("failed to ") - common.SendErrorResponse(writer, "failed to marshal event data") + response = "failed to marshal event data" + logger.Error().Err(err).Msg(response) + common.SendInternalErrorResponse(writer, response) return } helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh <- data @@ -93,6 +100,7 @@ func RouteActiveHandler(writer http.ResponseWriter, request *http.Request, rc *g response = "request successfully processed" logger.Info().Msg(response) + common.SendSuccessResponse(writer, response) } // StartEventSource starts a event source diff --git a/gateways/community/slack/start_test.go b/gateways/community/slack/start_test.go new file mode 100644 index 0000000000..1443654074 --- /dev/null +++ b/gateways/community/slack/start_test.go @@ -0,0 +1,103 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package slack + +import ( + "bytes" + "encoding/json" + "github.com/ghodss/yaml" + "github.com/nlopes/slack/slackevents" + "io/ioutil" + "net/http" + "testing" + + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/smartystreets/goconvey/convey" +) + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + convey.Convey("Inactive route should return 404", func() { + writer := &gwcommon.FakeHttpWriter{} + RouteActiveHandler(writer, &http.Request{}, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + + rc.Configs[labelSlackToken] = "Jhj5dZrVaK7ZwHHjRyZWjbDl" + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + + convey.Convey("Test url verification request", func() { + writer := &gwcommon.FakeHttpWriter{} + urlVer := slackevents.EventsAPIURLVerificationEvent{ + Type: slackevents.URLVerification, + Token: "Jhj5dZrVaK7ZwHHjRyZWjbDl", + Challenge: "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P", + } + payload, err := yaml.Marshal(urlVer) + convey.So(err, convey.ShouldBeNil) + convey.So(payload, convey.ShouldNotBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(payload)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusInternalServerError) + }) + + convey.Convey("Test an event notification", func() { + writer := &gwcommon.FakeHttpWriter{} + event := []byte(` +{ +"type": "name_of_event", +"event_ts": "1234567890.123456", +"user": "UXXXXXXX1" +} +`) + + var j json.RawMessage + j = event + ce := slackevents.EventsAPICallbackEvent{ + Token: "Jhj5dZrVaK7ZwHHjRyZWjbDl", + Type: slackevents.CallbackEvent, + EventTime: 1234567890, + APIAppID: "AXXXXXXXXX", + AuthedUsers: []string{ + "UXXXXXXX1", + "UXXXXXXX2", + }, + EventID: "Ev08MFMKH6", + InnerEvent: &j, + } + payload, err := yaml.Marshal(ce) + convey.So(err, convey.ShouldBeNil) + + go func() { + <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + }() + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewBuffer(payload)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusInternalServerError) + }) + + }) +} diff --git a/gateways/community/storagegrid/config_test.go b/gateways/community/storagegrid/config_test.go new file mode 100644 index 0000000000..e8c88b27e2 --- /dev/null +++ b/gateways/community/storagegrid/config_test.go @@ -0,0 +1,44 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package storagegrid + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +hook: + endpoint: "/" + port: "8080" + url: "testurl" +events: + - "ObjectCreated:Put" +filter: + suffix: ".txt" + prefix: "hello-" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a storage grid event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*storageGrid) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/storagegrid/start_test.go b/gateways/community/storagegrid/start_test.go new file mode 100644 index 0000000000..9a6cec6a43 --- /dev/null +++ b/gateways/community/storagegrid/start_test.go @@ -0,0 +1,146 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package storagegrid + +import ( + "bytes" + "encoding/json" + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/ghodss/yaml" + "github.com/smartystreets/goconvey/convey" + "io/ioutil" + "net/http" + "testing" +) + +var notification = ` +{ + "Action": "Publish", + "Message": { + "Records": [ + { + "eventName": "ObjectCreated:Put", + "eventSource": "sgws:s3", + "eventTime": "2019-02-27T21:15:09Z", + "eventVersion": "2.0", + "requestParameters": { + "sourceIPAddress": "1.1.1.1" + }, + "responseElements": { + "x-amz-request-id": "12345678" + }, + "s3": { + "bucket": { + "arn": "urn:sgfs:s3:::my_bucket", + "name": "my_bucket", + "ownerIdentity": { + "principalId": "55555555555555555" + } + }, + "configurationId": "Object-Event", + "object": { + "eTag": "4444444444444444", + "key": "hello-world.txt", + "sequencer": "AAAAAA", + "size": 6 + }, + "s3SchemaVersion": "1.0" + }, + "userIdentity": { + "principalId": "1111111111111111" + } + } + ] + }, + "TopicArn": "urn:h:sns:us-east::my_topic_1", + "Version": "2010-03-31" +} +` + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + writer := &gwcommon.FakeHttpWriter{} + + convey.Convey("Inactive route should return error", func() { + pbytes, err := yaml.Marshal(ps.(*storageGrid)) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + + convey.Convey("Active route should return success", func() { + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + rc.Configs[LabelStorageGridConfig] = ps.(*storageGrid) + dataCh := make(chan []byte) + go func() { + resp := <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + dataCh <- resp + }() + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader([]byte(notification))), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusOK) + }) + + }) +} + +func TestGenerateUUID(t *testing.T) { + convey.Convey("Make sure generated UUIDs are unique", t, func() { + u1 := generateUUID() + u2 := generateUUID() + convey.So(u1.String(), convey.ShouldNotEqual, u2.String()) + }) +} + +func TestFilterEvent(t *testing.T) { + convey.Convey("Given a storage grid event, test whether it passes the filter", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + var sg *storageGridNotification + err = json.Unmarshal([]byte(notification), &sg) + convey.So(err, convey.ShouldBeNil) + convey.So(sg, convey.ShouldNotBeNil) + + ok := filterEvent(sg, ps.(*storageGrid)) + convey.So(ok, convey.ShouldEqual, true) + }) +} + +func TestFilterName(t *testing.T) { + convey.Convey("Given a storage grid event, test whether the object key passes the filter", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + var sg *storageGridNotification + err = json.Unmarshal([]byte(notification), &sg) + convey.So(err, convey.ShouldBeNil) + convey.So(sg, convey.ShouldNotBeNil) + + ok := filterName(sg, ps.(*storageGrid)) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/trello/config_test.go b/gateways/community/trello/config_test.go new file mode 100644 index 0000000000..26d63464df --- /dev/null +++ b/gateways/community/trello/config_test.go @@ -0,0 +1,47 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package trello + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +hook: + endpoint: "/" + port: "8080" + url: "testurl" +apiKey: + key: api + name: trello +token: + key: token + name: trello +url: "URL to register on trello" +description: "test hook" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a trello event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*trello) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/community/trello/start_test.go b/gateways/community/trello/start_test.go new file mode 100644 index 0000000000..488caae8c0 --- /dev/null +++ b/gateways/community/trello/start_test.go @@ -0,0 +1,95 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package trello + +import ( + "bytes" + "github.com/argoproj/argo-events/common" + "io/ioutil" + "k8s.io/client-go/kubernetes/fake" + "net/http" + "testing" + + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/ghodss/yaml" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + rc.Configs[LabelTrelloConfig] = ps.(*trello) + writer := &gwcommon.FakeHttpWriter{} + + convey.Convey("Inactive route should return error", func() { + pbytes, err := yaml.Marshal(ps.(*trello)) + convey.So(err, convey.ShouldBeNil) + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(pbytes)), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + + convey.Convey("Active route should return success", func() { + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + dataCh := make(chan []byte) + go func() { + resp := <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + dataCh <- resp + }() + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader([]byte("fake notification"))), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusOK) + data := <-dataCh + convey.So(string(data), convey.ShouldEqual, "fake notification") + }) + + convey.Convey("Run post activate", func() { + ese := &TrelloEventSourceExecutor{ + Clientset: fake.NewSimpleClientset(), + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + Namespace: "fake", + } + secret, err := ese.Clientset.CoreV1().Secrets(ese.Namespace).Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "trello", + Namespace: ese.Namespace, + }, + Data: map[string][]byte{ + "api": []byte("api"), + "token": []byte("token"), + }, + }) + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + err = ese.PostActivate(rc) + convey.So(err, convey.ShouldNotBeNil) + }) + + }) +} diff --git a/gateways/core/artifact/config_test.go b/gateways/core/artifact/config_test.go new file mode 100644 index 0000000000..ac73c722aa --- /dev/null +++ b/gateways/core/artifact/config_test.go @@ -0,0 +1,51 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package artifact + +import ( + "testing" + + apicommon "github.com/argoproj/argo-events/pkg/apis/common" + "github.com/smartystreets/goconvey/convey" +) + +var es = ` +bucket: + name: input +endpoint: minio-service.argo-events:9000 +event: s3:ObjectCreated:Put +filter: + prefix: "" + suffix: "" +insecure: true +accessKey: + key: accesskey + name: artifacts-minio +secretKey: + key: secretkey + name: artifacts-minio +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a artifact event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*apicommon.S3Artifact) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/artifact/start_test.go b/gateways/core/artifact/start_test.go new file mode 100644 index 0000000000..ecb5dbafd6 --- /dev/null +++ b/gateways/core/artifact/start_test.go @@ -0,0 +1,72 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package artifact + +import ( + "testing" + + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/gateways" + apicommon "github.com/argoproj/argo-events/pkg/apis/common" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" +) + +func TestListeEvents(t *testing.T) { + convey.Convey("Given an event source, listen to events", t, func() { + ese := &S3EventSourceExecutor{ + Clientset: fake.NewSimpleClientset(), + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + Namespace: "fake", + } + secret, err := ese.Clientset.CoreV1().Secrets(ese.Namespace).Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "artifacts-minio", + Namespace: ese.Namespace, + }, + Data: map[string][]byte{ + "accesskey": []byte("access"), + "secretkey": []byte("secret"), + }, + }) + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + dataCh := make(chan []byte) + errorCh := make(chan error) + doneCh := make(chan struct{}, 1) + errCh2 := make(chan error) + + go func() { + err := <-errorCh + errCh2 <- err + }() + + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + ese.listenEvents(ps.(*apicommon.S3Artifact), &gateways.EventSource{ + Id: "1234", + Data: es, + Name: "fake", + }, dataCh, errorCh, doneCh) + + err = <-errCh2 + convey.So(err, convey.ShouldNotBeNil) + }) +} diff --git a/gateways/core/calendar/config_test.go b/gateways/core/calendar/config_test.go new file mode 100644 index 0000000000..0d94761cc5 --- /dev/null +++ b/gateways/core/calendar/config_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package calendar + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +interval: 2s +userPayload: "{\r\n\"hello\": \"world\"\r\n}" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a calendar event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*calSchedule) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/calendar/start_test.go b/gateways/core/calendar/start_test.go new file mode 100644 index 0000000000..1d5ea565e1 --- /dev/null +++ b/gateways/core/calendar/start_test.go @@ -0,0 +1,73 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package calendar + +import ( + "github.com/argoproj/argo-events/common" + "github.com/argoproj/argo-events/gateways" + "github.com/ghodss/yaml" + "github.com/smartystreets/goconvey/convey" + "testing" +) + +func TestResolveSchedule(t *testing.T) { + convey.Convey("Given a calendar schedule, resolve it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + + schedule, err := resolveSchedule(ps.(*calSchedule)) + convey.So(err, convey.ShouldBeNil) + convey.So(schedule, convey.ShouldNotBeNil) + }) +} + +func TestListenEvents(t *testing.T) { + convey.Convey("Given a calendar schedule, listen events", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + + ese := &CalendarEventSourceExecutor{ + Log: common.GetLoggerContext(common.LoggerConf()).Logger(), + } + dataCh := make(chan []byte) + errorCh := make(chan error) + doneCh := make(chan struct{}, 1) + dataCh2 := make(chan []byte) + + go func() { + data := <-dataCh + dataCh2 <- data + }() + + go ese.listenEvents(ps.(*calSchedule), &gateways.EventSource{ + Name: "fake", + Data: es, + Id: "1234", + }, dataCh, errorCh, doneCh) + + data := <-dataCh2 + doneCh <- struct{}{} + + var cal *calResponse + err = yaml.Unmarshal(data, &cal) + convey.So(err, convey.ShouldBeNil) + + convey.So(cal.UserPayload, convey.ShouldEqual, "{\r\n\"hello\": \"world\"\r\n}") + }) +} diff --git a/gateways/core/file/config_test.go b/gateways/core/file/config_test.go new file mode 100644 index 0000000000..b4be30ff2c --- /dev/null +++ b/gateways/core/file/config_test.go @@ -0,0 +1,38 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package file + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +directory: "/bin/" +type: CREATE +path: x.txt +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a file event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*fileWatcher) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/resource/config_test.go b/gateways/core/resource/config_test.go new file mode 100644 index 0000000000..f62282866d --- /dev/null +++ b/gateways/core/resource/config_test.go @@ -0,0 +1,43 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resource + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +namespace: "argo-events" +group: "" +version: "v1" +kind: "Pod" +filter: + labels: + workflows.argoproj.io/phase: Succeeded + name: "my-workflow" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a resource event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*resource) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/resource/start_test.go b/gateways/core/resource/start_test.go new file mode 100644 index 0000000000..e8e940d54a --- /dev/null +++ b/gateways/core/resource/start_test.go @@ -0,0 +1,109 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package resource + +import ( + "github.com/mitchellh/mapstructure" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/client-go/kubernetes/fake" + "testing" +) + +var ( + ese = &ResourceEventSourceExecutor{} + resourceList = metav1.APIResourceList{ + GroupVersion: "v1", + APIResources: []metav1.APIResource{ + { + Group: "", + Version: "v1", + Name: "fake-1", + Kind: "Fake", + Namespaced: true, + ShortNames: []string{"f1"}, + SingularName: "fake-1", + Verbs: []string{"watch"}, + }, + }, + } +) + +func TestServerResourceForGVK(t *testing.T) { + convey.Convey("Given a resource gvk, discover the resource", t, func() { + result, err := ese.serverResourceForGVK(&resourceList, "Fake") + convey.So(err, convey.ShouldBeNil) + convey.So(result.Kind, convey.ShouldEqual, "Fake") + }) +} + +func TestCanWatchResource(t *testing.T) { + convey.Convey("Given a resource, test if it can watched", t, func() { + result, err := ese.serverResourceForGVK(&resourceList, "Fake") + convey.So(err, convey.ShouldBeNil) + ok := ese.canWatchResource(result) + convey.So(ok, convey.ShouldEqual, true) + }) +} + +func TestResolveGroupVersion(t *testing.T) { + convey.Convey("Given a resource, resolve the group and version", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + gv := ese.resolveGroupVersion(ps.(*resource)) + convey.So(gv, convey.ShouldEqual, "v1") + gv = ese.resolveGroupVersion(&resource{ + GroupVersionKind: metav1.GroupVersionKind{ + Group: "argoproj.io", + Kind: "Fake", + Version: "v1alpha1", + }, + Version: "v1alpha1", + }) + convey.So(gv, convey.ShouldEqual, "argoproj.io/v1alpha1") + }) +} + +func TestFilter(t *testing.T) { + convey.Convey("Given a resource object, apply filter on it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + pod := &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "fake", + Namespace: "fake", + Labels: map[string]string{ + "workflows.argoproj.io/phase": "Succeeded", + "name": "my-workflow", + }, + }, + } + pod, err = fake.NewSimpleClientset().CoreV1().Pods("fake").Create(pod) + convey.So(err, convey.ShouldBeNil) + + outmap := make(map[string]interface{}) + err = mapstructure.Decode(pod, &outmap) + convey.So(err, convey.ShouldBeNil) + + ok := ese.passFilters("fake", &unstructured.Unstructured{ + Object: outmap, + }, ps.(*resource).Filter) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/stream/amqp/config_test.go b/gateways/core/stream/amqp/config_test.go new file mode 100644 index 0000000000..890604fd75 --- /dev/null +++ b/gateways/core/stream/amqp/config_test.go @@ -0,0 +1,39 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package amqp + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +url: amqp://amqp.argo-events:5672 +exchangeName: fooExchangeName +exchangeType: fanout +routingKey: fooRoutingKey +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a amqp event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*amqp) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/stream/kafka/config_test.go b/gateways/core/stream/kafka/config_test.go new file mode 100644 index 0000000000..c8d6a26a43 --- /dev/null +++ b/gateways/core/stream/kafka/config_test.go @@ -0,0 +1,38 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package kafka + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +url: kafka.argo-events:9092 +topic: foo +partition: "0" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a kafka event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*kafka) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/stream/mqtt/config_test.go b/gateways/core/stream/mqtt/config_test.go new file mode 100644 index 0000000000..f4282092c0 --- /dev/null +++ b/gateways/core/stream/mqtt/config_test.go @@ -0,0 +1,38 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package mqtt + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +url: tcp://mqtt.argo-events:1883 +topic: foo +clientId: 1 +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a mqtt event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*mqtt) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/stream/nats/config_test.go b/gateways/core/stream/nats/config_test.go new file mode 100644 index 0000000000..907edb4adf --- /dev/null +++ b/gateways/core/stream/nats/config_test.go @@ -0,0 +1,37 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package nats + +import ( + "github.com/smartystreets/goconvey/convey" + "testing" +) + +var es = ` +url: natsConfig://natsConfig.argo-events:4222 +subject: foo +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a nats event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*natsConfig) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/webhook/config_test.go b/gateways/core/webhook/config_test.go new file mode 100644 index 0000000000..044285ae78 --- /dev/null +++ b/gateways/core/webhook/config_test.go @@ -0,0 +1,40 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package webhook + +import ( + "testing" + + "github.com/argoproj/argo-events/gateways/common" + "github.com/smartystreets/goconvey/convey" +) + +var es = ` +endpoint: "/bar" +port: "10000" +method: "POST" +` + +func TestParseConfig(t *testing.T) { + convey.Convey("Given a webhook event source, parse it", t, func() { + ps, err := parseEventSource(es) + convey.So(err, convey.ShouldBeNil) + convey.So(ps, convey.ShouldNotBeNil) + _, ok := ps.(*common.Webhook) + convey.So(ok, convey.ShouldEqual, true) + }) +} diff --git a/gateways/core/webhook/start_test.go b/gateways/core/webhook/start_test.go new file mode 100644 index 0000000000..2758a1e485 --- /dev/null +++ b/gateways/core/webhook/start_test.go @@ -0,0 +1,71 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package webhook + +import ( + "bytes" + gwcommon "github.com/argoproj/argo-events/gateways/common" + "github.com/smartystreets/goconvey/convey" + "io/ioutil" + "net/http" + "testing" +) + +func TestRouteActiveHandler(t *testing.T) { + convey.Convey("Given a route configuration", t, func() { + rc := gwcommon.GetFakeRouteConfig() + rc.Webhook.Method = http.MethodGet + helper.ActiveEndpoints[rc.Webhook.Endpoint] = &gwcommon.Endpoint{ + DataCh: make(chan []byte), + } + + writer := &gwcommon.FakeHttpWriter{} + + convey.Convey("Inactive route should return error", func() { + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader([]byte("hello"))), + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + + helper.ActiveEndpoints[rc.Webhook.Endpoint].Active = true + + convey.Convey("Active route with correct method should return success", func() { + dataCh := make(chan []byte) + go func() { + resp := <-helper.ActiveEndpoints[rc.Webhook.Endpoint].DataCh + dataCh <- resp + }() + + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader([]byte("fake notification"))), + Method: http.MethodGet, + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusOK) + data := <-dataCh + convey.So(string(data), convey.ShouldEqual, "fake notification") + }) + + convey.Convey("Active route with incorrect method should return failure", func() { + RouteActiveHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader([]byte("fake notification"))), + Method: http.MethodHead, + }, rc) + convey.So(writer.HeaderStatus, convey.ShouldEqual, http.StatusBadRequest) + }) + }) +} diff --git a/gateways/gateway_test.go b/gateways/gateway_test.go new file mode 100644 index 0000000000..9cbb0f565e --- /dev/null +++ b/gateways/gateway_test.go @@ -0,0 +1,105 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package gateways + +import ( + "context" + "fmt" + "github.com/rs/zerolog" + "github.com/smartystreets/goconvey/convey" + "google.golang.org/grpc/metadata" + "os" + "testing" + "time" +) + +type FakeGRPCStream struct { + SentData *Event + Ctx context.Context +} + +func (f *FakeGRPCStream) Send(event *Event) error { + f.SentData = event + return nil +} + +func (f *FakeGRPCStream) SetHeader(metadata.MD) error { + return nil +} + +func (f *FakeGRPCStream) SendHeader(metadata.MD) error { + return nil +} + +func (f *FakeGRPCStream) SetTrailer(metadata.MD) { + return +} + +func (f *FakeGRPCStream) Context() context.Context { + return f.Ctx +} + +func (f *FakeGRPCStream) SendMsg(m interface{}) error { + return nil +} + +func (f *FakeGRPCStream) RecvMsg(m interface{}) error { + return nil +} + +func TestRecover(t *testing.T) { + convey.Convey("Recover from panic", t, func() { + defer Recover("fake") + panic("fake panic") + }) +} + +func TestHandleEventsFromEventSource(t *testing.T) { + convey.Convey("Given a gateway server, handle events from an event source", t, func() { + dataCh := make(chan []byte) + errorCh := make(chan error) + doneCh := make(chan struct{}) + logger := zerolog.New(os.Stdout) + + ctx, cancel := context.WithCancel(context.Background()) + + convey.Convey("handle data", func() { + es := &FakeGRPCStream{ + Ctx: ctx, + } + go HandleEventsFromEventSource("fake", es, dataCh, errorCh, doneCh, &logger) + dataCh <- []byte("hello") + time.Sleep(1 * time.Second) + cancel() + convey.So(string(es.SentData.Payload), convey.ShouldEqual, "hello") + }) + + convey.Convey("handle error", func() { + es := &FakeGRPCStream{ + Ctx: ctx, + } + errorCh2 := make(chan error) + go func() { + err := HandleEventsFromEventSource("fake", es, dataCh, errorCh, doneCh, &logger) + errorCh2 <- err + }() + errorCh <- fmt.Errorf("fake error") + err := <-errorCh2 + convey.So(err.Error(), convey.ShouldEqual, "fake error") + }) + }) +} diff --git a/gateways/state_test.go b/gateways/state_test.go index f1c7290133..82fb3545d5 100644 --- a/gateways/state_test.go +++ b/gateways/state_test.go @@ -17,10 +17,9 @@ limitations under the License. package gateways import ( - "testing" - "github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1" "github.com/smartystreets/goconvey/convey" + "testing" ) func TestGatewayState(t *testing.T) { @@ -84,3 +83,69 @@ func TestGatewayState(t *testing.T) { }) }) } + +func TestMarkGatewayNodePhase(t *testing.T) { + convey.Convey("Given a node status, mark node state", t, func() { + gc := getGatewayConfig() + nodeStatus := &EventSourceStatus{ + Name: "fake", + Id: "1234", + Message: "running", + Phase: v1alpha1.NodePhaseRunning, + Gw: gc.gw, + } + gc.gw.Status.Nodes = map[string]v1alpha1.NodeStatus{ + "1234": v1alpha1.NodeStatus{ + Phase: v1alpha1.NodePhaseNew, + Message: "init", + Name: "fake", + ID: "1234", + }, + } + + resultStatus := gc.markGatewayNodePhase(nodeStatus) + convey.So(resultStatus, convey.ShouldNotBeNil) + convey.So(resultStatus.Name, convey.ShouldEqual, nodeStatus.Name) + + gc.gw.Status.Nodes = map[string]v1alpha1.NodeStatus{ + "4567": v1alpha1.NodeStatus{ + Phase: v1alpha1.NodePhaseNew, + Message: "init", + Name: "fake", + ID: "1234", + }, + } + + resultStatus = gc.markGatewayNodePhase(nodeStatus) + convey.So(resultStatus, convey.ShouldBeNil) + }) +} + +func TestGetNodeByID(t *testing.T) { + convey.Convey("Given a node id, retrieve the node", t, func() { + gc := getGatewayConfig() + gc.gw.Status.Nodes = map[string]v1alpha1.NodeStatus{ + "1234": v1alpha1.NodeStatus{ + Phase: v1alpha1.NodePhaseNew, + Message: "init", + Name: "fake", + ID: "1234", + }, + } + status := gc.getNodeByID("1234") + convey.So(status, convey.ShouldNotBeNil) + convey.So(status.ID, convey.ShouldEqual, "1234") + }) +} + +func TestInitializeNode(t *testing.T) { + convey.Convey("Given a node, initialize it", t, func() { + gc := getGatewayConfig() + status := gc.initializeNode("1234", "fake", "init") + convey.So(status, convey.ShouldNotBeNil) + convey.So(status.ID, convey.ShouldEqual, "1234") + convey.So(status.Name, convey.ShouldEqual, "fake") + convey.So(status.Message, convey.ShouldEqual, "init") + convey.So(len(gc.gw.Status.Nodes), convey.ShouldEqual, 1) + }) +} diff --git a/gateways/transformer.go b/gateways/transformer.go index f52bc4cb9a..43977c7fa8 100644 --- a/gateways/transformer.go +++ b/gateways/transformer.go @@ -84,7 +84,7 @@ func (gc *GatewayConfig) transformEvent(gatewayEvent *Event) (*apicommon.Event, EventType: gc.gw.Spec.Type, EventTypeVersion: gc.gw.Spec.EventVersion, Source: &apicommon.URI{ - Host: common.DefaultGatewayConfigurationName(gc.gw.Name, gatewayEvent.Name), + Host: common.DefaultEventSourceName(gc.gw.Name, gatewayEvent.Name), }, }, Payload: gatewayEvent.Payload, diff --git a/gateways/transformer_test.go b/gateways/transformer_test.go new file mode 100644 index 0000000000..e0bd2f761d --- /dev/null +++ b/gateways/transformer_test.go @@ -0,0 +1,80 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package gateways + +import ( + "fmt" + "github.com/argoproj/argo-events/pkg/apis/common" + "github.com/smartystreets/goconvey/convey" + "github.com/stretchr/testify/mock" + "testing" +) + +type MyMockedObject struct { + mock.Mock +} + +func (m *MyMockedObject) dispatchEventOverHttp(source string, eventPayload []byte) error { + return nil +} + +func (m *MyMockedObject) dispatchEventOverNats(source string, eventPayload []byte) error { + return nil +} + +func TestDispatchEvent(t *testing.T) { + convey.Convey("Given an event, dispatch it to sensor", t, func() { + gc := getGatewayConfig() + event := &Event{ + Name: "fake", + Payload: []byte("fake"), + } + testObj := new(MyMockedObject) + testObj.On("dispatchEventOverHttp", "fake", []byte("fake")).Return(nil) + testObj.On("dispatchEventOverNats", "fake", []byte("fake")).Return(nil) + + err := gc.DispatchEvent(event) + convey.So(err, convey.ShouldBeNil) + + gc.gw.Spec.EventProtocol.Type = common.NATS + + err = gc.DispatchEvent(event) + convey.So(err, convey.ShouldBeNil) + + gc.gw.Spec.EventProtocol.Type = common.NATS + + err = gc.DispatchEvent(event) + convey.So(err, convey.ShouldBeNil) + + gc.gw.Spec.EventProtocol.Type = common.EventProtocolType("fake") + err = gc.DispatchEvent(event) + convey.So(err, convey.ShouldNotBeNil) + }) +} + +func TestTransformEvent(t *testing.T) { + convey.Convey("Given a gateway event, convert it into cloud event", t, func() { + gc := getGatewayConfig() + ce, err := gc.transformEvent(&Event{ + Name: "fake", + Payload: []byte("fake"), + }) + convey.So(err, convey.ShouldBeNil) + convey.So(ce, convey.ShouldNotBeNil) + convey.So(ce.Context.Source.Host, convey.ShouldEqual, fmt.Sprintf("%s:%s", gc.gw.Name, "fake")) + }) +} diff --git a/gateways/utils.go b/gateways/utils.go index 8dd0387529..2e70adea15 100644 --- a/gateways/utils.go +++ b/gateways/utils.go @@ -17,31 +17,15 @@ limitations under the License. package gateways import ( - "time" - + "github.com/argoproj/argo-events/common" "k8s.io/apimachinery/pkg/util/wait" ) -// SetValidateReason set the result of event source validation -func SetValidEventSource(v *ValidEventSource, reason string, valid bool) { - v.Reason = reason - v.IsValid = valid -} - -// InitBackoff initializes backoff -func InitBackoff(backoff *wait.Backoff) { - if backoff == nil { - backoff = &wait.Backoff{ - Steps: 1, - Duration: 1, - } - } - backoff.Duration = backoff.Duration * time.Second -} - // General connection helper func Connect(backoff *wait.Backoff, conn func() error) error { - InitBackoff(backoff) + if backoff == nil { + backoff = &common.DefaultRetry + } err := wait.ExponentialBackoff(*backoff, func() (bool, error) { if err := conn(); err != nil { return false, nil diff --git a/gateways/utils_test.go b/gateways/utils_test.go index 8017d4e043..926f26e162 100644 --- a/gateways/utils_test.go +++ b/gateways/utils_test.go @@ -18,14 +18,16 @@ package gateways import ( "github.com/smartystreets/goconvey/convey" + "k8s.io/apimachinery/pkg/util/wait" "testing" ) -func TestGatewayUtil(t *testing.T) { - convey.Convey("Given a event source, set the validation message", t, func() { - v := ValidEventSource{} - SetValidEventSource(&v, "event source is valid", true) - convey.So(v.IsValid, convey.ShouldBeTrue) - convey.So(v.Reason, convey.ShouldEqual, "event source is valid") +func TestConnect(t *testing.T) { + convey.Convey("Given a backoff option, test connection", t, func() { + var backoff *wait.Backoff + err := Connect(backoff, func() error { + return nil + }) + convey.So(err, convey.ShouldBeNil) }) } diff --git a/hack/generate-proto.sh b/hack/generate-proto.sh index 2080dafcf9..f05ad7bab4 100755 --- a/hack/generate-proto.sh +++ b/hack/generate-proto.sh @@ -42,6 +42,3 @@ dist/go-to-protobuf \ --apimachinery-packages=$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}") \ --proto-import=${PROJECT_ROOT}/vendor -# generate protocol documentation -protoc -I=${GOPATH}/src --doc_out=../docs --doc_opt=markdown,gateway-protocol.md github.com/argoproj/argo-events/pkg/apis/gateway/v1alpha1/generated.proto -protoc -I=${GOPATH}/src --doc_out=../docs --doc_opt=markdown,sensor-protocol.md github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1/generated.proto diff --git a/pkg/apis/common/deepcopy_generated.go b/pkg/apis/common/deepcopy_generated.go index a84fcce7b0..97df0ef8f2 100644 --- a/pkg/apis/common/deepcopy_generated.go +++ b/pkg/apis/common/deepcopy_generated.go @@ -21,7 +21,7 @@ limitations under the License. package common import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/apis/common/generated.pb.go b/pkg/apis/common/generated.pb.go index 19b9ad1544..647712c744 100644 --- a/pkg/apis/common/generated.pb.go +++ b/pkg/apis/common/generated.pb.go @@ -18,18 +18,18 @@ limitations under the License. package common import ( - fmt "fmt" + "fmt" - io "io" + "io" - proto "github.com/gogo/protobuf/proto" + "github.com/gogo/protobuf/proto" github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" github_com_minio_minio_go "github.com/minio/minio-go" v11 "k8s.io/api/core/v1" - math "math" - reflect "reflect" - strings "strings" + "math" + "reflect" + "strings" ) // Reference imports to suppress errors if they are not otherwise used. diff --git a/pkg/apis/sensor/v1alpha1/generated.proto b/pkg/apis/sensor/v1alpha1/generated.proto index 7d645d9a32..e24a1aa161 100644 --- a/pkg/apis/sensor/v1alpha1/generated.proto +++ b/pkg/apis/sensor/v1alpha1/generated.proto @@ -229,7 +229,7 @@ message ResourceObject { optional GroupVersionKind groupVersionKind = 5; // Namespace in which to create this object - // defaults to the service account namespace + // defaults to the sensor namespace optional string namespace = 1; // Source of the K8 resource file(s) diff --git a/sensors/event-handler_test.go b/sensors/event-handler_test.go index 3aa6ea19de..720dec7493 100644 --- a/sensors/event-handler_test.go +++ b/sensors/event-handler_test.go @@ -17,8 +17,12 @@ limitations under the License. package sensors import ( + "bytes" + "encoding/json" "fmt" + "io/ioutil" "net/http" + "strings" "testing" "time" @@ -30,6 +34,8 @@ import ( "github.com/ghodss/yaml" "github.com/smartystreets/goconvey/convey" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" discoveryFake "k8s.io/client-go/discovery/fake" "k8s.io/client-go/kubernetes/fake" ) @@ -37,7 +43,6 @@ import ( var sensorStr = `apiVersion: argoproj.io/v1alpha1 kind: Sensor metadata: - namespace: argo-events name: test-sensor labels: sensors.argoproj.io/sensor-controller-instanceid: argo-events @@ -92,18 +97,22 @@ func getSensor() (*v1alpha1.Sensor, error) { return &sensor, err } -type mockHttpWriter struct{} +type mockHttpWriter struct { + Status int + Payload []byte +} func (m *mockHttpWriter) Header() http.Header { return http.Header{} } -func (m *mockHttpWriter) Write([]byte) (int, error) { +func (m *mockHttpWriter) Write(p []byte) (int, error) { + m.Payload = p return 0, nil } func (m *mockHttpWriter) WriteHeader(statusCode int) { - + m.Status = statusCode } func getsensorExecutionCtx(sensor *v1alpha1.Sensor) *sensorExecutionCtx { @@ -121,6 +130,7 @@ func getsensorExecutionCtx(sensor *v1alpha1.Sensor) *sensorExecutionCtx { sensorClient: sensorFake.NewSimpleClientset(), sensor: sensor, controllerInstanceID: "test-1", + queue: make(chan *updateNotification), } } @@ -134,7 +144,7 @@ func getCloudEvent() *apicommon.Event { EventType: "test", EventTypeVersion: common.CloudEventsVersion, Source: &apicommon.URI{ - Host: common.DefaultGatewayConfigurationName("test-gateway", "test"), + Host: common.DefaultEventSourceName("test-gateway", "test"), }, }, Payload: []byte(`{ @@ -225,3 +235,205 @@ func TestDeleteStaleStatusNodes(t *testing.T) { convey.So(ok, convey.ShouldEqual, false) }) } + +func TestValidateEvent(t *testing.T) { + convey.Convey("Given an event, validate it", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + dep, valid := sec.validateEvent(&apicommon.Event{ + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + }) + convey.So(valid, convey.ShouldEqual, true) + convey.So(dep, convey.ShouldNotBeNil) + }) +} + +func TestParseEvent(t *testing.T) { + convey.Convey("Given an event payload, parse event", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + e := &apicommon.Event{ + Payload: []byte("hello"), + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + } + payload, err := json.Marshal(e) + convey.So(err, convey.ShouldBeNil) + + event, err := sec.parseEvent(payload) + convey.So(err, convey.ShouldBeNil) + convey.So(string(event.Payload), convey.ShouldEqual, "hello") + }) +} + +func TestSendToInternalQueue(t *testing.T) { + convey.Convey("Given an event, send it on internal queue", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + e := &apicommon.Event{ + Payload: []byte("hello"), + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + } + go func() { + <-sec.queue + }() + ok := sec.sendEventToInternalQueue(e, &mockHttpWriter{}) + convey.So(ok, convey.ShouldEqual, true) + }) +} + +func TestHandleHttpEventHandler(t *testing.T) { + convey.Convey("Test http handler", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + e := &apicommon.Event{ + Payload: []byte("hello"), + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + } + go func() { + <-sec.queue + }() + payload, err := json.Marshal(e) + convey.So(err, convey.ShouldBeNil) + writer := &mockHttpWriter{} + sec.httpEventHandler(writer, &http.Request{ + Body: ioutil.NopCloser(bytes.NewReader(payload)), + }) + convey.So(writer.Status, convey.ShouldEqual, http.StatusOK) + }) +} + +func TestSuccessNatsConnection(t *testing.T) { + convey.Convey("Given a successful nats connection, generate K8s event", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + sec.successNatsConnection() + req1, err := labels.NewRequirement(common.LabelOperation, selection.Equals, []string{"nats_connection_setup"}) + convey.So(err, convey.ShouldBeNil) + req2, err := labels.NewRequirement(common.LabelEventType, selection.Equals, []string{string(common.OperationSuccessEventType)}) + convey.So(err, convey.ShouldBeNil) + req3, err := labels.NewRequirement(common.LabelSensorName, selection.Equals, []string{string(sec.sensor.Name)}) + convey.So(err, convey.ShouldBeNil) + + eventList, err := sec.kubeClient.CoreV1().Events(sec.sensor.Namespace).List(metav1.ListOptions{ + LabelSelector: labels.NewSelector().Add([]labels.Requirement{*req1, *req2, *req3}...).String(), + }) + convey.So(err, convey.ShouldBeNil) + convey.So(len(eventList.Items), convey.ShouldEqual, 1) + event := eventList.Items[0] + convey.So(event.Reason, convey.ShouldEqual, "connection setup successfully") + }) +} + +func TestEscalateNatsConnectionFailure(t *testing.T) { + convey.Convey("Given a failed nats connection, escalate through K8s event", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + sec.escalateNatsConnectionFailure() + req1, err := labels.NewRequirement(common.LabelOperation, selection.Equals, []string{"nats_connection_setup"}) + convey.So(err, convey.ShouldBeNil) + req2, err := labels.NewRequirement(common.LabelEventType, selection.Equals, []string{string(common.OperationFailureEventType)}) + convey.So(err, convey.ShouldBeNil) + req3, err := labels.NewRequirement(common.LabelSensorName, selection.Equals, []string{string(sec.sensor.Name)}) + convey.So(err, convey.ShouldBeNil) + + eventList, err := sec.kubeClient.CoreV1().Events(sec.sensor.Namespace).List(metav1.ListOptions{ + LabelSelector: labels.NewSelector().Add([]labels.Requirement{*req1, *req2, *req3}...).String(), + }) + convey.So(err, convey.ShouldBeNil) + convey.So(len(eventList.Items), convey.ShouldEqual, 1) + event := eventList.Items[0] + convey.So(event.Reason, convey.ShouldEqual, "connection setup failed") + }) +} + +func TestSuccessNatsSubscription(t *testing.T) { + convey.Convey("Given a successful nats subscription, generate K8s event", t, func() { + s, _ := getSensor() + eventSource := "fake" + sec := getsensorExecutionCtx(s) + sec.successNatsSubscription(eventSource) + req1, err := labels.NewRequirement(common.LabelOperation, selection.Equals, []string{"nats_subscription_success"}) + convey.So(err, convey.ShouldBeNil) + req2, err := labels.NewRequirement(common.LabelEventType, selection.Equals, []string{string(common.OperationSuccessEventType)}) + convey.So(err, convey.ShouldBeNil) + req3, err := labels.NewRequirement(common.LabelSensorName, selection.Equals, []string{string(sec.sensor.Name)}) + convey.So(err, convey.ShouldBeNil) + req4, err := labels.NewRequirement(common.LabelEventSource, selection.Equals, []string{strings.Replace(eventSource, ":", "_", -1)}) + convey.So(err, convey.ShouldBeNil) + + eventList, err := sec.kubeClient.CoreV1().Events(sec.sensor.Namespace).List(metav1.ListOptions{ + LabelSelector: labels.NewSelector().Add([]labels.Requirement{*req1, *req2, *req3, *req4}...).String(), + }) + convey.So(err, convey.ShouldBeNil) + convey.So(len(eventList.Items), convey.ShouldEqual, 1) + event := eventList.Items[0] + convey.So(event.Reason, convey.ShouldEqual, "nats subscription success") + }) +} + +func TestEscalateNatsSubscriptionFailure(t *testing.T) { + convey.Convey("Given a failed nats subscription, escalate K8s event", t, func() { + s, _ := getSensor() + eventSource := "fake" + sec := getsensorExecutionCtx(s) + sec.escalateNatsSubscriptionFailure(eventSource) + req1, err := labels.NewRequirement(common.LabelOperation, selection.Equals, []string{"nats_subscription_failure"}) + convey.So(err, convey.ShouldBeNil) + req2, err := labels.NewRequirement(common.LabelEventType, selection.Equals, []string{string(common.OperationFailureEventType)}) + convey.So(err, convey.ShouldBeNil) + req3, err := labels.NewRequirement(common.LabelSensorName, selection.Equals, []string{string(sec.sensor.Name)}) + convey.So(err, convey.ShouldBeNil) + req4, err := labels.NewRequirement(common.LabelEventSource, selection.Equals, []string{strings.Replace(eventSource, ":", "_", -1)}) + convey.So(err, convey.ShouldBeNil) + + eventList, err := sec.kubeClient.CoreV1().Events(sec.sensor.Namespace).List(metav1.ListOptions{ + LabelSelector: labels.NewSelector().Add([]labels.Requirement{*req1, *req2, *req3, *req4}...).String(), + }) + convey.So(err, convey.ShouldBeNil) + convey.So(len(eventList.Items), convey.ShouldEqual, 1) + event := eventList.Items[0] + convey.So(event.Reason, convey.ShouldEqual, "nats subscription failed") + }) +} + +func TestProcessNatsMessage(t *testing.T) { + convey.Convey("Given nats message, process it", t, func() { + s, _ := getSensor() + sec := getsensorExecutionCtx(s) + e := &apicommon.Event{ + Payload: []byte("hello"), + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + } + dataCh := make(chan []byte) + go func() { + data := <-sec.queue + dataCh <- data.event.Payload + }() + payload, err := json.Marshal(e) + convey.So(err, convey.ShouldBeNil) + sec.processNatsMessage(payload, "fake") + data := <-dataCh + convey.So(data, convey.ShouldNotBeNil) + convey.So(string(data), convey.ShouldEqual, "hello") + }) +} diff --git a/sensors/nats-events-handler.go b/sensors/nats-events-handler.go index dfc8a04a2a..69de54659e 100644 --- a/sensors/nats-events-handler.go +++ b/sensors/nats-events-handler.go @@ -44,11 +44,11 @@ func (sec *sensorExecutionCtx) successNatsConnection() { func (sec *sensorExecutionCtx) escalateNatsConnectionFailure() { // escalate error labels := map[string]string{ - common.LabelEventType: string(common.EscalationEventType), + common.LabelEventType: string(common.OperationFailureEventType), common.LabelSensorName: sec.sensor.Name, common.LabelOperation: "nats_connection_setup", } - if err := common.GenerateK8sEvent(sec.kubeClient, "connection setup failed", common.EscalationEventType, "connection setup", sec.sensor.Name, sec.sensor.Namespace, sec.controllerInstanceID, sensor.Kind, labels); err != nil { + if err := common.GenerateK8sEvent(sec.kubeClient, "connection setup failed", common.OperationFailureEventType, "connection setup", sec.sensor.Name, sec.sensor.Namespace, sec.controllerInstanceID, sensor.Kind, labels); err != nil { sec.log.Error().Err(err).Msg("failed to create K8s event to log nats connection setup error") return } diff --git a/sensors/trigger_test.go b/sensors/trigger_test.go index b52fd6dd8d..8a3b93f153 100644 --- a/sensors/trigger_test.go +++ b/sensors/trigger_test.go @@ -19,6 +19,7 @@ package sensors import ( "testing" + apicommon "github.com/argoproj/argo-events/pkg/apis/common" "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" "github.com/smartystreets/goconvey/convey" corev1 "k8s.io/api/core/v1" @@ -288,3 +289,33 @@ func getUnstructuredPod(pod *corev1.Pod) (*unstructured.Unstructured, error) { } return &unstructured.Unstructured{Object: obj}, nil } + +func TestExtractEvents(t *testing.T) { + convey.Convey("Given a sensor, extract events", t, func() { + sensor, _ := getSensor() + sec := getsensorExecutionCtx(sensor) + id := sensor.NodeID("test-gateway:test") + sensor.Status.Nodes = map[string]v1alpha1.NodeStatus{ + id: { + Type: v1alpha1.NodeTypeEventDependency, + Event: &apicommon.Event{ + Payload: []byte("hello"), + Context: apicommon.EventContext{ + Source: &apicommon.URI{ + Host: "test-gateway:test", + }, + }, + }, + }, + } + extractedEvents := sec.extractEvents([]v1alpha1.ResourceParameter{ + { + Src: &v1alpha1.ResourceParameterSource{ + Event: "test-gateway:test", + }, + Dest: "fake-dest", + }, + }) + convey.So(len(extractedEvents), convey.ShouldEqual, 1) + }) +} diff --git a/store/git_test.go b/store/git_test.go new file mode 100644 index 0000000000..49244ef010 --- /dev/null +++ b/store/git_test.go @@ -0,0 +1,97 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package store + +import ( + "github.com/argoproj/argo-events/pkg/apis/sensor/v1alpha1" + "github.com/smartystreets/goconvey/convey" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes/fake" + "testing" +) + +var gar = &GitArtifactReader{ + kubeClientset: fake.NewSimpleClientset(), + artifact: &v1alpha1.GitArtifact{ + URL: "fake", + Namespace: "fake", + Creds: &v1alpha1.GitCreds{ + Username: &corev1.SecretKeySelector{ + Key: "username", + LocalObjectReference: corev1.LocalObjectReference{ + Name: "git-secret", + }, + }, + Password: &corev1.SecretKeySelector{ + Key: "password", + LocalObjectReference: corev1.LocalObjectReference{ + Name: "git-secret", + }, + }, + }, + }, +} + +func TestNewGitReader(t *testing.T) { + convey.Convey("Given configuration, get new git reader", t, func() { + reader, err := NewGitReader(fake.NewSimpleClientset(), &v1alpha1.GitArtifact{}) + convey.So(err, convey.ShouldBeNil) + convey.So(reader, convey.ShouldNotBeNil) + }) +} + +func TestGetRemote(t *testing.T) { + convey.Convey("Test git remote", t, func() { + remote := gar.getRemote() + convey.So(remote, convey.ShouldEqual, DefaultRemote) + }) +} + +func TestGetGitAuth(t *testing.T) { + convey.Convey("Given auth secret, get git auth tokens", t, func() { + secret, err := gar.kubeClientset.CoreV1().Secrets("fake").Create(&corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: gar.artifact.Creds.Username.Name, + Namespace: gar.artifact.Namespace, + }, + Data: map[string][]byte{ + "username": []byte("username"), + "password": []byte("password"), + }, + }) + convey.So(err, convey.ShouldBeNil) + convey.So(secret, convey.ShouldNotBeNil) + + auth, err := gar.getGitAuth() + convey.So(err, convey.ShouldBeNil) + convey.So(auth, convey.ShouldNotBeNil) + }) +} + +func TestGetBranchOrTag(t *testing.T) { + convey.Convey("Given a git artifact, get the branch or tag", t, func() { + br := gar.getBranchOrTag() + convey.So(br.Branch, convey.ShouldEqual, "refs/heads/master") + gar.artifact.Branch = "br" + br = gar.getBranchOrTag() + convey.So(br.Branch, convey.ShouldNotEqual, "refs/heads/master") + gar.artifact.Tag = "t" + tag := gar.getBranchOrTag() + convey.So(tag.Branch, convey.ShouldNotEqual, "refs/heads/master") + }) +} diff --git a/store/s3_test.go b/store/s3_test.go new file mode 100644 index 0000000000..6fa5445d00 --- /dev/null +++ b/store/s3_test.go @@ -0,0 +1,52 @@ +/* +Copyright 2018 BlackRock, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package store + +import ( + "testing" + + apicommon "github.com/argoproj/argo-events/pkg/apis/common" + "github.com/smartystreets/goconvey/convey" +) + +func TestNewMinioClient(t *testing.T) { + convey.Convey("Given a configuration, get minio client", t, func() { + client, err := NewMinioClient(&apicommon.S3Artifact{ + Endpoint: "fake", + Region: "us-east-1", + }, Credentials{ + accessKey: "access", + secretKey: "secret", + }) + convey.So(err, convey.ShouldBeNil) + convey.So(client, convey.ShouldNotBeNil) + }) +} + +func TestNewS3Reader(t *testing.T) { + convey.Convey("Given a minio client, get a reader", t, func() { + reader, err := NewS3Reader(&apicommon.S3Artifact{ + Endpoint: "fake", + Region: "us-east-1", + }, &Credentials{ + accessKey: "access", + secretKey: "secret", + }) + convey.So(err, convey.ShouldBeNil) + convey.So(reader, convey.ShouldNotBeNil) + }) +}