Skip to content

Commit 52e384f

Browse files
committed
Rebase with upstream. Added topic environment variable.
Signed-off-by: Rishabh Gupta<[email protected]>
1 parent 8987d86 commit 52e384f

File tree

17 files changed

+781
-54
lines changed

17 files changed

+781
-54
lines changed

cmd/tester/Gopkg.lock

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
[[constraint]]
2929
name = "github.com/openfaas-incubator/connector-sdk"
30-
version = "0.2.0"
30+
version = "0.3.1"
3131

3232
[prune]
3333
go-tests = true

cmd/tester/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ To check if it actually works and triggers a function, deploy any function with
1414
You can also run this command to deploy a sample function and see `trigger-func` invocation count growing in ui.
1515

1616
```bash
17-
faas-cli deploy --image=functions/nodeinfo --name=trigger-func --annotation topic=faas-request
17+
faas-cli deploy --image=functions/nodeinfo --name=trigger-func --annotation topic=vm.powered.on
1818
```

cmd/tester/main.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
package main
66

77
import (
8+
"errors"
89
"log"
10+
"os"
911
"time"
1012

1113
"github.com/openfaas-incubator/connector-sdk/types"
1214
)
1315

1416
func main() {
1517
creds := types.GetCredentials()
16-
config := &types.ControllerConfig{
17-
RebuildInterval: time.Millisecond * 1000,
18-
GatewayURL: "http://127.0.0.1:8080",
19-
PrintResponse: true,
20-
PrintResponseBody: true,
18+
config, err := getControllerConfig()
19+
if err != nil {
20+
panic(err)
2121
}
2222

2323
controller := types.NewController(creds, config)
@@ -27,11 +27,16 @@ func main() {
2727

2828
controller.BeginMapBuilder()
2929

30+
topic, err := getTopic()
31+
if err != nil {
32+
panic(err)
33+
}
34+
3035
// Simulate events emitting from queue/pub-sub
3136
for {
3237
time.Sleep(2 * time.Second)
3338
data := []byte("test " + time.Now().String())
34-
controller.Invoke("vm.powered.on", &data)
39+
controller.Invoke(topic, &data)
3540
}
3641

3742
}
@@ -49,4 +54,27 @@ func (ResponseReceiver) Response(res types.InvokerResponse) {
4954
} else {
5055
log.Printf("tester got result: [%d] %s => %s (%d) bytes", res.Status, res.Topic, res.Function, len(*res.Body))
5156
}
52-
}
57+
}
58+
59+
func getControllerConfig() (*types.ControllerConfig, error) {
60+
gatewayURL, ok := os.LookupEnv("gateway_url")
61+
if !ok {
62+
return nil, errors.New("Gateway URL not set")
63+
}
64+
65+
return &types.ControllerConfig{
66+
RebuildInterval: time.Millisecond * 1000,
67+
GatewayURL: gatewayURL,
68+
PrintResponse: true,
69+
PrintResponseBody: true,
70+
}, nil
71+
}
72+
73+
func getTopic() (string, error) {
74+
topic, ok := os.LookupEnv("topic")
75+
if !ok {
76+
return "", errors.New("topic not provided")
77+
}
78+
79+
return topic, nil
80+
}

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/controller.go

Lines changed: 70 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/invoker.go

Lines changed: 47 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/response_printer.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/tester/vendor/github.com/openfaas-incubator/connector-sdk/types/response_subscriber.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)