-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
55 lines (46 loc) · 1.05 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"flag"
"os"
"testing"
"github.com/metadium/go-delegator/crypto"
"github.com/metadium/go-delegator/json"
"github.com/aws/aws-lambda-go/events"
)
func testHelp() {
os.Args = os.Args[:1]
}
func testEnv() {
os.Setenv(crypto.IsAwsLambda, "")
os.Setenv(crypto.Path, "crypto/test/testkey")
os.Setenv(crypto.Passphrase, "")
}
func testArg() {
os.Setenv(crypto.IsAwsLambda, "")
os.Args[1] = "crypto/test/testkey"
os.Args[2] = ""
}
// FIXME: os.Setenv is not reflected to main()
func TestMain(m *testing.M) {
//testHelp()
//testEnv()
testArg()
flag.Parse()
os.Exit(m.Run())
}
func TestLambdaHandler(t *testing.T) {
req := json.RPCRequest{
Jsonrpc: "2.0",
Method: "eth_getBalance",
ID: 1,
}
req.Params = append(req.Params, "0xeeaf5f87cb85433a0db0fc31863b21d1c8279f7d")
req.Params = append(req.Params, "latest")
req.Params = append(req.Params, "ether")
resp, err := lambdaHandler(nil, events.APIGatewayProxyRequest{
Body: req.String(),
})
if resp.Body == "" || err != nil {
t.Errorf("Failed to start main")
}
}