mirror of
https://github.com/Fishwaldo/mouthpiece.git
synced 2025-03-15 19:41:22 +00:00
Test Suites for the main module
This commit is contained in:
parent
cd09e35209
commit
56c5c83a43
45 changed files with 2078 additions and 683 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -25,3 +25,4 @@ test.db-journal
|
|||
logs/
|
||||
pkg/ent/schema-viz.html
|
||||
.vscode/launch.json
|
||||
.vscode/settings.json
|
||||
|
|
12
go.mod
12
go.mod
|
@ -19,6 +19,7 @@ require (
|
|||
github.com/casbin/casbin/v2 v2.51.2
|
||||
github.com/casbin/gorm-adapter/v3 v3.7.4
|
||||
github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be
|
||||
github.com/dmarkham/enumer v1.5.6
|
||||
github.com/go-chi/chi v4.1.2+incompatible
|
||||
github.com/go-pkgz/auth v1.19.0
|
||||
github.com/go-pkgz/rest v1.15.6
|
||||
|
@ -27,10 +28,10 @@ require (
|
|||
github.com/golang/mock v1.6.0
|
||||
github.com/google/uuid v1.3.0
|
||||
github.com/mattn/go-sqlite3 v1.14.15
|
||||
github.com/mymmrac/telego v0.16.1
|
||||
github.com/onsi/ginkgo/v2 v2.1.6
|
||||
github.com/onsi/gomega v1.20.1
|
||||
github.com/spf13/viper v1.12.0
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
|
||||
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||
)
|
||||
|
@ -47,6 +48,7 @@ require (
|
|||
github.com/danielgtaylor/casing v0.0.0-20210126043903-4e55e6373ac3 // indirect
|
||||
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
|
||||
github.com/dghubble/oauth1 v0.7.1 // indirect
|
||||
github.com/fasthttp/router v1.4.11 // indirect
|
||||
github.com/fatih/color v1.13.0 // indirect
|
||||
github.com/fatih/structs v1.1.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.5.4 // indirect
|
||||
|
@ -60,6 +62,7 @@ require (
|
|||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/go-stack/stack v1.8.1 // indirect
|
||||
github.com/goccy/go-json v0.9.11 // indirect
|
||||
github.com/goccy/go-yaml v1.9.5 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||
github.com/golang-sql/sqlexp v0.0.0-20170517235910-f1bb20e5a188 // indirect
|
||||
|
@ -92,18 +95,20 @@ require (
|
|||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022 // indirect
|
||||
github.com/opentracing/opentracing-go v1.2.0 // indirect
|
||||
github.com/pascaldekloe/name v1.0.0 // indirect
|
||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
|
||||
github.com/spf13/afero v1.8.2 // indirect
|
||||
github.com/spf13/cast v1.5.0 // indirect
|
||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stretchr/testify v1.8.0 // indirect
|
||||
github.com/subosito/gotenv v1.3.0 // indirect
|
||||
github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect
|
||||
github.com/valyala/fasthttp v1.38.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.39.0 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.0 // indirect
|
||||
|
@ -124,6 +129,7 @@ require (
|
|||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa // indirect
|
||||
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
|
|
21
go.sum
21
go.sum
|
@ -152,6 +152,8 @@ github.com/denisenkom/go-mssqldb v0.12.0 h1:VtrkII767ttSPNRfFekePK3sctr+joXgO58s
|
|||
github.com/denisenkom/go-mssqldb v0.12.0/go.mod h1:iiK0YP1ZeepvmBQk/QpLEhhTNJgfzrpArPY/aFvc9yU=
|
||||
github.com/dghubble/oauth1 v0.7.1 h1:JjbOVSVVkms9A4h/sTQy5Jb2nFuAAVb2qVYgenJPyrE=
|
||||
github.com/dghubble/oauth1 v0.7.1/go.mod h1:0eEzON0UY/OLACQrmnjgJjmvCGXzjBCsZqL1kWDXtF0=
|
||||
github.com/dmarkham/enumer v1.5.6 h1:afhpzVOu8PoBL/+4J07PxVBf9cNnSawS/jAZK1snyLw=
|
||||
github.com/dmarkham/enumer v1.5.6/go.mod h1:eAawajOQnFBxf0NndBKgbqJImkHytg3eFEngUovqgo8=
|
||||
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
|
@ -166,6 +168,8 @@ github.com/envoyproxy/go-control-plane v0.10.1/go.mod h1:AY7fTTXNdv/aJ2O5jwpxAPO
|
|||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.6.2/go.mod h1:2t7qjJNvHPx8IjnBOzl9E9/baC+qXE/TeeyBRzgJDws=
|
||||
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
|
||||
github.com/fasthttp/router v1.4.11 h1:99BvgVxeS2oOZBHnKr/okpdPq1jkn8WvYA2trh/71LY=
|
||||
github.com/fasthttp/router v1.4.11/go.mod h1:luEEYkGBSAmYyPaMeIUGNgqY+FdHHYDOK9Kivaw7aNo=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
||||
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
||||
|
@ -235,6 +239,8 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
|
|||
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
|
||||
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
|
||||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
|
||||
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-yaml v1.9.5 h1:Eh/+3uk9kLxG4koCX6lRMAPS1OaMSAi+FJcya0INdB0=
|
||||
github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
|
@ -539,6 +545,8 @@ github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJ
|
|||
github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
|
||||
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/mymmrac/telego v0.16.1 h1:MMGW7CcyRtSmCH8EJf5mX+S9KemXFUuYD6h1W+8KU5U=
|
||||
github.com/mymmrac/telego v0.16.1/go.mod h1:SNwAJI5rkdBvma9WzbYo/jjrfCg8yzoFicBdyHLCW4s=
|
||||
github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022 h1:Ys0rDzh8s4UMlGaDa1UTA0sfKgvF0hQZzTYX8ktjiDc=
|
||||
github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022/go.mod h1:x4NsS+uc7ecH/Cbm9xKQ6XzmJM57rWTkjywjfB2yQ18=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
|
@ -555,6 +563,8 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
|
|||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pascaldekloe/name v1.0.0 h1:n7LKFgHixETzxpRv2R77YgPUFo85QHGZKrdaYm7eY5U=
|
||||
github.com/pascaldekloe/name v1.0.0/go.mod h1:Z//MfYJnH4jVpQ9wkclwu2I2MkHmXTlT9wR5UZScttM=
|
||||
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
|
||||
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
||||
|
@ -598,6 +608,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
|||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/sagikazarmark/crypt v0.4.0/go.mod h1:ALv2SRj7GxYV4HO9elxH9nS6M9gW+xDNxqmyJ6RfDFM=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo=
|
||||
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4=
|
||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
|
@ -633,7 +645,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
|
@ -642,7 +653,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/subosito/gotenv v1.3.0 h1:mjC+YW8QpAdXibNi+vNWgzmgBH4+5l5dCXv8cNysBLI=
|
||||
github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t6PwAXzs=
|
||||
|
@ -671,8 +681,9 @@ github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqri
|
|||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.14.0/go.mod h1:ol1PCaL0dX20wC0htZ7sYCsvCYmrouYra0zHzaclZhE=
|
||||
github.com/valyala/fasthttp v1.38.0 h1:yTjSSNjuDi2PPvXY2836bIwLmiTS2T4T9p1coQshpco=
|
||||
github.com/valyala/fasthttp v1.38.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||
github.com/valyala/fasthttp v1.39.0 h1:lW8mGeM7yydOqZKmwyMTaz/PH/A+CLgtmmcjv+OORfU=
|
||||
github.com/valyala/fasthttp v1.39.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
|
||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
|
||||
|
@ -785,8 +796,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
|
|||
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ=
|
||||
|
@ -1071,6 +1080,8 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
|||
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa h1:uKcci2q7Qtp6nMTC/AAvfNUAldFtJuHWV9/5QWiypts=
|
||||
golang.org/x/tools v0.1.13-0.20220804200503-81c7dc4e4efa/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
|
|
@ -24,7 +24,7 @@ func newApp(ctx context.Context, log logr.Logger, appname string, desc string) (
|
|||
dbApp, err := db.DbClient.DbApp.Create().
|
||||
SetName(appname).
|
||||
SetDescription(desc).
|
||||
SetStatus(interfaces.Enabled).
|
||||
SetStatus(interfaces.AppEnabled).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
newlogger.Error(err, "Error creating app")
|
||||
|
@ -249,7 +249,7 @@ func (app *App) AddFilter(ctx context.Context, filter interfaces.FilterI) error
|
|||
if err != nil {
|
||||
app.log.Error(err, "Error adding filter to app", "Filter", filter.GetName())
|
||||
return mperror.FilterErrors(err)
|
||||
}
|
||||
}
|
||||
app.dbApp = dbtmp
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -118,9 +118,9 @@ var _ = Describe("App", func() {
|
|||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
It("Should Be able to Set Status", func() {
|
||||
err := globalApp.SetStatus(mptest.Ctx, interfaces.Disabled)
|
||||
err := globalApp.SetStatus(mptest.Ctx, interfaces.AppDisabled)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalApp.GetStatus()).To(Equal(interfaces.Disabled))
|
||||
Expect(globalApp.GetStatus()).To(Equal(interfaces.AppDisabled))
|
||||
})
|
||||
})
|
||||
Context("Process Messages", func() {
|
||||
|
@ -156,7 +156,6 @@ var _ = Describe("App", func() {
|
|||
err = globalGroup.AddApp(mptest.Ctx, globalApp)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
|
||||
globalflt, err = mptest.Mp.GetFilterService().Create(mptest.Ctx, "NoOpFilter", "NoOp Filter", interfaces.AppFilter)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalflt).ToNot(BeNil())
|
||||
|
@ -164,7 +163,6 @@ var _ = Describe("App", func() {
|
|||
err = globalApp.AddFilter(mptest.Ctx, globalflt)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
|
||||
mymsg := msg.NewMessage(mptest.Ctx, "Message", mptest.App)
|
||||
Expect(mymsg).ToNot(BeNil())
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ var (
|
|||
// StatusValidator is a validator for the "Status" field enum values. It is called by the builders before save.
|
||||
func StatusValidator(_status interfaces.AppStatus) error {
|
||||
switch _status.String() {
|
||||
case "Enabled", "Disabled":
|
||||
case "AppEnabled", "AppDisabled":
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("dbapp: invalid enum value for Status field: %q", _status)
|
||||
|
|
|
@ -1,217 +0,0 @@
|
|||
package ent_test
|
||||
|
||||
import (
|
||||
// "context"
|
||||
// "fmt"
|
||||
|
||||
"context"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbapp"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/rules"
|
||||
)
|
||||
|
||||
var _ = Describe("Applications: ", func() {
|
||||
When("Creating", func() {
|
||||
DescribeTable("Some Apps",
|
||||
func(name string, description string, status dbapp.Status, Icon string, URL string,
|
||||
expectedName string, expectedDescription string, expectedStatus dbapp.Status, expectedIcon string, expectedURL string) {
|
||||
newapp, err := eClient.DbApp.Create().
|
||||
SetName(name).
|
||||
SetStatus(status).
|
||||
SetDescription(description).
|
||||
SetIcon(Icon).
|
||||
SetURL(URL).
|
||||
Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Name).To(Equal(expectedName))
|
||||
Expect(newapp.Status).To(Equal(expectedStatus))
|
||||
Expect(newapp.Description).To(Equal(expectedDescription))
|
||||
Expect(newapp.Icon).To(Equal(expectedIcon))
|
||||
Expect(newapp.URL).To(Equal(expectedURL))
|
||||
},
|
||||
Entry("a Normal App", "TestApp", "Test Description", dbapp.StatusEnabled, "https://example.com/icon.png", "https://example.com", "TestApp", "Test Description", dbapp.StatusEnabled, "https://example.com/icon.png", "https://example.com"),
|
||||
Entry("a Disabled App", "TestApp2", "Test Description", dbapp.StatusDisabled, "https://example.com/icon.png", "https://example.com", "TestApp2", "Test Description", dbapp.StatusDisabled, "https://example.com/icon.png", "https://example.com"),
|
||||
)
|
||||
})
|
||||
When("Creating a New App From Invalid Params Params", func() {
|
||||
It("should fail", func() {
|
||||
_, err := eClient.DbApp.Create().
|
||||
SetName("").
|
||||
SetStatus(dbapp.StatusEnabled).
|
||||
SetDescription("Test Description").
|
||||
SetIcon("https://example.com/icon.png").
|
||||
SetURL("https://example.com").
|
||||
Save(ctx)
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
})
|
||||
When("Getting a Disabled App", func() {
|
||||
It("should be disabled", func() {
|
||||
_, _ = eClient.DbApp.Query().All(ctx)
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Status).To(Equal(dbapp.StatusDisabled))
|
||||
})
|
||||
})
|
||||
When("Getting a Enabled App", func() {
|
||||
It("should be enabled", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Status).To(Equal(dbapp.StatusEnabled))
|
||||
})
|
||||
})
|
||||
When("Creating a New App From a Struct", func() {
|
||||
It("Can be saved to the Database", func() {
|
||||
newapp := &ent.DbApp{
|
||||
Name: "TestApp3",
|
||||
Description: "Test Description",
|
||||
Status: dbapp.StatusEnabled,
|
||||
Icon: "https://example.com/icon.png",
|
||||
URL: "https://example.com",
|
||||
}
|
||||
app, err := eClient.DbApp.Create().SetDbAppFromStruct(newapp).Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(app).ToNot(BeNil())
|
||||
Expect(app.Name).To(Equal(newapp.Name))
|
||||
Expect(app.Status).To(Equal(newapp.Status))
|
||||
Expect(app.Description).To(Equal(newapp.Description))
|
||||
Expect(app.Icon).To(Equal(newapp.Icon))
|
||||
Expect(app.URL).To(Equal(newapp.URL))
|
||||
})
|
||||
It("with a invlaid field it can not be saved to the Database", func() {
|
||||
newapp := &ent.DbApp{
|
||||
Name: "TestApp3",
|
||||
Description: "Test Description",
|
||||
Status: dbapp.StatusEnabled,
|
||||
Icon: "https//example.com/icon.png",
|
||||
URL: "https://example.com",
|
||||
}
|
||||
app, err := eClient.DbApp.Create().SetDbAppFromStruct(newapp).Save(ctx)
|
||||
Expect(err).To(Not(BeNil()))
|
||||
Expect(app).To(BeNil())
|
||||
Expect(err.Error()).To(ContainSubstring("failed on the 'url' tag"))
|
||||
})
|
||||
})
|
||||
When("Getting a existing app", func() {
|
||||
It("can modify name", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetName("TestApp4").Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Name).To(Equal("TestApp4"))
|
||||
})
|
||||
It("can modify description", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetDescription("Test Description2").Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Description).To(Equal("Test Description2"))
|
||||
})
|
||||
It("can modify status", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetStatus(dbapp.StatusDisabled).Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Status).To(Equal(dbapp.StatusDisabled))
|
||||
})
|
||||
It("can modify icon", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetIcon("https://example.com/icon2.png").Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.Icon).To(Equal("https://example.com/icon2.png"))
|
||||
})
|
||||
It("can modify url", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetURL("https://example.com").Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
Expect(newapp.URL).To(Equal("https://example.com"))
|
||||
})
|
||||
It("Can be deleted", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
err = eClient.DbApp.DeleteOne(newapp).Exec(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
newapp, err = eClient.DbApp.Query().Where(dbapp.Name("TestApp4")).Only(ctx)
|
||||
Expect(ent.IsNotFound(err)).To(BeTrue())
|
||||
Expect(newapp).To(BeNil())
|
||||
})
|
||||
It("has no Messages", func() {
|
||||
newapp, err := eClient.DbApp.Query().WithMessages().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).To(Not(BeNil()))
|
||||
msg, err := newapp.Edges.MessagesOrErr()
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(msg)).To(Equal(0))
|
||||
})
|
||||
It("Has no Filters", func() {
|
||||
newapp, err := eClient.DbApp.Query().WithFilters().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).To(Not(BeNil()))
|
||||
flt, err := newapp.Edges.FiltersOrErr()
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(flt)).To(Equal(0))
|
||||
})
|
||||
It("Has no Groups", func() {
|
||||
newapp, err := eClient.DbApp.Query().WithGroups().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).To(Not(BeNil()))
|
||||
grp, err := newapp.Edges.GroupsOrErr()
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(grp)).To(Equal(0))
|
||||
})
|
||||
It("Has No Transports",func() {
|
||||
newapp, err := eClient.DbApp.Query().WithTransportRecipients().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).To(Not(BeNil()))
|
||||
trp, err := newapp.Edges.TransportRecipientsOrErr()
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(trp)).To(Equal(0))
|
||||
})
|
||||
It("can not modify tenant id", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
newtnt := *rules.FromContextGetTenant(ctx)
|
||||
newtnt.ID = newtnt.ID + 1
|
||||
newapp, err = eClient.DbApp.UpdateOne(newapp).SetTenant(&newtnt).Save(ctx)
|
||||
Expect(err).ToNot(BeNil())
|
||||
Expect(newapp).To(BeNil())
|
||||
})
|
||||
It("Can Modify the Tenant ID if Global Admin", func() {
|
||||
newapp, err := eClient.DbApp.Query().Where(dbapp.Name("TestApp2")).Only(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newapp).ToNot(BeNil())
|
||||
viewer := rules.FromContext(ctx)
|
||||
uv := viewer.(*rules.UserViewer)
|
||||
newctx := rules.NewContext(context.Background(), rules.UserViewer{T: uv.T, Role: rules.GlobalAdmin})
|
||||
tnt, err := eClient.Tenant.Create().SetName("Default2").Save(newctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tnt).ToNot(BeNil())
|
||||
newapp1, err1 := eClient.DbApp.UpdateOne(newapp).SetTenant(tnt).Save(newctx)
|
||||
Expect(err1).To(BeNil())
|
||||
Expect(newapp1).ToNot(BeNil())
|
||||
Expect(newapp1.TenantID).To(Equal(tnt.ID))
|
||||
})
|
||||
})
|
||||
|
||||
})
|
|
@ -1,139 +0,0 @@
|
|||
package ent_test
|
||||
|
||||
import (
|
||||
// "context"
|
||||
"time"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbapp"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/dbmessage"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var DemoApp *ent.DbApp
|
||||
var DemoMsg *ent.DbMessage
|
||||
|
||||
var _ = Describe("Messages: ", func() {
|
||||
It("Setup Demo App", func() {
|
||||
var err error
|
||||
DemoApp, err = eClient.DbApp.Create().
|
||||
SetName("DemoApp").
|
||||
SetStatus(dbapp.StatusEnabled).
|
||||
SetDescription("Demo Application").
|
||||
SetIcon("https://example.com/icon.png").
|
||||
SetURL("https://example.com").
|
||||
Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(DemoApp).ToNot(BeNil())
|
||||
})
|
||||
When("Creating", func() {
|
||||
DescribeTable("Some Messages",
|
||||
func(message string, shortmsg string, topic string, severity int, ts time.Time, expectedmessage string, expectedshortmsg string, expectedtopic string, expectedseverity int, expectedts time.Time) {
|
||||
newmsg, err := eClient.DbMessage.Create().
|
||||
SetMessage(message).
|
||||
SetShortMsg(shortmsg).
|
||||
SetTopic(topic).
|
||||
SetSeverity(severity).
|
||||
SetTimestamp(ts).
|
||||
SetApp(DemoApp).
|
||||
Save(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newmsg).ToNot(BeNil())
|
||||
Expect(newmsg.Message).To(Equal(expectedmessage))
|
||||
Expect(newmsg.ShortMsg).To(HaveValue(Equal(expectedshortmsg)))
|
||||
Expect(newmsg.Topic).To(HaveValue(Equal(expectedtopic)))
|
||||
Expect(newmsg.Severity).To(Equal(expectedseverity))
|
||||
Expect(newmsg.Timestamp).To(Equal(expectedts))
|
||||
},
|
||||
Entry("Normal Message", "message", "shortmsg", "topic", 3, time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), "message", "shortmsg", "topic", 3, time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)),
|
||||
Entry("Another Normal Message", "anothermessage", "anothershortmsg", "anothertopic", 1, time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), "anothermessage", "anothershortmsg", "anothertopic", 1, time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)),
|
||||
)
|
||||
})
|
||||
When("Creating Messages with Fields", func() {
|
||||
It("Should be ok", func() {
|
||||
var err error
|
||||
DemoMsg, err = eClient.DbMessage.Create().
|
||||
SetMessage("message").
|
||||
SetShortMsg("shortmsg").
|
||||
SetTopic("topic").
|
||||
SetSeverity(3).
|
||||
SetTimestamp(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)).
|
||||
SetApp(DemoApp).
|
||||
Save(ctx)
|
||||
|
||||
var1, err1 := eClient.DbMessageFields.Create().SetName("key1").SetValue("value1").SetOwner(DemoMsg).Save(ctx)
|
||||
var2, err2 := eClient.DbMessageFields.Create().SetName("key2").SetValue("value2").SetOwner(DemoMsg).Save(ctx)
|
||||
|
||||
Expect(err).To(BeNil())
|
||||
Expect(DemoMsg).ToNot(BeNil())
|
||||
Expect(DemoMsg.Message).To(Equal("message"))
|
||||
Expect(DemoMsg.ShortMsg).To(HaveValue(Equal("shortmsg")))
|
||||
Expect(DemoMsg.Topic).To(HaveValue(Equal("topic")))
|
||||
Expect(DemoMsg.Severity).To(Equal(3))
|
||||
Expect(DemoMsg.Timestamp).To(Equal(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)))
|
||||
|
||||
Expect(err1).To(BeNil())
|
||||
Expect(var1).ToNot(BeNil())
|
||||
Expect(var1.Name).To(Equal("key1"))
|
||||
Expect(var1.Value).To(Equal("value1"))
|
||||
Expect(err2).To(BeNil())
|
||||
Expect(var2).ToNot(BeNil())
|
||||
Expect(var2.Name).To(Equal("key2"))
|
||||
Expect(var2.Value).To(Equal("value2"))
|
||||
|
||||
|
||||
dbmsg, err := eClient.DbMessage.Query().Where(dbmessage.ID(DemoMsg.ID)).WithFields().WithApp().Only(ctx)
|
||||
|
||||
Expect(err).To(BeNil())
|
||||
Expect(dbmsg).ToNot(BeNil())
|
||||
Expect(dbmsg.Message).To(Equal("message"))
|
||||
Expect(dbmsg.ShortMsg).To(HaveValue(Equal("shortmsg")))
|
||||
Expect(dbmsg.Topic).To(HaveValue(Equal("topic")))
|
||||
Expect(dbmsg.Severity).To(Equal(3))
|
||||
Expect(dbmsg.Timestamp).To(Equal(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)))
|
||||
Expect(dbmsg.Edges.App.ID).To(Equal(DemoApp.ID))
|
||||
Expect(dbmsg.Edges.Fields).To(HaveLen(2))
|
||||
Expect(dbmsg.Edges.Fields[0].Name).To(Equal("key1"))
|
||||
Expect(dbmsg.Edges.Fields[0].Value).To(Equal("value1"))
|
||||
Expect(dbmsg.Edges.Fields[1].Name).To(Equal("key2"))
|
||||
Expect(dbmsg.Edges.Fields[1].Value).To(Equal("value2"))
|
||||
})
|
||||
It("Cannot Have Duplicate Fields", func() {
|
||||
newmsg, err := eClient.DbMessage.Query().WithFields().Where(dbmessage.ID(DemoMsg.ID)).First(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(newmsg).ToNot(BeNil())
|
||||
var3, err := eClient.DbMessageFields.Create().SetName("key1").SetValue("value1").SetOwner(newmsg).Save(ctx)
|
||||
Expect(err).ToNot(BeNil())
|
||||
Expect(var3).To(BeNil())
|
||||
})
|
||||
})
|
||||
When("Retrieving Messages", func() {
|
||||
It("Should have 3 messages", func() {
|
||||
messages, err := eClient.DbMessage.Query().All(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(messages).ToNot(BeNil())
|
||||
Expect(len(messages)).To(Equal(3))
|
||||
})
|
||||
})
|
||||
When("Message Must be Associated with a App", func() {
|
||||
It("Should fail to create a Message without an App", func() {
|
||||
_, err := eClient.DbMessage.Create().
|
||||
SetMessage("message").
|
||||
SetShortMsg("shortmsg").
|
||||
SetTopic("topic").
|
||||
SetSeverity(3).
|
||||
SetTimestamp(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)).
|
||||
Save(ctx)
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
It("Should have the Apps", func() {
|
||||
msg, err := eClient.DbMessage.Query().WithApp().First(ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(msg).ToNot(BeNil())
|
||||
Expect(msg.Edges.App).ToNot(BeNil())
|
||||
Expect(msg.Edges.App.Name).To(Equal(DemoApp.Name))
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,49 +0,0 @@
|
|||
package ent_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"context"
|
||||
|
||||
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/rules"
|
||||
_ "github.com/Fishwaldo/mouthpiece/pkg/ent/runtime"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/ent/migrate"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func TestEnt(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Ent Suite")
|
||||
}
|
||||
|
||||
var eClient *ent.Client
|
||||
var ctx context.Context
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
var err error
|
||||
eClient, err = ent.Open(dialect.SQLite, "file:test.db?mode=memory&cache=shared&_fk=1")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(eClient).ToNot(BeNil())
|
||||
// Run the automatic migration tool to create all schema resources.
|
||||
Expect(eClient.Schema.Create(context.Background(), migrate.WithGlobalUniqueID(true))).To(BeNil())
|
||||
tntrole := &rules.UserViewer{
|
||||
Role: rules.GlobalAdmin,
|
||||
}
|
||||
ctx = rules.NewContext(context.Background(), tntrole)
|
||||
tnt, err := eClient.Tenant.Create().SetName("Default").Save(ctx)
|
||||
tntrole.Role = rules.Admin
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tnt).ToNot(BeNil())
|
||||
tntrole.T = tnt
|
||||
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
eClient.Close()
|
||||
})
|
File diff suppressed because one or more lines are too long
|
@ -36,7 +36,7 @@ var (
|
|||
DbAppsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"Enabled", "Disabled"}},
|
||||
{Name: "status", Type: field.TypeEnum, Enums: []string{"AppEnabled", "AppDisabled"}},
|
||||
{Name: "description", Type: field.TypeString},
|
||||
{Name: "icon", Type: field.TypeString, Nullable: true},
|
||||
{Name: "url", Type: field.TypeString, Nullable: true},
|
||||
|
|
|
@ -324,7 +324,21 @@ func init() {
|
|||
// dbuserDescEmail is the schema descriptor for Email field.
|
||||
dbuserDescEmail := dbuserFields[0].Descriptor()
|
||||
// dbuser.EmailValidator is a validator for the "Email" field. It is called by the builders before save.
|
||||
dbuser.EmailValidator = dbuserDescEmail.Validators[0].(func(string) error)
|
||||
dbuser.EmailValidator = func() func(string) error {
|
||||
validators := dbuserDescEmail.Validators
|
||||
fns := [...]func(string) error{
|
||||
validators[0].(func(string) error),
|
||||
validators[1].(func(string) error),
|
||||
}
|
||||
return func(_Email string) error {
|
||||
for _, fn := range fns {
|
||||
if err := fn(_Email); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
// dbuserDescName is the schema descriptor for Name field.
|
||||
dbuserDescName := dbuserFields[1].Descriptor()
|
||||
// dbuser.NameValidator is a validator for the "Name" field. It is called by the builders before save.
|
||||
|
|
|
@ -23,7 +23,7 @@ func (DbApp) Fields() []ent.Field {
|
|||
Validate(validate.EntStringValidator("required,max=255,alphanum")).
|
||||
StructTag(`doc:"Application Name"`),
|
||||
field.Enum("Status").
|
||||
GoType(interfaces.AppStatus(interfaces.Enabled)).
|
||||
GoType(interfaces.AppStatus(interfaces.AppEnabled)).
|
||||
StructTag(`doc:"Status of Application"`),
|
||||
field.String("Description").
|
||||
NotEmpty().
|
||||
|
@ -54,4 +54,4 @@ func (DbApp) Mixin() []ent.Mixin {
|
|||
BaseMixin{},
|
||||
TenantMixin{},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/validate"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/entsql"
|
||||
"entgo.io/ent/schema/edge"
|
||||
|
@ -26,6 +29,7 @@ func (DbUser) Fields() []ent.Field {
|
|||
return []ent.Field{
|
||||
field.String("Email").
|
||||
NotEmpty().
|
||||
Validate(validate.EntStringValidator("required,email")).
|
||||
StructTag(`doc:"Email Address of the User`),
|
||||
field.String("Name").
|
||||
NotEmpty().
|
||||
|
|
|
@ -2,80 +2,178 @@ package evalfilter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mperror"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/log"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/msg"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/skx/evalfilter/v2"
|
||||
"github.com/skx/evalfilter/v2/object"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var llog logr.Logger
|
||||
//go:embed scripts
|
||||
var embededScripts embed.FS
|
||||
|
||||
func init() {
|
||||
filter.RegisterFilterImpl("EvalFilter", EvalFilterFactory{})
|
||||
}
|
||||
|
||||
type EvalFilter struct {
|
||||
ready bool
|
||||
filter *evalfilter.Eval
|
||||
processedMessage *msg.Message
|
||||
config []filter.Filterconfig
|
||||
processedMessage interfaces.MessageI
|
||||
config *EvalFilterConfig
|
||||
ctx context.Context
|
||||
filtertype FilterType
|
||||
filtername string
|
||||
log logr.Logger
|
||||
}
|
||||
|
||||
var (
|
||||
FilterImplDetails = filter.FilterImplDetails{Factory: NewEvalFilter}
|
||||
type EvalFilterConfig struct {
|
||||
Script string
|
||||
}
|
||||
|
||||
func (c *EvalFilterConfig) AsJSON() (string, error) {
|
||||
b, err := json.Marshal(c)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
func (c *EvalFilterConfig) FromJSON(data string) error {
|
||||
return json.Unmarshal([]byte(data), c)
|
||||
}
|
||||
|
||||
type FilterType int
|
||||
|
||||
const (
|
||||
FilterTypeInvalid FilterType = iota
|
||||
FilterTypeFile
|
||||
FilterTypeEmbeded
|
||||
FilterTypeStatic
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("Registering EvalFilter")
|
||||
filter.RegisterFilterImpl("EvalFilter", FilterImplDetails)
|
||||
type EvalFilterFactory struct {
|
||||
filtertype FilterType
|
||||
filtersource string
|
||||
}
|
||||
|
||||
func NewEvalFilter(ctx context.Context, config []filter.Filterconfig) (filter.FilterImplI, error) {
|
||||
llog = log.Log.WithName("EvalFilter")
|
||||
|
||||
if idx := slices.IndexFunc(config, func(config filter.Filterconfig) bool { return config.Name == "name" }); idx == -1 {
|
||||
return &EvalFilter{}, fmt.Errorf("EvalFilter: No name specified")
|
||||
func (eff EvalFilterFactory) FilterFactory(ctx context.Context, config string) (interfaces.FilterImplI, error) {
|
||||
var cfg EvalFilterConfig
|
||||
if err := cfg.FromJSON(config); err != nil {
|
||||
return nil, mperror.ErrFilterConfigInvalid
|
||||
}
|
||||
eflt := &EvalFilter{
|
||||
config: &cfg,
|
||||
filtertype: eff.filtertype,
|
||||
log: log.Log.WithName("EvalFilter"),
|
||||
}
|
||||
|
||||
if idx := slices.IndexFunc(config, func(config filter.Filterconfig) bool { return config.Name == "script" }); idx == -1 {
|
||||
return &EvalFilter{}, fmt.Errorf("EvalFilter: No Script specified")
|
||||
}
|
||||
var filterscript string
|
||||
|
||||
ef := &EvalFilter{
|
||||
config: config,
|
||||
switch eff.filtertype {
|
||||
case FilterTypeFile:
|
||||
if filecontext, err := os.ReadFile(eff.filtersource); err != nil {
|
||||
eflt.log.Error(err, "Filter Script File Read Failed", "script", eff.filtersource)
|
||||
return nil, err
|
||||
} else {
|
||||
filterscript = string(filecontext)
|
||||
eflt.filtername = trimFileExtension(filepath.Base(eff.filtersource))
|
||||
}
|
||||
case FilterTypeEmbeded:
|
||||
if filecontent, err := fs.ReadFile(embededScripts, eff.filtersource); err != nil {
|
||||
eflt.log.Error(err, "Filter Script Embeded Read Failed", "script", eff.filtersource)
|
||||
return nil, err
|
||||
} else {
|
||||
filterscript = string(filecontent)
|
||||
eflt.filtername = trimFileExtension(filepath.Base(eff.filtersource))
|
||||
}
|
||||
case FilterTypeStatic:
|
||||
filterscript = eflt.config.Script
|
||||
eflt.filtername = "Static"
|
||||
default:
|
||||
return nil, mperror.ErrFilterConfigInvalid
|
||||
}
|
||||
return ef, nil
|
||||
eflt.log = log.Log.WithName(eflt.filtername)
|
||||
|
||||
eflt.filter = evalfilter.New(filterscript)
|
||||
eflt.filter.AddFunction("printf", eflt.fnPrintf)
|
||||
eflt.filter.AddFunction("print", eflt.fnPrint)
|
||||
eflt.filter.AddFunction("setfield", eflt.fnSetField)
|
||||
eflt.filter.AddFunction("clearfield", eflt.fnClearField)
|
||||
eflt.filter.AddFunction("setshortmessage", eflt.fnSetShortMessage)
|
||||
eflt.filter.AddFunction("setseverity", eflt.fnSetSeverity)
|
||||
if err := eflt.filter.Prepare(); err != nil {
|
||||
eflt.log.Error(err, "Compile Filter Script Failed", "filter", eflt.FilterName())
|
||||
eflt.ready = false
|
||||
return nil, err
|
||||
}
|
||||
eflt.log.V(1).Info("Compile Filter Script Success", "filter", eflt.FilterName())
|
||||
eflt.ready = true
|
||||
return eflt, nil
|
||||
|
||||
}
|
||||
|
||||
func (ef *EvalFilter) FilterName() string {
|
||||
return "EvalFilter"
|
||||
func (sff EvalFilterFactory) DefaultConfig(ctx context.Context) interfaces.MarshableConfigI {
|
||||
return &EvalFilterConfig{}
|
||||
}
|
||||
|
||||
func (ev *EvalFilter) Init() error {
|
||||
idx := slices.IndexFunc(ev.config, func(config filter.Filterconfig) bool { return config.Name == "script" })
|
||||
|
||||
ev.filter = evalfilter.New(ev.config[idx].Value)
|
||||
ev.filter.AddFunction("printf", ev.fnPrintf)
|
||||
ev.filter.AddFunction("print", ev.fnPrint)
|
||||
ev.filter.AddFunction("setfield", ev.fnSetField)
|
||||
ev.filter.AddFunction("clearfield", ev.fnClearField)
|
||||
ev.filter.AddFunction("setshortmessage", ev.fnSetShortMessage)
|
||||
ev.filter.AddFunction("setseverity", ev.fnSetSeverity)
|
||||
if err := ev.filter.Prepare(); err != nil {
|
||||
llog.Error(err, "Compile Filter Script Failed", "filter", ev.getName())
|
||||
ev.ready = false
|
||||
return err
|
||||
}
|
||||
llog.V(1).Info("Compile Filter Script Success", "filter", ev.getName())
|
||||
ev.ready = true
|
||||
func (sf *EvalFilter) Init(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ev *EvalFilter) getName() string {
|
||||
idx := slices.IndexFunc(ev.config, func(config filter.Filterconfig) bool { return config.Name == "name" })
|
||||
return ev.config[idx].Value
|
||||
func (ef *EvalFilter) Process(ctx context.Context, msg interfaces.MessageI) (interfaces.FilterAction, error) {
|
||||
ef.ctx = ctx
|
||||
ef.processedMessage = msg
|
||||
|
||||
if !ef.ready {
|
||||
if err := ef.Init(ctx); err != nil {
|
||||
ef.log.Error(err, "Filter Init Failed", "filter", ef.FilterName())
|
||||
return interfaces.FilterPass, err
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
ef.log.Error(err.(error), "Filter Script Error", "filter", ef.FilterName())
|
||||
}
|
||||
}()
|
||||
ef.filter.SetContext(ctx)
|
||||
ok, err := ef.filter.Run(getFlatMessage(ctx, msg))
|
||||
if err != nil {
|
||||
ef.log.Info("Filter Run Failed", "filter", ef.FilterName(), "result", ok, "Error", err)
|
||||
return interfaces.FilterPass, err
|
||||
}
|
||||
ef.log.V(1).Info("Filter Run Success", "filter", ef.FilterName(), "result", ok)
|
||||
|
||||
ef.ctx = nil
|
||||
ef.processedMessage = nil
|
||||
|
||||
if ok {
|
||||
return interfaces.FilterMatch, nil
|
||||
} else {
|
||||
return interfaces.FilterNoMatch, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (sf *EvalFilter) FilterName() string {
|
||||
return sf.filtername
|
||||
}
|
||||
|
||||
func (sf *EvalFilter) SetConfig(ctx context.Context, config interfaces.MarshableConfigI) error {
|
||||
var ok bool
|
||||
if sf.config, ok = config.(*EvalFilterConfig); !ok {
|
||||
return mperror.ErrFilterConfigInvalid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (sf *EvalFilter) GetConfig(ctx context.Context) (interfaces.MarshableConfigI, error) {
|
||||
return sf.config, nil
|
||||
}
|
||||
|
||||
func (ev *EvalFilter) fnPrintf(args []object.Object) object.Object {
|
||||
|
@ -105,13 +203,13 @@ func (ev *EvalFilter) fnPrintf(args []object.Object) object.Object {
|
|||
// Call the helper
|
||||
out := fmt.Sprintf(fs, fmtArgs...)
|
||||
|
||||
llog.Info("Filter Script Output", "filter", ev.getName(), "output", out)
|
||||
ev.log.Info("Filter Script Output", "filter", ev.FilterName(), "output", out)
|
||||
return &object.Void{}
|
||||
}
|
||||
|
||||
func (ev *EvalFilter) fnPrint(args []object.Object) object.Object {
|
||||
for _, e := range args {
|
||||
llog.Info("Filter Script Output", "filter", ev.getName(), "Output", e.Inspect())
|
||||
ev.log.Info("Filter Script Output", "filter", ev.FilterName(), "Output", e.Inspect())
|
||||
}
|
||||
return &object.Void{}
|
||||
}
|
||||
|
@ -132,8 +230,16 @@ func (ev *EvalFilter) fnSetField(args []object.Object) object.Object {
|
|||
|
||||
arg := args[0].ToInterface()
|
||||
|
||||
llog.Info("Setting Field Value", "filter", ev.getName(), "field", fld, "value", arg)
|
||||
ev.processedMessage.Body.Fields[fld] = arg
|
||||
if val, ok := arg.(string); !ok {
|
||||
ev.log.Error(nil, "Cannot Convert Argument to String", "filter", ev.FilterName(), "field", fld, "value", val)
|
||||
return &object.Null{}
|
||||
}
|
||||
|
||||
ev.log.Info("Setting Field Value", "filter", ev.FilterName(), "field", fld, "value", arg)
|
||||
if err := ev.processedMessage.SetMetadata(ev.ctx, fld, arg); err != nil {
|
||||
ev.log.Error(err, "Set Field Failed", "filter", ev.FilterName(), "field", fld, "value", arg)
|
||||
return &object.Null{}
|
||||
}
|
||||
return &object.Void{}
|
||||
}
|
||||
|
||||
|
@ -146,11 +252,9 @@ func (ev *EvalFilter) fnClearField(args []object.Object) object.Object {
|
|||
return &object.Null{}
|
||||
}
|
||||
fld := args[0].(*object.String).Value
|
||||
llog.Info("Clearing Field Value", "filter", ev.getName(), "field", fld)
|
||||
if _, ok := ev.processedMessage.Body.Fields[fld]; ok {
|
||||
delete(ev.processedMessage.Body.Fields, fld)
|
||||
} else {
|
||||
llog.Info("Field Not Found", "filter", ev.getName(), "field", fld)
|
||||
ev.log.Info("Clearing Field Value", "filter", ev.FilterName(), "field", fld)
|
||||
if err := ev.processedMessage.SetMetadata(ev.ctx, fld, nil); err != nil {
|
||||
ev.log.Info("Clear Field Failed", "filter", ev.FilterName(), "field", fld)
|
||||
}
|
||||
return &object.Void{}
|
||||
}
|
||||
|
@ -164,8 +268,8 @@ func (ev *EvalFilter) fnSetShortMessage(arg []object.Object) object.Object {
|
|||
return &object.Null{}
|
||||
}
|
||||
msg := arg[0].(*object.String).Value
|
||||
llog.Info("Setting Short Message", "filter", ev.getName(), "message", msg)
|
||||
ev.processedMessage.Body.ShortMsg = msg
|
||||
ev.log.Info("Setting Short Message", "filter", ev.FilterName(), "Short Message", msg)
|
||||
ev.processedMessage.SetShortMsg(ev.ctx, msg)
|
||||
return &object.Void{}
|
||||
}
|
||||
|
||||
|
@ -174,35 +278,29 @@ func (ev *EvalFilter) fnSetSeverity(arg []object.Object) object.Object {
|
|||
return &object.Null{}
|
||||
}
|
||||
// Type-check
|
||||
if arg[0].Type() != object.STRING {
|
||||
if arg[0].Type() != object.INTEGER {
|
||||
return &object.Null{}
|
||||
}
|
||||
msg := arg[0].(*object.String).Value
|
||||
llog.Info("Setting Severity", "filter", ev.getName(), "Severity", msg)
|
||||
ev.processedMessage.Body.Severity = msg
|
||||
msg := arg[0].(*object.Integer).Value
|
||||
ev.log.Info("Setting Severity", "filter", ev.FilterName(), "Severity", msg)
|
||||
ev.processedMessage.SetSeverity(ev.ctx, int(msg))
|
||||
return &object.Void{}
|
||||
}
|
||||
|
||||
func (ev *EvalFilter) Process(ctx context.Context, msg *msg.Message) (bool, error) {
|
||||
if !ev.ready {
|
||||
if err := ev.Init(); err != nil {
|
||||
llog.Error(err, "Filter Init Failed", "filter", ev.getName())
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
llog.Error(err.(error), "Filter Script Error", "filter", ev.getName())
|
||||
}
|
||||
}()
|
||||
ev.processedMessage = msg
|
||||
ev.filter.SetContext(ctx)
|
||||
ok, err := ev.filter.Run(msg.Body)
|
||||
ev.processedMessage = nil
|
||||
if err != nil {
|
||||
llog.Info("Filter Run Failed", "filter", ev.getName(), "result", ok, "Error", err)
|
||||
return true, err
|
||||
}
|
||||
llog.V(1).Info("Filter Run Success", "filter", ev.getName(), "result", ok)
|
||||
return ok, nil
|
||||
type FlatMessage struct {
|
||||
Message string
|
||||
Severity int
|
||||
//ShortMsg *string
|
||||
//Topic *string
|
||||
TimeStamp time.Time
|
||||
}
|
||||
|
||||
func getFlatMessage(ctx context.Context, mymsg interfaces.MessageI) FlatMessage {
|
||||
var fm FlatMessage
|
||||
fm.Message = mymsg.GetMessage()
|
||||
fm.Severity = mymsg.GetSeverity()
|
||||
//fm.ShortMsg = *mymsg.GetShortMsg()
|
||||
//fm.Topic = *mymsg.GetTopic()
|
||||
fm.TimeStamp = mymsg.GetTimestamp()
|
||||
return fm
|
||||
}
|
57
pkg/filter/evalfilter/evalfilter_suite_test.go
Normal file
57
pkg/filter/evalfilter/evalfilter_suite_test.go
Normal file
|
@ -0,0 +1,57 @@
|
|||
package evalfilter_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter"
|
||||
_ "github.com/Fishwaldo/mouthpiece/pkg/filter/evalfilter"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestEvalfilter(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Evalfilter Suite")
|
||||
}
|
||||
|
||||
var globalFilter interfaces.FilterImplI
|
||||
|
||||
var _ = Describe("Evalfilter", func() {
|
||||
Context("It Should Register Filters", func() {
|
||||
It("Embeded Scripts", func() {
|
||||
filters := filter.GetFilterImpls(context.Background())
|
||||
Expect(filters).ToNot(BeNil())
|
||||
})
|
||||
It("SHould Create a Filter From a script", func() {
|
||||
var err error
|
||||
globalFilter, err = filter.GetNewFilterImpl(context.Background(), "FindSeverity", "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalFilter).ToNot(BeNil())
|
||||
Expect(globalFilter.FilterName()).To(Equal("FindSeverity"))
|
||||
})
|
||||
})
|
||||
Context("Should Filter Messages", func() {
|
||||
It("Should Filter a Message", func() {
|
||||
ctrl := gomock.NewController(GinkgoT())
|
||||
msg := mptest.NewMockMessageI(ctrl)
|
||||
msg.EXPECT().GetSeverity().Return(3).AnyTimes()
|
||||
msg.EXPECT().GetMessage().Return("Test warning Message").AnyTimes()
|
||||
msg.EXPECT().GetShortMsg().Return(nil).AnyTimes()
|
||||
msg.EXPECT().GetTopic().Return(nil).AnyTimes()
|
||||
msg.EXPECT().GetTimestamp().Return(time.Now()).AnyTimes()
|
||||
msg.EXPECT().SetSeverity(gomock.Any(), 4).Return(nil).AnyTimes()
|
||||
res, err := globalFilter.Process(context.Background(), msg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(res).To(Equal(interfaces.FilterMatch))
|
||||
})
|
||||
})
|
||||
})
|
|
@ -2,15 +2,15 @@
|
|||
// If the content of the Messages contains Warning, Error etc
|
||||
|
||||
// If the Severity is already set, skip this
|
||||
if (len(Severity) > 0) {
|
||||
return true;
|
||||
}
|
||||
severity = "Info";
|
||||
//if (len(Severity) > 0) {
|
||||
// return true;
|
||||
//}
|
||||
severity = 3;
|
||||
if (Message ~= /warning/i ) {
|
||||
severity = "Warning";
|
||||
severity = 4;
|
||||
}
|
||||
if (Message ~= /error/i ) {
|
||||
severity = "Error";
|
||||
severity = 5;
|
||||
}
|
||||
setseverity(severity);
|
||||
return true;
|
42
pkg/filter/evalfilter/utils.go
Normal file
42
pkg/filter/evalfilter/utils.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package evalfilter
|
||||
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"embed"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerFileScripts()
|
||||
}
|
||||
|
||||
|
||||
func filterFiles(efs embed.FS, root, ext string) []string {
|
||||
var a []string
|
||||
fs.WalkDir(efs, root, func(s string, d fs.DirEntry, e error) error {
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if filepath.Ext(d.Name()) == ext {
|
||||
a = append(a, s)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return a
|
||||
}
|
||||
|
||||
func trimFileExtension(fileName string) string {
|
||||
return strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||
}
|
||||
|
||||
func registerFileScripts() {
|
||||
for _, f := range filterFiles(embededScripts, "scripts", ".ef") {
|
||||
//fmt.Printf("Registering %s\n", trimFileExtension(filepath.Base(f)))
|
||||
filter.RegisterFilterImpl(trimFileExtension(filepath.Base(f)), EvalFilterFactory{FilterTypeEmbeded, f})
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter/field"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mperror"
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
|
@ -15,19 +15,20 @@ import (
|
|||
)
|
||||
|
||||
func TestField(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Field Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Severity", func() {
|
||||
var (
|
||||
mockMessage *mock_interfaces.MockMessageI
|
||||
mockMessage *mptest.MockMessageI
|
||||
flt interfaces.FilterImplI
|
||||
ctrl *gomock.Controller
|
||||
)
|
||||
BeforeEach(func() {
|
||||
ctrl = gomock.NewController(GinkgoT())
|
||||
mockMessage = mock_interfaces.NewMockMessageI(ctrl)
|
||||
mockMessage = mptest.NewMockMessageI(ctrl)
|
||||
|
||||
fltfactory := &field.FieldFilterFactory{}
|
||||
var err error
|
||||
|
|
|
@ -2,7 +2,6 @@ package filter
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
|
@ -16,8 +15,6 @@ import (
|
|||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
//go:embed scripts
|
||||
var ScriptFiles embed.FS
|
||||
|
||||
type Filter struct {
|
||||
interfaces.CacheAble
|
||||
|
@ -27,6 +24,8 @@ type Filter struct {
|
|||
log logr.Logger
|
||||
}
|
||||
|
||||
|
||||
//XXX TODO: SHould return a error
|
||||
func newFilter(ctx context.Context, log logr.Logger, fltimpl string, name string, flttype interfaces.FilterType) interfaces.FilterI {
|
||||
newlog := log.WithName("Filter")
|
||||
newlog.Info("Creating new filter")
|
||||
|
|
59
pkg/filter/noop/noop_suite_test.go
Normal file
59
pkg/filter/noop/noop_suite_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package noopfilter_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
_ "github.com/Fishwaldo/mouthpiece/pkg/filter/noop"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestNoop(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Noop Suite")
|
||||
}
|
||||
|
||||
var globalFilter interfaces.FilterImplI
|
||||
|
||||
var _ = Describe("Evalfilter", func() {
|
||||
Context("It Should Register Filters", func() {
|
||||
It("Embeded Scripts", func() {
|
||||
filters := filter.GetFilterImpls(context.Background())
|
||||
Expect(filters).ToNot(BeNil())
|
||||
})
|
||||
It("SHould Create a Filter From a script", func() {
|
||||
var err error
|
||||
globalFilter, err = filter.GetNewFilterImpl(context.Background(), "NoOpFilter", "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalFilter).ToNot(BeNil())
|
||||
Expect(globalFilter.FilterName()).To(Equal("NoOpFilter"))
|
||||
})
|
||||
})
|
||||
Context("Should Filter Messages", func() {
|
||||
It("Should Filter a Message", func() {
|
||||
ctrl := gomock.NewController(GinkgoT())
|
||||
msg := mptest.NewMockMessageI(ctrl)
|
||||
msg.EXPECT().GetSeverity().Return(3).AnyTimes()
|
||||
msg.EXPECT().GetMessage().Return("Test warning Message").AnyTimes()
|
||||
msg.EXPECT().GetShortMsg().Return(nil).AnyTimes()
|
||||
msg.EXPECT().GetTopic().Return(nil).AnyTimes()
|
||||
msg.EXPECT().GetTimestamp().Return(time.Now()).AnyTimes()
|
||||
msg.EXPECT().SetSeverity(gomock.Any(), 4).Return(nil).AnyTimes()
|
||||
msg.EXPECT().GetID().Return(uuid.New()).AnyTimes()
|
||||
res, err := globalFilter.Process(context.Background(), msg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(res).To(Equal(interfaces.FilterPass))
|
||||
})
|
||||
})
|
||||
})
|
|
@ -6,8 +6,9 @@ import (
|
|||
"encoding/json"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/filter/severity"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -15,19 +16,20 @@ import (
|
|||
|
||||
|
||||
func TestSeverity(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Severity Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Severity", func() {
|
||||
var (
|
||||
mockMessage *mock_interfaces.MockMessageI
|
||||
mockMessage *mptest.MockMessageI
|
||||
flt interfaces.FilterImplI
|
||||
ctrl *gomock.Controller
|
||||
)
|
||||
BeforeEach(func() {
|
||||
ctrl = gomock.NewController(GinkgoT())
|
||||
mockMessage = mock_interfaces.NewMockMessageI(ctrl)
|
||||
mockMessage = mptest.NewMockMessageI(ctrl)
|
||||
|
||||
fltfactory := &severity.SevFilterFactory{}
|
||||
var err error
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
const _AppStatusName = "EnabledDisabled"
|
||||
const _AppStatusName = "AppEnabledAppDisabled"
|
||||
|
||||
var _AppStatusIndex = [...]uint8{0, 7, 15}
|
||||
var _AppStatusIndex = [...]uint8{0, 10, 21}
|
||||
|
||||
const _AppStatusLowerName = "enableddisabled"
|
||||
const _AppStatusLowerName = "appenabledappdisabled"
|
||||
|
||||
func (i AppStatus) String() string {
|
||||
if i < 0 || i >= AppStatus(len(_AppStatusIndex)-1) {
|
||||
|
@ -26,22 +26,22 @@ func (i AppStatus) String() string {
|
|||
// Re-run the stringer command to generate them again.
|
||||
func _AppStatusNoOp() {
|
||||
var x [1]struct{}
|
||||
_ = x[Enabled-(0)]
|
||||
_ = x[Disabled-(1)]
|
||||
_ = x[AppEnabled-(0)]
|
||||
_ = x[AppDisabled-(1)]
|
||||
}
|
||||
|
||||
var _AppStatusValues = []AppStatus{Enabled, Disabled}
|
||||
var _AppStatusValues = []AppStatus{AppEnabled, AppDisabled}
|
||||
|
||||
var _AppStatusNameToValueMap = map[string]AppStatus{
|
||||
_AppStatusName[0:7]: Enabled,
|
||||
_AppStatusLowerName[0:7]: Enabled,
|
||||
_AppStatusName[7:15]: Disabled,
|
||||
_AppStatusLowerName[7:15]: Disabled,
|
||||
_AppStatusName[0:10]: AppEnabled,
|
||||
_AppStatusLowerName[0:10]: AppEnabled,
|
||||
_AppStatusName[10:21]: AppDisabled,
|
||||
_AppStatusLowerName[10:21]: AppDisabled,
|
||||
}
|
||||
|
||||
var _AppStatusNames = []string{
|
||||
_AppStatusName[0:7],
|
||||
_AppStatusName[7:15],
|
||||
_AppStatusName[0:10],
|
||||
_AppStatusName[10:21],
|
||||
}
|
||||
|
||||
// AppStatusString retrieves an enum value from the enum constants string name.
|
||||
|
|
|
@ -126,6 +126,11 @@ type UserI interface {
|
|||
//DelTransport Remove a Transport from the Group
|
||||
DelTransportRecipient(context.Context, TransportRecipient) error
|
||||
|
||||
SetFields(ctx context.Context, fields map[string]string) (err error)
|
||||
GetFields(ctx context.Context) (flds map[string]string, err error)
|
||||
GetField(ctx context.Context, key string) (value string, err error)
|
||||
SetField(ctx context.Context, key string, value string) (err error)
|
||||
|
||||
ProcessMessage(context.Context, MessageI) error
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package interfaces
|
||||
|
||||
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
@ -10,11 +8,12 @@ import (
|
|||
//CtxUserValue Context Key to get token.User value from Context
|
||||
type CtxUserValue struct{}
|
||||
|
||||
//go:generate go run github.com/dmarkham/enumer -type=AppStatus -json -text -sql
|
||||
//go:generate go run github.com/dmarkham/enumer -type=AppStatus -json -text -sql
|
||||
type AppStatus int
|
||||
|
||||
const (
|
||||
Enabled AppStatus = iota
|
||||
Disabled
|
||||
AppEnabled AppStatus = iota
|
||||
AppDisabled
|
||||
)
|
||||
|
||||
func (AppStatus) Values() []string {
|
||||
|
@ -32,8 +31,6 @@ func (c *CacheAble) SetLastUsed() {
|
|||
c.lastUsed = time.Now()
|
||||
}
|
||||
|
||||
|
||||
|
||||
type AppDetails struct {
|
||||
ID uint `doc:"App ID" gorm:"primary_key"`
|
||||
AppName string `doc:"Application Name" pattern:"^[a-z0-9]+$" gorm:"unique;uniqueIndex" validate:"required,max=255,alphanum"`
|
||||
|
@ -51,8 +48,9 @@ type UserDetails struct {
|
|||
Password string `doc:"Password" json:"-" writeOnly:"true" validate:"required"`
|
||||
}
|
||||
|
||||
//go:generate go run github.com/dmarkham/enumer -type=FilterType -json -text -sql
|
||||
//go:generate go run github.com/dmarkham/enumer -type=FilterType -json -text -sql
|
||||
type FilterType int
|
||||
|
||||
const (
|
||||
InvalidFilter FilterType = iota
|
||||
AppFilter
|
||||
|
@ -64,13 +62,12 @@ func (FilterType) Values() []string {
|
|||
return FilterTypeStrings()
|
||||
}
|
||||
|
||||
|
||||
type ctxKey struct {
|
||||
key string
|
||||
}
|
||||
|
||||
var (
|
||||
MpctxKey = ctxKey{key: "mp"}
|
||||
MpctxKey = ctxKey{key: "mp"}
|
||||
)
|
||||
|
||||
type MpService interface {
|
||||
|
@ -81,7 +78,6 @@ type MpService interface {
|
|||
GetTransportService() TransportServiceI
|
||||
}
|
||||
|
||||
|
||||
func GetUserService(ctx context.Context) UserServiceI {
|
||||
return ctx.Value(MpctxKey).(MpService).GetUserService()
|
||||
}
|
||||
|
@ -103,10 +99,10 @@ func GetTransportService(ctx context.Context) TransportServiceI {
|
|||
}
|
||||
|
||||
const (
|
||||
MD_AppName = "X-AppName"
|
||||
MD_AppName = "X-AppName"
|
||||
MD_AppDescription = "X-AppDescription"
|
||||
MD_AppURL = "X-AppURL"
|
||||
MD_AppIcon = "X-AppIcon"
|
||||
MD_UserEmail = "X-UserEmail"
|
||||
MD_UserName = "X-UserName"
|
||||
)
|
||||
MD_AppURL = "X-AppURL"
|
||||
MD_AppIcon = "X-AppIcon"
|
||||
MD_UserEmail = "X-UserEmail"
|
||||
MD_UserName = "X-UserName"
|
||||
)
|
||||
|
|
|
@ -78,20 +78,6 @@ func (mr *MockAppIMockRecorder) GetDescription() *gomock.Call {
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDescription", reflect.TypeOf((*MockAppI)(nil).GetDescription))
|
||||
}
|
||||
|
||||
// GetDetails mocks base method.
|
||||
func (m *MockAppI) GetDetails() interfaces.AppDetails {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetDetails")
|
||||
ret0, _ := ret[0].(interfaces.AppDetails)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetDetails indicates an expected call of GetDetails.
|
||||
func (mr *MockAppIMockRecorder) GetDetails() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDetails", reflect.TypeOf((*MockAppI)(nil).GetDetails))
|
||||
}
|
||||
|
||||
// GetFilters mocks base method.
|
||||
func (m *MockAppI) GetFilters(arg0 context.Context) ([]interfaces.FilterI, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
@ -233,20 +219,6 @@ func (mr *MockAppIMockRecorder) SetDescription(arg0, arg1 interface{}) *gomock.C
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDescription", reflect.TypeOf((*MockAppI)(nil).SetDescription), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetDetails mocks base method.
|
||||
func (m *MockAppI) SetDetails(arg0 context.Context, arg1 interfaces.AppDetails) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetDetails", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetDetails indicates an expected call of SetDetails.
|
||||
func (mr *MockAppIMockRecorder) SetDetails(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDetails", reflect.TypeOf((*MockAppI)(nil).SetDetails), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetIcon mocks base method.
|
||||
func (m *MockAppI) SetIcon(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/go-logr/logr"
|
||||
"github.com/go-logr/logr/testr"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/google/uuid"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -23,17 +25,17 @@ var Ctx context.Context
|
|||
var Tst *testing.T
|
||||
var Mp *mouthpiece.MouthPiece
|
||||
var App interfaces.AppI
|
||||
var GlobalLogger logr.Logger
|
||||
|
||||
var DBBeforeSuite = BeforeSuite(func() {
|
||||
interfaces.Config.ExpireFilters = 2 * time.Second
|
||||
|
||||
var logger logr.Logger
|
||||
if len(os.Getenv("MP_DEBUG_LOG")) > 0 {
|
||||
logger = testr.NewWithOptions(Tst, testr.Options{Verbosity: 10})
|
||||
GlobalLogger = testr.NewWithOptions(Tst, testr.Options{Verbosity: 10})
|
||||
} else {
|
||||
logger = logr.Discard()
|
||||
GlobalLogger = logr.Discard()
|
||||
}
|
||||
Mp = mouthpiece.NewMouthPiece(context.Background(), "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", logger)
|
||||
Mp = mouthpiece.NewMouthPiece(context.Background(), "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", GlobalLogger)
|
||||
Expect(Mp).ToNot(BeNil())
|
||||
|
||||
Ctx = Mp.SetAdminTenant(context.Background())
|
||||
|
@ -51,3 +53,35 @@ var DBBeforeSuite = BeforeSuite(func() {
|
|||
var DBAfterSuite = AfterSuite(func() {
|
||||
Mp.Close()
|
||||
})
|
||||
|
||||
func TestTransportSend(tpi interfaces.TransportInstanceImpl) {
|
||||
ctrl := gomock.NewController(GinkgoT())
|
||||
mockMessage := NewMockMessageI(ctrl)
|
||||
|
||||
mockMessage.EXPECT().String().Return("Test Message").AnyTimes()
|
||||
mockMessage.EXPECT().GetFields(gomock.Any()).Return(map[string]string{"test": "value"}, nil).AnyTimes()
|
||||
mockMessage.EXPECT().GetMetadataFields(gomock.Any()).Return(map[string]interface{}{"test": "value"}, nil).AnyTimes()
|
||||
mockMessage.EXPECT().GetID().Return(uuid.New()).AnyTimes()
|
||||
|
||||
user := NewMockUserI(ctrl)
|
||||
user.EXPECT().GetEmail().Return("test@test.com").AnyTimes()
|
||||
|
||||
tpr := NewMockTransportRecipient(ctrl)
|
||||
tpr.EXPECT().GetRecipientType(gomock.Any()).Return(interfaces.TransportRecipientTypeUser).AnyTimes()
|
||||
tpr.EXPECT().GetUser(gomock.Any()).Return(user, nil).AnyTimes()
|
||||
tpr.EXPECT().GetName().Return("test").AnyTimes()
|
||||
|
||||
err := tpi.Send(Ctx, tpr, mockMessage)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
grp := NewMockGroupI(ctrl)
|
||||
grp.EXPECT().GetName().Return("test").AnyTimes()
|
||||
|
||||
tpr2 := NewMockTransportRecipient(ctrl)
|
||||
tpr2.EXPECT().GetGroup(gomock.Any()).Return(grp, nil).AnyTimes()
|
||||
tpr2.EXPECT().GetName().Return("test").AnyTimes()
|
||||
tpr2.EXPECT().GetRecipientType(gomock.Any()).Return(interfaces.TransportRecipientTypeGroup).AnyTimes()
|
||||
|
||||
err = tpi.Send(Ctx, tpr2, mockMessage)
|
||||
Expect(err).To(BeNil())
|
||||
}
|
||||
|
|
275
pkg/mocks/group.go
Normal file
275
pkg/mocks/group.go
Normal file
|
@ -0,0 +1,275 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/Fishwaldo/mouthpiece/pkg/interfaces (interfaces: GroupI)
|
||||
|
||||
// Package mock_interfaces is a generated GoMock package.
|
||||
package mock_interfaces
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
interfaces "github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
logr "github.com/go-logr/logr"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockGroupI is a mock of GroupI interface.
|
||||
type MockGroupI struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockGroupIMockRecorder
|
||||
}
|
||||
|
||||
// MockGroupIMockRecorder is the mock recorder for MockGroupI.
|
||||
type MockGroupIMockRecorder struct {
|
||||
mock *MockGroupI
|
||||
}
|
||||
|
||||
// NewMockGroupI creates a new mock instance.
|
||||
func NewMockGroupI(ctrl *gomock.Controller) *MockGroupI {
|
||||
mock := &MockGroupI{ctrl: ctrl}
|
||||
mock.recorder = &MockGroupIMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockGroupI) EXPECT() *MockGroupIMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AddApp mocks base method.
|
||||
func (m *MockGroupI) AddApp(arg0 context.Context, arg1 interfaces.AppI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddApp", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddApp indicates an expected call of AddApp.
|
||||
func (mr *MockGroupIMockRecorder) AddApp(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddApp", reflect.TypeOf((*MockGroupI)(nil).AddApp), arg0, arg1)
|
||||
}
|
||||
|
||||
// AddTransportRecipient mocks base method.
|
||||
func (m *MockGroupI) AddTransportRecipient(arg0 context.Context, arg1 interfaces.TransportRecipient) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddTransportRecipient", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddTransportRecipient indicates an expected call of AddTransportRecipient.
|
||||
func (mr *MockGroupIMockRecorder) AddTransportRecipient(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTransportRecipient", reflect.TypeOf((*MockGroupI)(nil).AddTransportRecipient), arg0, arg1)
|
||||
}
|
||||
|
||||
// AddUser mocks base method.
|
||||
func (m *MockGroupI) AddUser(arg0 context.Context, arg1 interfaces.UserI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddUser", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddUser indicates an expected call of AddUser.
|
||||
func (mr *MockGroupIMockRecorder) AddUser(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddUser", reflect.TypeOf((*MockGroupI)(nil).AddUser), arg0, arg1)
|
||||
}
|
||||
|
||||
// DelApp mocks base method.
|
||||
func (m *MockGroupI) DelApp(arg0 context.Context, arg1 interfaces.AppI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DelApp", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DelApp indicates an expected call of DelApp.
|
||||
func (mr *MockGroupIMockRecorder) DelApp(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelApp", reflect.TypeOf((*MockGroupI)(nil).DelApp), arg0, arg1)
|
||||
}
|
||||
|
||||
// DelTransportRecipient mocks base method.
|
||||
func (m *MockGroupI) DelTransportRecipient(arg0 context.Context, arg1 interfaces.TransportRecipient) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DelTransportRecipient", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DelTransportRecipient indicates an expected call of DelTransportRecipient.
|
||||
func (mr *MockGroupIMockRecorder) DelTransportRecipient(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelTransportRecipient", reflect.TypeOf((*MockGroupI)(nil).DelTransportRecipient), arg0, arg1)
|
||||
}
|
||||
|
||||
// DelUser mocks base method.
|
||||
func (m *MockGroupI) DelUser(arg0 context.Context, arg1 interfaces.UserI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DelUser", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DelUser indicates an expected call of DelUser.
|
||||
func (mr *MockGroupIMockRecorder) DelUser(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelUser", reflect.TypeOf((*MockGroupI)(nil).DelUser), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetApps mocks base method.
|
||||
func (m *MockGroupI) GetApps(arg0 context.Context) []interfaces.AppI {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetApps", arg0)
|
||||
ret0, _ := ret[0].([]interfaces.AppI)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetApps indicates an expected call of GetApps.
|
||||
func (mr *MockGroupIMockRecorder) GetApps(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetApps", reflect.TypeOf((*MockGroupI)(nil).GetApps), arg0)
|
||||
}
|
||||
|
||||
// GetDescription mocks base method.
|
||||
func (m *MockGroupI) GetDescription() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetDescription")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetDescription indicates an expected call of GetDescription.
|
||||
func (mr *MockGroupIMockRecorder) GetDescription() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDescription", reflect.TypeOf((*MockGroupI)(nil).GetDescription))
|
||||
}
|
||||
|
||||
// GetID mocks base method.
|
||||
func (m *MockGroupI) GetID() int {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetID")
|
||||
ret0, _ := ret[0].(int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetID indicates an expected call of GetID.
|
||||
func (mr *MockGroupIMockRecorder) GetID() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetID", reflect.TypeOf((*MockGroupI)(nil).GetID))
|
||||
}
|
||||
|
||||
// GetName mocks base method.
|
||||
func (m *MockGroupI) GetName() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetName")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetName indicates an expected call of GetName.
|
||||
func (mr *MockGroupIMockRecorder) GetName() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetName", reflect.TypeOf((*MockGroupI)(nil).GetName))
|
||||
}
|
||||
|
||||
// GetTransportRecipients mocks base method.
|
||||
func (m *MockGroupI) GetTransportRecipients(arg0 context.Context) []interfaces.TransportRecipient {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetTransportRecipients", arg0)
|
||||
ret0, _ := ret[0].([]interfaces.TransportRecipient)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetTransportRecipients indicates an expected call of GetTransportRecipients.
|
||||
func (mr *MockGroupIMockRecorder) GetTransportRecipients(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransportRecipients", reflect.TypeOf((*MockGroupI)(nil).GetTransportRecipients), arg0)
|
||||
}
|
||||
|
||||
// GetUsers mocks base method.
|
||||
func (m *MockGroupI) GetUsers(arg0 context.Context) []interfaces.UserI {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUsers", arg0)
|
||||
ret0, _ := ret[0].([]interfaces.UserI)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetUsers indicates an expected call of GetUsers.
|
||||
func (mr *MockGroupIMockRecorder) GetUsers(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsers", reflect.TypeOf((*MockGroupI)(nil).GetUsers), arg0)
|
||||
}
|
||||
|
||||
// Load mocks base method.
|
||||
func (m *MockGroupI) Load(arg0 context.Context, arg1 logr.Logger, arg2 interface{}) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Load", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Load indicates an expected call of Load.
|
||||
func (mr *MockGroupIMockRecorder) Load(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Load", reflect.TypeOf((*MockGroupI)(nil).Load), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// ProcessMessage mocks base method.
|
||||
func (m *MockGroupI) ProcessMessage(arg0 context.Context, arg1 interfaces.MessageI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ProcessMessage", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ProcessMessage indicates an expected call of ProcessMessage.
|
||||
func (mr *MockGroupIMockRecorder) ProcessMessage(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessMessage", reflect.TypeOf((*MockGroupI)(nil).ProcessMessage), arg0, arg1)
|
||||
}
|
||||
|
||||
// Save mocks base method.
|
||||
func (m *MockGroupI) Save(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Save", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Save indicates an expected call of Save.
|
||||
func (mr *MockGroupIMockRecorder) Save(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockGroupI)(nil).Save), arg0)
|
||||
}
|
||||
|
||||
// SetDescription mocks base method.
|
||||
func (m *MockGroupI) SetDescription(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetDescription", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetDescription indicates an expected call of SetDescription.
|
||||
func (mr *MockGroupIMockRecorder) SetDescription(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDescription", reflect.TypeOf((*MockGroupI)(nil).SetDescription), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetName mocks base method.
|
||||
func (m *MockGroupI) SetName(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetName", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetName indicates an expected call of SetName.
|
||||
func (mr *MockGroupIMockRecorder) SetName(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetName", reflect.TypeOf((*MockGroupI)(nil).SetName), arg0, arg1)
|
||||
}
|
|
@ -5,4 +5,10 @@ import (
|
|||
|
||||
//go:generate mockgen -destination ./message.go github.com/Fishwaldo/mouthpiece/pkg/interfaces MessageI
|
||||
|
||||
//go:generate mockgen -destination ./transportrecipient.go github.com/Fishwaldo/mouthpiece/pkg/interfaces TransportRecipient
|
||||
|
||||
//go:generate mockgen -destination ./app.go github.com/Fishwaldo/mouthpiece/pkg/interfaces AppI
|
||||
|
||||
//go:generate mockgen -destination ./user.go github.com/Fishwaldo/mouthpiece/pkg/interfaces UserI
|
||||
|
||||
//go:generate mockgen -destination ./group.go github.com/Fishwaldo/mouthpiece/pkg/interfaces GroupI
|
||||
|
|
236
pkg/mocks/transportrecipient.go
Normal file
236
pkg/mocks/transportrecipient.go
Normal file
|
@ -0,0 +1,236 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/Fishwaldo/mouthpiece/pkg/interfaces (interfaces: TransportRecipient)
|
||||
|
||||
// Package mock_interfaces is a generated GoMock package.
|
||||
package mock_interfaces
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
interfaces "github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
logr "github.com/go-logr/logr"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockTransportRecipient is a mock of TransportRecipient interface.
|
||||
type MockTransportRecipient struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockTransportRecipientMockRecorder
|
||||
}
|
||||
|
||||
// MockTransportRecipientMockRecorder is the mock recorder for MockTransportRecipient.
|
||||
type MockTransportRecipientMockRecorder struct {
|
||||
mock *MockTransportRecipient
|
||||
}
|
||||
|
||||
// NewMockTransportRecipient creates a new mock instance.
|
||||
func NewMockTransportRecipient(ctrl *gomock.Controller) *MockTransportRecipient {
|
||||
mock := &MockTransportRecipient{ctrl: ctrl}
|
||||
mock.recorder = &MockTransportRecipientMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockTransportRecipient) EXPECT() *MockTransportRecipientMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// GetConfig mocks base method.
|
||||
func (m *MockTransportRecipient) GetConfig() (interfaces.MarshableConfigI, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetConfig")
|
||||
ret0, _ := ret[0].(interfaces.MarshableConfigI)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetConfig indicates an expected call of GetConfig.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetConfig() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetConfig", reflect.TypeOf((*MockTransportRecipient)(nil).GetConfig))
|
||||
}
|
||||
|
||||
// GetDescription mocks base method.
|
||||
func (m *MockTransportRecipient) GetDescription() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetDescription")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetDescription indicates an expected call of GetDescription.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetDescription() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDescription", reflect.TypeOf((*MockTransportRecipient)(nil).GetDescription))
|
||||
}
|
||||
|
||||
// GetGroup mocks base method.
|
||||
func (m *MockTransportRecipient) GetGroup(arg0 context.Context) (interfaces.GroupI, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetGroup", arg0)
|
||||
ret0, _ := ret[0].(interfaces.GroupI)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetGroup indicates an expected call of GetGroup.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetGroup(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroup", reflect.TypeOf((*MockTransportRecipient)(nil).GetGroup), arg0)
|
||||
}
|
||||
|
||||
// GetID mocks base method.
|
||||
func (m *MockTransportRecipient) GetID() int {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetID")
|
||||
ret0, _ := ret[0].(int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetID indicates an expected call of GetID.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetID() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetID", reflect.TypeOf((*MockTransportRecipient)(nil).GetID))
|
||||
}
|
||||
|
||||
// GetName mocks base method.
|
||||
func (m *MockTransportRecipient) GetName() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetName")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetName indicates an expected call of GetName.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetName() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetName", reflect.TypeOf((*MockTransportRecipient)(nil).GetName))
|
||||
}
|
||||
|
||||
// GetRecipientType mocks base method.
|
||||
func (m *MockTransportRecipient) GetRecipientType(arg0 context.Context) interfaces.TransportRecipientType {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetRecipientType", arg0)
|
||||
ret0, _ := ret[0].(interfaces.TransportRecipientType)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetRecipientType indicates an expected call of GetRecipientType.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetRecipientType(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecipientType", reflect.TypeOf((*MockTransportRecipient)(nil).GetRecipientType), arg0)
|
||||
}
|
||||
|
||||
// GetUser mocks base method.
|
||||
func (m *MockTransportRecipient) GetUser(arg0 context.Context) (interfaces.UserI, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetUser", arg0)
|
||||
ret0, _ := ret[0].(interfaces.UserI)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetUser indicates an expected call of GetUser.
|
||||
func (mr *MockTransportRecipientMockRecorder) GetUser(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUser", reflect.TypeOf((*MockTransportRecipient)(nil).GetUser), arg0)
|
||||
}
|
||||
|
||||
// Load mocks base method.
|
||||
func (m *MockTransportRecipient) Load(arg0 context.Context, arg1 logr.Logger, arg2 interface{}) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Load", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Load indicates an expected call of Load.
|
||||
func (mr *MockTransportRecipientMockRecorder) Load(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Load", reflect.TypeOf((*MockTransportRecipient)(nil).Load), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// ProcessMessage mocks base method.
|
||||
func (m *MockTransportRecipient) ProcessMessage(arg0 context.Context, arg1 interfaces.MessageI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ProcessMessage", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ProcessMessage indicates an expected call of ProcessMessage.
|
||||
func (mr *MockTransportRecipientMockRecorder) ProcessMessage(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessMessage", reflect.TypeOf((*MockTransportRecipient)(nil).ProcessMessage), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetConfig mocks base method.
|
||||
func (m *MockTransportRecipient) SetConfig(arg0 context.Context, arg1 interfaces.MarshableConfigI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetConfig", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetConfig indicates an expected call of SetConfig.
|
||||
func (mr *MockTransportRecipientMockRecorder) SetConfig(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetConfig", reflect.TypeOf((*MockTransportRecipient)(nil).SetConfig), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetDescription mocks base method.
|
||||
func (m *MockTransportRecipient) SetDescription(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetDescription", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetDescription indicates an expected call of SetDescription.
|
||||
func (mr *MockTransportRecipientMockRecorder) SetDescription(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDescription", reflect.TypeOf((*MockTransportRecipient)(nil).SetDescription), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetGroup mocks base method.
|
||||
func (m *MockTransportRecipient) SetGroup(arg0 context.Context, arg1 interfaces.GroupI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetGroup", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetGroup indicates an expected call of SetGroup.
|
||||
func (mr *MockTransportRecipientMockRecorder) SetGroup(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetGroup", reflect.TypeOf((*MockTransportRecipient)(nil).SetGroup), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetName mocks base method.
|
||||
func (m *MockTransportRecipient) SetName(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetName", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetName indicates an expected call of SetName.
|
||||
func (mr *MockTransportRecipientMockRecorder) SetName(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetName", reflect.TypeOf((*MockTransportRecipient)(nil).SetName), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetUser mocks base method.
|
||||
func (m *MockTransportRecipient) SetUser(arg0 context.Context, arg1 interfaces.UserI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetUser", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetUser indicates an expected call of SetUser.
|
||||
func (mr *MockTransportRecipientMockRecorder) SetUser(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetUser", reflect.TypeOf((*MockTransportRecipient)(nil).SetUser), arg0, arg1)
|
||||
}
|
320
pkg/mocks/user.go
Normal file
320
pkg/mocks/user.go
Normal file
|
@ -0,0 +1,320 @@
|
|||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/Fishwaldo/mouthpiece/pkg/interfaces (interfaces: UserI)
|
||||
|
||||
// Package mock_interfaces is a generated GoMock package.
|
||||
package mock_interfaces
|
||||
|
||||
import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
interfaces "github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
logr "github.com/go-logr/logr"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockUserI is a mock of UserI interface.
|
||||
type MockUserI struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockUserIMockRecorder
|
||||
}
|
||||
|
||||
// MockUserIMockRecorder is the mock recorder for MockUserI.
|
||||
type MockUserIMockRecorder struct {
|
||||
mock *MockUserI
|
||||
}
|
||||
|
||||
// NewMockUserI creates a new mock instance.
|
||||
func NewMockUserI(ctrl *gomock.Controller) *MockUserI {
|
||||
mock := &MockUserI{ctrl: ctrl}
|
||||
mock.recorder = &MockUserIMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockUserI) EXPECT() *MockUserIMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AddFilter mocks base method.
|
||||
func (m *MockUserI) AddFilter(arg0 context.Context, arg1 interfaces.FilterI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddFilter", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddFilter indicates an expected call of AddFilter.
|
||||
func (mr *MockUserIMockRecorder) AddFilter(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddFilter", reflect.TypeOf((*MockUserI)(nil).AddFilter), arg0, arg1)
|
||||
}
|
||||
|
||||
// AddTransportRecipient mocks base method.
|
||||
func (m *MockUserI) AddTransportRecipient(arg0 context.Context, arg1 interfaces.TransportRecipient) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddTransportRecipient", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddTransportRecipient indicates an expected call of AddTransportRecipient.
|
||||
func (mr *MockUserIMockRecorder) AddTransportRecipient(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddTransportRecipient", reflect.TypeOf((*MockUserI)(nil).AddTransportRecipient), arg0, arg1)
|
||||
}
|
||||
|
||||
// DelFilter mocks base method.
|
||||
func (m *MockUserI) DelFilter(arg0 context.Context, arg1 interfaces.FilterI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DelFilter", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DelFilter indicates an expected call of DelFilter.
|
||||
func (mr *MockUserIMockRecorder) DelFilter(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelFilter", reflect.TypeOf((*MockUserI)(nil).DelFilter), arg0, arg1)
|
||||
}
|
||||
|
||||
// DelTransportRecipient mocks base method.
|
||||
func (m *MockUserI) DelTransportRecipient(arg0 context.Context, arg1 interfaces.TransportRecipient) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "DelTransportRecipient", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// DelTransportRecipient indicates an expected call of DelTransportRecipient.
|
||||
func (mr *MockUserIMockRecorder) DelTransportRecipient(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DelTransportRecipient", reflect.TypeOf((*MockUserI)(nil).DelTransportRecipient), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetDescription mocks base method.
|
||||
func (m *MockUserI) GetDescription() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetDescription")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetDescription indicates an expected call of GetDescription.
|
||||
func (mr *MockUserIMockRecorder) GetDescription() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetDescription", reflect.TypeOf((*MockUserI)(nil).GetDescription))
|
||||
}
|
||||
|
||||
// GetEmail mocks base method.
|
||||
func (m *MockUserI) GetEmail() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetEmail")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetEmail indicates an expected call of GetEmail.
|
||||
func (mr *MockUserIMockRecorder) GetEmail() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetEmail", reflect.TypeOf((*MockUserI)(nil).GetEmail))
|
||||
}
|
||||
|
||||
// GetField mocks base method.
|
||||
func (m *MockUserI) GetField(arg0 context.Context, arg1 string) (string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetField", arg0, arg1)
|
||||
ret0, _ := ret[0].(string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetField indicates an expected call of GetField.
|
||||
func (mr *MockUserIMockRecorder) GetField(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetField", reflect.TypeOf((*MockUserI)(nil).GetField), arg0, arg1)
|
||||
}
|
||||
|
||||
// GetFields mocks base method.
|
||||
func (m *MockUserI) GetFields(arg0 context.Context) (map[string]string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFields", arg0)
|
||||
ret0, _ := ret[0].(map[string]string)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFields indicates an expected call of GetFields.
|
||||
func (mr *MockUserIMockRecorder) GetFields(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFields", reflect.TypeOf((*MockUserI)(nil).GetFields), arg0)
|
||||
}
|
||||
|
||||
// GetFilters mocks base method.
|
||||
func (m *MockUserI) GetFilters(arg0 context.Context) ([]interfaces.FilterI, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetFilters", arg0)
|
||||
ret0, _ := ret[0].([]interfaces.FilterI)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// GetFilters indicates an expected call of GetFilters.
|
||||
func (mr *MockUserIMockRecorder) GetFilters(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFilters", reflect.TypeOf((*MockUserI)(nil).GetFilters), arg0)
|
||||
}
|
||||
|
||||
// GetID mocks base method.
|
||||
func (m *MockUserI) GetID() int {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetID")
|
||||
ret0, _ := ret[0].(int)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetID indicates an expected call of GetID.
|
||||
func (mr *MockUserIMockRecorder) GetID() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetID", reflect.TypeOf((*MockUserI)(nil).GetID))
|
||||
}
|
||||
|
||||
// GetName mocks base method.
|
||||
func (m *MockUserI) GetName() string {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetName")
|
||||
ret0, _ := ret[0].(string)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetName indicates an expected call of GetName.
|
||||
func (mr *MockUserIMockRecorder) GetName() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetName", reflect.TypeOf((*MockUserI)(nil).GetName))
|
||||
}
|
||||
|
||||
// GetTransportRecipients mocks base method.
|
||||
func (m *MockUserI) GetTransportRecipients(arg0 context.Context) []interfaces.TransportRecipient {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "GetTransportRecipients", arg0)
|
||||
ret0, _ := ret[0].([]interfaces.TransportRecipient)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// GetTransportRecipients indicates an expected call of GetTransportRecipients.
|
||||
func (mr *MockUserIMockRecorder) GetTransportRecipients(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransportRecipients", reflect.TypeOf((*MockUserI)(nil).GetTransportRecipients), arg0)
|
||||
}
|
||||
|
||||
// Load mocks base method.
|
||||
func (m *MockUserI) Load(arg0 context.Context, arg1 logr.Logger, arg2 interface{}) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Load", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Load indicates an expected call of Load.
|
||||
func (mr *MockUserIMockRecorder) Load(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Load", reflect.TypeOf((*MockUserI)(nil).Load), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// ProcessMessage mocks base method.
|
||||
func (m *MockUserI) ProcessMessage(arg0 context.Context, arg1 interfaces.MessageI) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ProcessMessage", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// ProcessMessage indicates an expected call of ProcessMessage.
|
||||
func (mr *MockUserIMockRecorder) ProcessMessage(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProcessMessage", reflect.TypeOf((*MockUserI)(nil).ProcessMessage), arg0, arg1)
|
||||
}
|
||||
|
||||
// Save mocks base method.
|
||||
func (m *MockUserI) Save(arg0 context.Context) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Save", arg0)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// Save indicates an expected call of Save.
|
||||
func (mr *MockUserIMockRecorder) Save(arg0 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockUserI)(nil).Save), arg0)
|
||||
}
|
||||
|
||||
// SetDescription mocks base method.
|
||||
func (m *MockUserI) SetDescription(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetDescription", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetDescription indicates an expected call of SetDescription.
|
||||
func (mr *MockUserIMockRecorder) SetDescription(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetDescription", reflect.TypeOf((*MockUserI)(nil).SetDescription), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetEmail mocks base method.
|
||||
func (m *MockUserI) SetEmail(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetEmail", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetEmail indicates an expected call of SetEmail.
|
||||
func (mr *MockUserIMockRecorder) SetEmail(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetEmail", reflect.TypeOf((*MockUserI)(nil).SetEmail), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetField mocks base method.
|
||||
func (m *MockUserI) SetField(arg0 context.Context, arg1, arg2 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetField", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetField indicates an expected call of SetField.
|
||||
func (mr *MockUserIMockRecorder) SetField(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetField", reflect.TypeOf((*MockUserI)(nil).SetField), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// SetFields mocks base method.
|
||||
func (m *MockUserI) SetFields(arg0 context.Context, arg1 map[string]string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetFields", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetFields indicates an expected call of SetFields.
|
||||
func (mr *MockUserIMockRecorder) SetFields(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetFields", reflect.TypeOf((*MockUserI)(nil).SetFields), arg0, arg1)
|
||||
}
|
||||
|
||||
// SetName mocks base method.
|
||||
func (m *MockUserI) SetName(arg0 context.Context, arg1 string) error {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "SetName", arg0, arg1)
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// SetName indicates an expected call of SetName.
|
||||
func (mr *MockUserIMockRecorder) SetName(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetName", reflect.TypeOf((*MockUserI)(nil).SetName), arg0, arg1)
|
||||
}
|
7
pkg/tools.go
Normal file
7
pkg/tools.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
//go:build tools
|
||||
|
||||
package mouthpiece
|
||||
|
||||
import (
|
||||
_ "github.com/dmarkham/enumer"
|
||||
)
|
|
@ -5,13 +5,11 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
// "github.com/Fishwaldo/mouthpiece/pkg/db"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/log"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mperror"
|
||||
|
||||
// "github.com/Fishwaldo/mouthpiece/pkg/msg"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
|
@ -96,7 +94,7 @@ func (t *ConsoleTransportInstance) Init(context.Context) error {
|
|||
|
||||
func (t *ConsoleTransportInstance) SetConfig(ctx context.Context, config interfaces.MarshableConfigI) error {
|
||||
cfg, ok := config.(*ConsoleConfig)
|
||||
if ok == false {
|
||||
if !ok {
|
||||
t.log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", config))
|
||||
return mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
|
@ -119,7 +117,7 @@ func (tpi *ConsoleTransportInstance) Stop(context.Context) error {
|
|||
}
|
||||
|
||||
func (tpi *ConsoleTransportInstance) ValidateTransportRecipientConfig(ctx context.Context, config interfaces.MarshableConfigI) error {
|
||||
if _, ok := config.(*ConsoleRecipientConfig); ok == false {
|
||||
if _, ok := config.(*ConsoleRecipientConfig); !ok {
|
||||
tpi.log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", config))
|
||||
return mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
|
|
77
pkg/transport/console/console_suite_test.go
Normal file
77
pkg/transport/console/console_suite_test.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
package console_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport/console"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestConsole(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Console Suite")
|
||||
}
|
||||
|
||||
var _ = mptest.DBBeforeSuite
|
||||
var _ = mptest.DBBeforeSuite
|
||||
|
||||
var globalTPP interfaces.TransportProvider
|
||||
var globalCfg interfaces.MarshableConfigI
|
||||
var globalTPI interfaces.TransportInstanceImpl
|
||||
var globalRcpCfg interfaces.MarshableConfigI
|
||||
|
||||
var _ = Describe("Console", func() {
|
||||
Context("Provider", func() {
|
||||
It("SHould Register with the Provider", func() {
|
||||
var err error
|
||||
globalTPP, err = transport.GetTransportProvider(mptest.Ctx, "console")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalTPP).ToNot(BeNil())
|
||||
Expect(globalTPP.GetName()).To(Equal("console"))
|
||||
})
|
||||
It("Should Create a New console Config Instance", func() {
|
||||
var err error
|
||||
globalCfg, err = globalTPP.LoadConfigFromJSON(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalCfg).ToNot(BeNil())
|
||||
Expect(globalCfg).To(BeAssignableToTypeOf(&console.ConsoleConfig{}))
|
||||
})
|
||||
It("Should Create a New Console Instance Implementation", func() {
|
||||
var err error
|
||||
globalTPI, err = globalTPP.CreateInstance(mptest.Ctx, mptest.GlobalLogger, "consoleinstance", globalCfg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalTPI).ToNot(BeNil())
|
||||
Expect(globalTPI).To(BeAssignableToTypeOf(&console.ConsoleTransportInstance{}))
|
||||
})
|
||||
It("Should Return a Valid Config", func() {
|
||||
cfg := globalTPI.GetConfig(mptest.Ctx)
|
||||
Expect(cfg).ToNot(BeNil())
|
||||
Expect(cfg).To(BeAssignableToTypeOf(&console.ConsoleConfig{}))
|
||||
})
|
||||
It("Load a Recipient Config", func() {
|
||||
var err error
|
||||
globalRcpCfg, err = globalTPI.LoadTransportReciepientConfig(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalRcpCfg).ToNot(BeNil())
|
||||
Expect(globalRcpCfg).To(BeAssignableToTypeOf(&console.ConsoleRecipientConfig{}))
|
||||
})
|
||||
It("Should Validate a Config", func() {
|
||||
err := globalTPI.ValidateTransportRecipientConfig(mptest.Ctx, globalRcpCfg)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should Process a Message", func() {
|
||||
mptest.TestTransportSend(globalTPI)
|
||||
})
|
||||
It("Should Stop", func() {
|
||||
err := globalTPI.Stop(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
77
pkg/transport/noop/noop_suite_test.go
Normal file
77
pkg/transport/noop/noop_suite_test.go
Normal file
|
@ -0,0 +1,77 @@
|
|||
package noop_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport/noop"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestNoop(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Noop Suite")
|
||||
}
|
||||
|
||||
var _ = mptest.DBBeforeSuite
|
||||
var _ = mptest.DBBeforeSuite
|
||||
|
||||
var globalTPP interfaces.TransportProvider
|
||||
var globalCfg interfaces.MarshableConfigI
|
||||
var globalTPI interfaces.TransportInstanceImpl
|
||||
var globalRcpCfg interfaces.MarshableConfigI
|
||||
|
||||
var _ = Describe("NoOp", func() {
|
||||
Context("Provider", func() {
|
||||
It("SHould Register with the Provider", func() {
|
||||
var err error
|
||||
globalTPP, err = transport.GetTransportProvider(mptest.Ctx, "noop")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalTPP).ToNot(BeNil())
|
||||
Expect(globalTPP.GetName()).To(Equal("noop"))
|
||||
})
|
||||
It("Should Create a New noop Config Instance", func() {
|
||||
var err error
|
||||
globalCfg, err = globalTPP.LoadConfigFromJSON(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalCfg).ToNot(BeNil())
|
||||
Expect(globalCfg).To(BeAssignableToTypeOf(&noop.NoOpConfig{}))
|
||||
})
|
||||
It("Should Create a New Console Instance Implementation", func() {
|
||||
var err error
|
||||
globalTPI, err = globalTPP.CreateInstance(mptest.Ctx, mptest.GlobalLogger, "consoleinstance", globalCfg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalTPI).ToNot(BeNil())
|
||||
Expect(globalTPI).To(BeAssignableToTypeOf(&noop.NoOpTransportInstance{}))
|
||||
})
|
||||
It("Should Return a Valid Config", func() {
|
||||
cfg := globalTPI.GetConfig(mptest.Ctx)
|
||||
Expect(cfg).ToNot(BeNil())
|
||||
Expect(cfg).To(BeAssignableToTypeOf(&noop.NoOpConfig{}))
|
||||
})
|
||||
It("Load a Recipient Config", func() {
|
||||
var err error
|
||||
globalRcpCfg, err = globalTPI.LoadTransportReciepientConfig(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalRcpCfg).ToNot(BeNil())
|
||||
Expect(globalRcpCfg).To(BeAssignableToTypeOf(&noop.NoOpRecipientConfig{}))
|
||||
})
|
||||
It("Should Validate a Config", func() {
|
||||
err := globalTPI.ValidateTransportRecipientConfig(mptest.Ctx, globalRcpCfg)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should Process a Message", func() {
|
||||
mptest.TestTransportSend(globalTPI)
|
||||
})
|
||||
It("Should Stop", func() {
|
||||
err := globalTPI.Stop(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
229
pkg/transport/telegram/telegram.go
Normal file
229
pkg/transport/telegram/telegram.go
Normal file
|
@ -0,0 +1,229 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/log"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mperror"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/mymmrac/telego"
|
||||
"github.com/mymmrac/telego/telegohandler"
|
||||
"github.com/mymmrac/telego/telegoutil"
|
||||
)
|
||||
|
||||
type TelegramTransportProvider struct {
|
||||
|
||||
}
|
||||
|
||||
|
||||
type TelegramTransportInstance struct {
|
||||
cfg *TelegramConfig
|
||||
log logr.Logger
|
||||
bot *telego.Bot
|
||||
updates <-chan telego.Update
|
||||
handler *telegohandler.BotHandler
|
||||
}
|
||||
|
||||
type TelegramConfig struct {
|
||||
TelegramToken string
|
||||
}
|
||||
|
||||
func (c *TelegramConfig) AsJSON() (string, error) {
|
||||
b, err := json.Marshal(c)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
func (c *TelegramConfig) FromJSON(data string) error {
|
||||
return json.Unmarshal([]byte(data), c)
|
||||
}
|
||||
|
||||
type TelegramRecipientConfig struct {
|
||||
ChatID int64
|
||||
}
|
||||
|
||||
func (c *TelegramRecipientConfig) AsJSON() (string, error) {
|
||||
b, err := json.Marshal(c)
|
||||
return string(b), err
|
||||
}
|
||||
|
||||
func (c *TelegramRecipientConfig) FromJSON(data string) error {
|
||||
return json.Unmarshal([]byte(data), c)
|
||||
}
|
||||
|
||||
|
||||
func init() {
|
||||
tp := NewTelegramTransportProvider()
|
||||
transport.RegisterTransportProvider(tp)
|
||||
|
||||
}
|
||||
|
||||
|
||||
func NewTelegramTransportProvider() interfaces.TransportProvider {
|
||||
return &TelegramTransportProvider{}
|
||||
}
|
||||
|
||||
func (t *TelegramTransportProvider) GetName() string {
|
||||
return "telegram"
|
||||
}
|
||||
|
||||
func (t *TelegramTransportProvider) CreateInstance(ctx context.Context, logger logr.Logger, name string, config interfaces.MarshableConfigI) (interfaces.TransportInstanceImpl, error) {
|
||||
log.Log.Info("Creating Telegram Transport Instance", "name", t.GetName())
|
||||
tticonfig, ok := config.(*TelegramConfig)
|
||||
if !ok {
|
||||
log.Log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", config))
|
||||
return nil, mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
|
||||
tpi := &TelegramTransportInstance{
|
||||
cfg: tticonfig,
|
||||
log: logger.WithName("TelegramTransportInstance").WithValues("name", name),
|
||||
}
|
||||
tpi.log.Info("Creating Telegram Transport Instance")
|
||||
return tpi, nil
|
||||
}
|
||||
|
||||
func (t *TelegramTransportProvider) LoadConfigFromJSON(ctx context.Context, data string) (interfaces.MarshableConfigI, error) {
|
||||
var cfg TelegramConfig
|
||||
err := cfg.FromJSON(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
|
||||
func (t *TelegramTransportInstance) Init(context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TelegramTransportInstance) SetConfig(ctx context.Context, config interfaces.MarshableConfigI) error {
|
||||
cfg, ok := config.(*TelegramConfig)
|
||||
if !ok {
|
||||
t.log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", config))
|
||||
return mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
t.cfg = cfg
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TelegramTransportInstance) GetConfig(ctx context.Context) interfaces.MarshableConfigI {
|
||||
return t.cfg
|
||||
}
|
||||
|
||||
func (tpi *TelegramTransportInstance) Start(context.Context) error {
|
||||
tpi.log.Info("Starting Telegram Transport Instance")
|
||||
|
||||
tlogger := &telegramLogger {
|
||||
log: tpi.log,
|
||||
token: tpi.cfg.TelegramToken,
|
||||
}
|
||||
|
||||
|
||||
var err error
|
||||
tpi.bot, err = telego.NewBot(tpi.cfg.TelegramToken, telego.WithLogger(tlogger), telego.WithHealthCheck())
|
||||
if err != nil {
|
||||
log.Log.Error(err, "Telegram Transport Failed to Start")
|
||||
return err
|
||||
}
|
||||
|
||||
// Get updates channel
|
||||
tpi.updates, err = tpi.bot.UpdatesViaLongPulling(nil)
|
||||
if err != nil {
|
||||
log.Log.Error(err, "Telegram Transport Failed to St Updates via Long Pull")
|
||||
return err
|
||||
}
|
||||
|
||||
// Create bot handler and specify from where to get updates
|
||||
tpi.handler, err = telegohandler.NewBotHandler(tpi.bot, tpi.updates)
|
||||
if err != nil {
|
||||
log.Log.Error(err, "Telegram Transport Failed to Create Bot Handler")
|
||||
return err
|
||||
}
|
||||
// Register new handler with match on command `/start`
|
||||
tpi.handler.Handle(func(bot *telego.Bot, update telego.Update) {
|
||||
// Send message
|
||||
_, _ = bot.SendMessage(telegoutil.Message(
|
||||
telegoutil.ID(update.Message.Chat.ID),
|
||||
fmt.Sprintf("Hello %s!", update.Message.From.FirstName),
|
||||
))
|
||||
}, telegohandler.CommandEqual("start"))
|
||||
|
||||
// Register new handler with match on any command
|
||||
// Handlers will match only once and in order of registration, so this handler will be called on any command
|
||||
// except `/start` command
|
||||
tpi.handler.Handle(func(bot *telego.Bot, update telego.Update) {
|
||||
// Send message
|
||||
_, _ = bot.SendMessage(telegoutil.Message(
|
||||
telegoutil.ID(update.Message.Chat.ID),
|
||||
"Unknown command, use /start",
|
||||
))
|
||||
}, telegohandler.AnyCommand())
|
||||
|
||||
// Start handling updates
|
||||
go tpi.handler.Start()
|
||||
|
||||
log.Log.Info("Telegram Transport Started")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tpi *TelegramTransportInstance) Stop(context.Context) error {
|
||||
tpi.log.Info("Stopping Transport Instance")
|
||||
tpi.handler.Stop()
|
||||
tpi.bot.StopLongPulling()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tpi *TelegramTransportInstance) ValidateTransportRecipientConfig(ctx context.Context, config interfaces.MarshableConfigI) error {
|
||||
if _, ok := config.(*TelegramRecipientConfig); !ok {
|
||||
tpi.log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", config))
|
||||
return mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tpi *TelegramTransportInstance) LoadTransportReciepientConfig(ctx context.Context, config string) (interfaces.MarshableConfigI, error) {
|
||||
cfg := &TelegramRecipientConfig{}
|
||||
if err := cfg.FromJSON(config); err != nil {
|
||||
tpi.log.Error(err, "Error Unmarshalling Config")
|
||||
return nil, err
|
||||
}
|
||||
if err := tpi.ValidateTransportRecipientConfig(ctx, cfg); err != nil {
|
||||
tpi.log.Error(err, "Error Validating Config")
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (tpi *TelegramTransportInstance) Send(ctx context.Context, tpr interfaces.TransportRecipient, msg interfaces.MessageI) error {
|
||||
trcfg, err := tpr.GetConfig()
|
||||
if err != nil {
|
||||
tpi.log.Error(err, "Error Getting Recipient Config")
|
||||
return err
|
||||
}
|
||||
cfg, ok := trcfg.(*TelegramRecipientConfig)
|
||||
if !ok {
|
||||
tpi.log.Error(mperror.ErrTransportConfigInvalid, "Invalid Config", "Type", fmt.Sprintf("%T", trcfg))
|
||||
return mperror.ErrTransportConfigInvalid
|
||||
}
|
||||
tmsg, err := tpi.bot.SendMessage(
|
||||
telegoutil.Message(
|
||||
telegoutil.ID(cfg.ChatID),
|
||||
msg.GetMessage(),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
tpi.log.Error(err, "Error Sending Message")
|
||||
return err
|
||||
}
|
||||
tpi.log.Info("Message Sent", "Message", tmsg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/log"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/message"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/mymmrac/telego"
|
||||
"github.com/mymmrac/telego/telegohandler"
|
||||
"github.com/mymmrac/telego/telegoutil"
|
||||
)
|
||||
|
||||
type TelegramTransport struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
viper.SetDefault("transport.telegram.enabled", false)
|
||||
tp := NewTGTransport()
|
||||
transport.RegisterTransport(tp)
|
||||
}
|
||||
|
||||
func NewTGTransport() transport.ITransport {
|
||||
return &TelegramTransport{}
|
||||
}
|
||||
|
||||
func (t TelegramTransport) GetName() string {
|
||||
return "telegram"
|
||||
}
|
||||
|
||||
func (t TelegramTransport) Start() {
|
||||
bot, err := telego.NewBot(viper.GetString("transport.telegram.token"), telego.WithDefaultLogger(false, true))
|
||||
if err != nil {
|
||||
log.Log.Error(err, "Telegram Transport Failed to Start")
|
||||
}
|
||||
|
||||
// Get updates channel
|
||||
updates, _ := bot.UpdatesViaLongPulling(nil)
|
||||
//defer bot.StopLongPulling()
|
||||
|
||||
// Create bot handler and specify from where to get updates
|
||||
bh, _ := telegohandler.NewBotHandler(bot, updates)
|
||||
|
||||
// Register new handler with match on command `/start`
|
||||
bh.Handle(func(bot *telego.Bot, update telego.Update) {
|
||||
// Send message
|
||||
_, _ = bot.SendMessage(telegoutil.Message(
|
||||
telegoutil.ID(update.Message.Chat.ID),
|
||||
fmt.Sprintf("Hello %s!", update.Message.From.FirstName),
|
||||
))
|
||||
}, telegohandler.CommandEqual("start"))
|
||||
|
||||
// Register new handler with match on any command
|
||||
// Handlers will match only once and in order of registration, so this handler will be called on any command
|
||||
// except `/start` command
|
||||
bh.Handle(func(bot *telego.Bot, update telego.Update) {
|
||||
// Send message
|
||||
_, _ = bot.SendMessage(telegoutil.Message(
|
||||
telegoutil.ID(update.Message.Chat.ID),
|
||||
"Unknown command, use /start",
|
||||
))
|
||||
}, telegohandler.AnyCommand())
|
||||
|
||||
// Start handling updates
|
||||
go bh.Start()
|
||||
|
||||
// Stop handling updates
|
||||
//defer bh.Stop()
|
||||
log.Log.Info("Transport Started", "name", t.GetName())
|
||||
}
|
||||
|
||||
func (t TelegramTransport) NewTransportConfig(ctx context.Context) {
|
||||
// user.TransportConfigs = append(user.TransportConfigs, mouthpiece.TransportConfig{
|
||||
// Transport: t.GetName(),
|
||||
// Config: user.Username,
|
||||
// })
|
||||
}
|
||||
|
||||
func (t TelegramTransport) SendMessage(ctx context.Context, config transport.TransportConfig, msg msg.Message) (err error) {
|
||||
fmt.Println("=========================================================")
|
||||
fmt.Printf("Message: %s\n", msg.Body.Message)
|
||||
fmt.Println("=========================================================")
|
||||
transport.UpdateTransportStatus(ctx, t, msg, "sent")
|
||||
return nil
|
||||
}
|
108
pkg/transport/telegram/telegram_suite_test.go
Normal file
108
pkg/transport/telegram/telegram_suite_test.go
Normal file
|
@ -0,0 +1,108 @@
|
|||
package telegram_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"strconv"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/transport/telegram"
|
||||
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestTelegram(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Telegram Suite")
|
||||
}
|
||||
|
||||
var _ = mptest.DBBeforeSuite
|
||||
var _ = mptest.DBBeforeSuite
|
||||
|
||||
var globalTPP interfaces.TransportInstanceImpl
|
||||
var globalTCfg *telegram.TelegramConfig
|
||||
|
||||
var _ = Describe("Telegram", func() {
|
||||
Context("Provider", func() {
|
||||
It("SHould Register with the Provider", func() {
|
||||
provider, err := transport.GetTransportProvider(mptest.Ctx, "telegram")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(provider).ToNot(BeNil())
|
||||
Expect(provider.GetName()).To(Equal("telegram"))
|
||||
})
|
||||
It("Should Create a new Telegram instance", func() {
|
||||
var err error
|
||||
provider, err := transport.GetTransportProvider(mptest.Ctx, "telegram")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(provider).ToNot(BeNil())
|
||||
Expect(provider.GetName()).To(Equal("telegram"))
|
||||
var cfg interfaces.MarshableConfigI
|
||||
cfg, err = provider.LoadConfigFromJSON(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(cfg).ToNot(BeNil())
|
||||
Expect(cfg).To(BeAssignableToTypeOf(&telegram.TelegramConfig{}))
|
||||
globalTCfg = cfg.(*telegram.TelegramConfig)
|
||||
globalTPP, err = provider.CreateInstance(mptest.Ctx, mptest.GlobalLogger, "telegraminstance", cfg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalTPP).ToNot(BeNil())
|
||||
Expect(globalTPP).To(BeAssignableToTypeOf(&telegram.TelegramTransportInstance{}))
|
||||
})
|
||||
})
|
||||
Context("Run", func() {
|
||||
It("Should Run", func() {
|
||||
ttoken := os.Getenv("TELEGRAM_TOKEN")
|
||||
if len(ttoken) == 0 {
|
||||
Skip("No Telegram Chat Enviroment Vars")
|
||||
} else {
|
||||
globalTCfg.TelegramToken = ttoken
|
||||
}
|
||||
err := globalTPP.SetConfig(mptest.Ctx, globalTCfg)
|
||||
Expect(err).To(BeNil())
|
||||
err = globalTPP.Start(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
// time.Sleep(10 * time.Second)
|
||||
})
|
||||
})
|
||||
Context("Send", func() {
|
||||
It("It Should Send a Message", func() {
|
||||
tchat := os.Getenv("TELEGRAM_CHAT")
|
||||
ttoken := os.Getenv("TELEGRAM_TOKEN")
|
||||
if (len(tchat) == 0) || (len(ttoken) == 0) {
|
||||
Skip("No Telegram Chat Enviroment Vars")
|
||||
}
|
||||
ctrl := gomock.NewController(GinkgoT())
|
||||
msg := mptest.NewMockMessageI(ctrl)
|
||||
tpr := mptest.NewMockTransportRecipient(ctrl)
|
||||
id, _ := strconv.Atoi(tchat)
|
||||
trcfg := &telegram.TelegramRecipientConfig{
|
||||
ChatID: int64(id),
|
||||
}
|
||||
|
||||
tpr.EXPECT().GetConfig().Return(trcfg, nil).AnyTimes()
|
||||
|
||||
msg.EXPECT().GetMessage().Return("Hello World - This is my birthday").AnyTimes()
|
||||
|
||||
err := globalTPP.Send(mptest.Ctx, tpr, msg)
|
||||
Expect(err).To(BeNil())
|
||||
//time.Sleep(11 * time.Second)
|
||||
|
||||
})
|
||||
})
|
||||
Context("Stop", func() {
|
||||
It("Should Stop", func() {
|
||||
tchat := os.Getenv("TELEGRAM_CHAT")
|
||||
ttoken := os.Getenv("TELEGRAM_TOKEN")
|
||||
if (len(tchat) == 0) || (len(ttoken) == 0) {
|
||||
Skip("No Telegram Chat Enviroment Vars")
|
||||
}
|
||||
err := globalTPP.Stop(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
35
pkg/transport/telegram/telegramlogger.go
Normal file
35
pkg/transport/telegram/telegramlogger.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package telegram
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
|
||||
type telegramLogger struct {
|
||||
log logr.Logger
|
||||
token string
|
||||
}
|
||||
|
||||
func (l *telegramLogger) Debug(msg ...interface{}) {
|
||||
l.log.V(1).Info(l.sanitize(fmt.Sprint(msg...)))
|
||||
}
|
||||
|
||||
func (l *telegramLogger) Debugf(format string, args ...interface{}) {
|
||||
l.log.V(1).Info(l.sanitize(fmt.Sprintf(format, args...)))
|
||||
}
|
||||
|
||||
func (l *telegramLogger) Error(msg ...interface{}) {
|
||||
l.log.Error(fmt.Errorf(l.sanitize(fmt.Sprint(msg...))), "Telegram Error")
|
||||
}
|
||||
|
||||
func (l *telegramLogger) Errorf(format string, args ...interface{}) {
|
||||
l.log.Error(fmt.Errorf(l.sanitize(fmt.Sprintf(format, args...))), "Telegram Error")
|
||||
}
|
||||
|
||||
func (l *telegramLogger) sanitize(msg string) string {
|
||||
return strings.NewReplacer(l.token, "TOKEN").Replace(msg)
|
||||
|
||||
}
|
|
@ -103,7 +103,7 @@ func (u *User) GetName() string {
|
|||
|
||||
func (u *User) SetName(ctx context.Context, name string) (err error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.RUnlock()
|
||||
defer u.lock.Unlock()
|
||||
dbtmp, err := u.dbUser.Update().SetName(name).Save(ctx)
|
||||
if err != nil {
|
||||
u.log.Error(err, "Error Saving User")
|
||||
|
@ -131,7 +131,7 @@ func (u *User) SetDescription(ctx context.Context, description string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (u *User) SetMetaData(ctx context.Context, fields map[string]string) (err error) {
|
||||
func (u *User) SetFields(ctx context.Context, fields map[string]string) (err error) {
|
||||
u.lock.Lock()
|
||||
defer u.lock.Unlock()
|
||||
tx, err := db.DbClient.Tx(ctx)
|
||||
|
|
|
@ -3,11 +3,193 @@ package user_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
noopflt "github.com/Fishwaldo/mouthpiece/pkg/filter/noop"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/interfaces"
|
||||
mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/mperror"
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/msg"
|
||||
noop "github.com/Fishwaldo/mouthpiece/pkg/transport/noop"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = mptest.DBBeforeSuite
|
||||
var _ = mptest.DBAfterSuite
|
||||
|
||||
func TestUser(t *testing.T) {
|
||||
mptest.Tst = t
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "User Suite")
|
||||
}
|
||||
|
||||
var globalUser interfaces.UserI
|
||||
|
||||
var _ = Describe("User", func() {
|
||||
Context("UserService", func() {
|
||||
It("should be able to create a user", func() {
|
||||
var err error
|
||||
globalUser, err = mptest.Mp.GetUserService().Create(mptest.Ctx, "test@test.com", "test user")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalUser).ToNot(BeNil())
|
||||
Expect(globalUser.GetEmail()).To(Equal("test@test.com"))
|
||||
})
|
||||
It("Should be able to get a user by email", func() {
|
||||
user, err := mptest.Mp.GetUserService().Get(mptest.Ctx, "test@test.com")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(user).ToNot(BeNil())
|
||||
Expect(user.GetEmail()).To(Equal("test@test.com"))
|
||||
})
|
||||
It("Should be able to get a user by ID", func() {
|
||||
user, err := mptest.Mp.GetUserService().GetByID(mptest.Ctx, globalUser.GetID())
|
||||
Expect(err).To(BeNil())
|
||||
Expect(user).ToNot(BeNil())
|
||||
Expect(user.GetEmail()).To(Equal("test@test.com"))
|
||||
})
|
||||
It("Should be able to get get All Users", func() {
|
||||
users, err := mptest.Mp.GetUserService().GetAll(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(users).ToNot(BeNil())
|
||||
Expect(len(users)).To(Equal(3))
|
||||
})
|
||||
It("Should be able to Test if exists by emaail", func() {
|
||||
ok, err := mptest.Mp.GetUserService().Exists(mptest.Ctx, "test@test.com")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(ok).To(BeTrue())
|
||||
})
|
||||
It("SHould be able to test if exists by email", func() {
|
||||
ok, err := mptest.Mp.GetUserService().ExistsByID(mptest.Ctx, globalUser.GetID())
|
||||
Expect(err).To(BeNil())
|
||||
Expect(ok).To(BeTrue())
|
||||
})
|
||||
It("Should be able to test if exists by ID", func() {
|
||||
ok, err := mptest.Mp.GetUserService().ExistsByID(mptest.Ctx, globalUser.GetID())
|
||||
Expect(err).To(BeNil())
|
||||
Expect(ok).To(BeTrue())
|
||||
})
|
||||
It("Should be able to Delete a user", func() {
|
||||
user, err := mptest.Mp.GetUserService().Create(mptest.Ctx, "test@delete.me", "test user")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(user).ToNot(BeNil())
|
||||
Expect(user.GetEmail()).To(Equal("test@delete.me"))
|
||||
err = mptest.Mp.GetUserService().Delete(mptest.Ctx, user)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should not allow duplicate email addresses", func() {
|
||||
_, err := mptest.Mp.GetUserService().Create(mptest.Ctx, "test@test.com", "test user")
|
||||
Expect(err).ToNot(BeNil())
|
||||
Expect(err).To(MatchError(mperror.ErrUserExists))
|
||||
})
|
||||
})
|
||||
Context("User", func() {
|
||||
It("Should be able to set and get the email", func() {
|
||||
err := globalUser.SetEmail(mptest.Ctx, "test2@test.com")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalUser.GetEmail()).To(Equal("test2@test.com"))
|
||||
})
|
||||
It("Should be able to set and get the name", func() {
|
||||
err := globalUser.SetName(mptest.Ctx, "test user2")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalUser.GetName()).To(Equal("test user2"))
|
||||
})
|
||||
It("Should reject invalid email addresses", func() {
|
||||
err := globalUser.SetEmail(mptest.Ctx, "test2test.com")
|
||||
Expect(err).ToNot(BeNil())
|
||||
Expect(err).To(MatchError(mperror.ErrValidationError))
|
||||
})
|
||||
It("Should be able to get and set the description", func() {
|
||||
err := globalUser.SetDescription(mptest.Ctx, "test description")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(globalUser.GetDescription()).To(Equal("test description"))
|
||||
})
|
||||
It("Should be able to Set and Get a Metadata Field", func() {
|
||||
err := globalUser.SetField(mptest.Ctx, "test", "test value")
|
||||
Expect(err).To(BeNil())
|
||||
val, err := globalUser.GetField(mptest.Ctx, "test")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(val).To(Equal("test value"))
|
||||
})
|
||||
It("Should be able to set and get Metadata Fields", func() {
|
||||
flds := map[string]string{
|
||||
"test": "test value222",
|
||||
"test4": "test value2",
|
||||
}
|
||||
err := globalUser.SetFields(mptest.Ctx, flds)
|
||||
Expect(err).To(BeNil())
|
||||
vals, err := globalUser.GetFields(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
validate := map[string]string{
|
||||
"test": "test value222",
|
||||
"test4": "test value2",
|
||||
}
|
||||
Expect(vals).To(Equal(validate))
|
||||
})
|
||||
It("Should be able to add Filters", func() {
|
||||
flt, err := mptest.Mp.GetFilterService().Create(mptest.Ctx, "NoOpFilter", "newfilter", interfaces.UserFilter)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(flt).ToNot(BeNil())
|
||||
err = globalUser.AddFilter(mptest.Ctx, flt)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should be able to Get Filters", func() {
|
||||
flts, err := globalUser.GetFilters(mptest.Ctx)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(len(flts)).To(Equal(1))
|
||||
})
|
||||
It("Should be able to remove Filters", func() {
|
||||
flt, err := mptest.Mp.GetFilterService().Create(mptest.Ctx, "NoOpFilter", "delfilter", interfaces.UserFilter)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(flt).ToNot(BeNil())
|
||||
err = globalUser.AddFilter(mptest.Ctx, flt)
|
||||
Expect(err).To(BeNil())
|
||||
err = globalUser.DelFilter(mptest.Ctx, flt)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should add Transport Recipients", func() {
|
||||
trp, err := mptest.Mp.GetTransportService().GetTransportProvider(mptest.Ctx, "noop")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(trp).ToNot(BeNil())
|
||||
Expect(trp.GetName()).To(Equal("noop"))
|
||||
cfg, err := trp.LoadConfigFromJSON(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(cfg).To(BeAssignableToTypeOf(&noop.NoOpConfig{}))
|
||||
tpi, err := mptest.Mp.GetTransportService().CreateTransportInstance(mptest.Ctx, trp, "test", cfg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tpi).ToNot(BeNil())
|
||||
Expect(tpi.GetName()).To(Equal("test"))
|
||||
tprcfg, err := tpi.LoadTransportReciepientConfig(mptest.Ctx, "{}")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tprcfg).To(BeAssignableToTypeOf(&noop.NoOpRecipientConfig{}))
|
||||
tpr, err := mptest.Mp.GetTransportService().Create(mptest.Ctx, tpi, "test", tprcfg)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(tpr).ToNot(BeNil())
|
||||
err = globalUser.AddTransportRecipient(mptest.Ctx, tpr)
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("SHould be able to get Transport Recipients", func() {
|
||||
trps := globalUser.GetTransportRecipients(mptest.Ctx)
|
||||
Expect(len(trps)).To(Equal(1))
|
||||
})
|
||||
It("SHould be able to Process a Message with Filters and Transport Recipients", func() {
|
||||
app, err := mptest.Mp.GetAppService().Get(mptest.Ctx, "MouthPiece")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(app).ToNot(BeNil())
|
||||
newmsg := msg.NewMessage(mptest.Ctx, "Hello World", app)
|
||||
Expect(newmsg).ToNot(BeNil())
|
||||
err = globalUser.ProcessMessage(mptest.Ctx, newmsg)
|
||||
Expect(err).To(BeNil())
|
||||
_, ok := noopflt.Messages[newmsg.GetID()]
|
||||
Expect(ok).To(BeTrue())
|
||||
_, ok = noop.Messages[newmsg.GetID()]
|
||||
Expect(ok).To(BeTrue())
|
||||
})
|
||||
It("SHould be able to Delete a Transport Recipient", func() {
|
||||
trps := globalUser.GetTransportRecipients(mptest.Ctx)
|
||||
Expect(len(trps)).To(Equal(1))
|
||||
err := globalUser.DelTransportRecipient(mptest.Ctx, trps[0])
|
||||
Expect(err).To(BeNil())
|
||||
trps = globalUser.GetTransportRecipients(mptest.Ctx)
|
||||
Expect(len(trps)).To(Equal(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -32,7 +32,7 @@ func (us *UserService) Start(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func (us *UserService) Create(ctx context.Context, email string, name string) (interfaces.UserI, error) {
|
||||
if ok, err := us.Exists(ctx, name); err != nil {
|
||||
if ok, err := us.Exists(ctx, email); err != nil {
|
||||
return nil, mperror.FilterErrors(err)
|
||||
} else if ok {
|
||||
return nil, mperror.ErrUserExists
|
||||
|
@ -47,7 +47,7 @@ func (us *UserService) Create(ctx context.Context, email string, name string) (i
|
|||
}
|
||||
|
||||
func (us *UserService) Delete(ctx context.Context, user interfaces.UserI) error {
|
||||
if ok, err := us.Exists(ctx, user.GetName()); err != nil {
|
||||
if ok, err := us.ExistsByID(ctx, user.GetID()); err != nil {
|
||||
return mperror.FilterErrors(err)
|
||||
} else if !ok {
|
||||
return mperror.ErrUserNotFound
|
||||
|
@ -113,9 +113,9 @@ func (us *UserService) Load(ctx context.Context, dbuser any) (interfaces.UserI,
|
|||
}
|
||||
|
||||
|
||||
func (us *UserService) Exists(ctx context.Context, name string) (bool, error) {
|
||||
if ok, err := db.DbClient.DbUser.Query().Where(dbuser.Name(name)).Exist(ctx); err != nil {
|
||||
us.log.Error(err, "Error checking if user exists", "name", name)
|
||||
func (us *UserService) Exists(ctx context.Context, email string) (bool, error) {
|
||||
if ok, err := db.DbClient.DbUser.Query().Where(dbuser.Email(email)).Exist(ctx); err != nil {
|
||||
us.log.Error(err, "Error checking if user exists", "email", email)
|
||||
return false, mperror.FilterErrors(err)
|
||||
} else {
|
||||
return ok, nil
|
||||
|
|
40
pkg/validate/validate_suite_test.go
Normal file
40
pkg/validate/validate_suite_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package validate_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/Fishwaldo/mouthpiece/pkg/validate"
|
||||
|
||||
//mptest "github.com/Fishwaldo/mouthpiece/pkg/mocks"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Validate Suite")
|
||||
}
|
||||
|
||||
var _ = Describe("Validate", func() {
|
||||
Context("Validate", func() {
|
||||
It("Should Return the Validate Struct", func() {
|
||||
v := validate.Get()
|
||||
Expect(v).ToNot(BeNil())
|
||||
})
|
||||
})
|
||||
Context("Ent Validation Functions", func() {
|
||||
It("Should Return a String Validator", func() {
|
||||
v := validate.EntStringValidator("required")
|
||||
Expect(v).ToNot(BeNil())
|
||||
err := v("test")
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
It("Should return a error for a invalid validation", func() {
|
||||
v := validate.EntStringValidator("email")
|
||||
Expect(v).ToNot(BeNil())
|
||||
err := v("test")
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Add table
Reference in a new issue