-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test functions and instructions to verify installation
**What** - Add test publisher and receiver functions and instructions for how to use them to test the installations of the `nats-connector`. This should make the installation easier for users. Resolves #4 Signed-off-by: Lucas Roesler <[email protected]>
- Loading branch information
1 parent
779e180
commit fb1e5da
Showing
93 changed files
with
14,480 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module publish-message | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/nats-io/nats-server/v2 v2.1.2 // indirect | ||
github.com/nats-io/nats.go v1.9.1 | ||
github.com/openfaas-incubator/go-function-sdk v0.0.0-20191017092257-70701da50a91 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= | ||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo= | ||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= | ||
github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= | ||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= | ||
github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= | ||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= | ||
github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= | ||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= | ||
github.com/nats-io/nkeys v0.1.0 h1:qMd4+pRHgdr1nAClu+2h/2a5F2TmKcCzjCDazVgRoX4= | ||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= | ||
github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= | ||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= | ||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= | ||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= | ||
github.com/openfaas-incubator/go-function-sdk v0.0.0-20191017092257-70701da50a91 h1:18SEXx3EzxO9wdrcO+EKePNM0JCquzyLjiPYbgIfX7w= | ||
github.com/openfaas-incubator/go-function-sdk v0.0.0-20191017092257-70701da50a91/go.mod h1:F37Kp+hwdHP+o3UKjkGzikQg4weKiMvcegT9vCQjvjE= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc= | ||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0= | ||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package function | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
nats "github.com/nats-io/nats.go" | ||
handler "github.com/openfaas-incubator/go-function-sdk" | ||
) | ||
|
||
var ( | ||
subject = "nats-test" | ||
defaultMessage = "Hello World" | ||
) | ||
|
||
// Handle a serverless request | ||
func Handle(req handler.Request) (handler.Response, error) { | ||
msg := defaultMessage | ||
if len(req.Body) > 0 { | ||
msg = string(bytes.TrimSpace(req.Body)) | ||
} | ||
|
||
natsURL := nats.DefaultURL | ||
val, ok := os.LookupEnv("nats_url") | ||
if ok { | ||
natsURL = val | ||
} | ||
|
||
nc, err := nats.Connect(natsURL) | ||
if err != nil { | ||
r := handler.Response{ | ||
Body: []byte(fmt.Sprintf("can not connect to nats: %s", err)), | ||
StatusCode: http.StatusInternalServerError, | ||
} | ||
return r, err | ||
} | ||
defer nc.Close() | ||
|
||
log.Printf("Sending %q to %q\n", msg, subject) | ||
err = nc.Publish(subject, []byte(msg)) | ||
if err != nil { | ||
log.Println(err) | ||
r := handler.Response{ | ||
Body: []byte(fmt.Sprintf("can not publish to nats: %s", err)), | ||
StatusCode: http.StatusInternalServerError, | ||
} | ||
return r, err | ||
} | ||
|
||
return handler.Response{ | ||
Body: []byte(fmt.Sprintf("Sent %q", msg)), | ||
StatusCode: http.StatusOK, | ||
}, nil | ||
} |
16 changes: 16 additions & 0 deletions
16
contrib/test-functions/publish-message/vendor/github.com/nats-io/jwt/.gitignore
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
contrib/test-functions/publish-message/vendor/github.com/nats-io/jwt/.travis.yml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.