-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skeleton for Noto domainapi test
Signed-off-by: Andrew Richardson <[email protected]>
- Loading branch information
Showing
9 changed files
with
430 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright © 2024 Kaleido, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
task test(dependsOn: ':kata:startTestbed') {} |
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,14 @@ | ||
module github.com/kaleido-io/paladin/domains/noto | ||
|
||
go 1.22.5 | ||
|
||
require github.com/gorilla/rpc v1.2.1 | ||
|
||
require ( | ||
golang.org/x/net v0.25.0 // indirect | ||
golang.org/x/sys v0.20.0 // indirect | ||
golang.org/x/text v0.15.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect | ||
google.golang.org/grpc v1.65.0 // indirect | ||
google.golang.org/protobuf v1.34.1 // indirect | ||
) |
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,14 @@ | ||
github.com/gorilla/rpc v1.2.1 h1:yC+LMV5esttgpVvNORL/xX4jvTTEUE30UZhZ5JF7K9k= | ||
github.com/gorilla/rpc v1.2.1/go.mod h1:uNpOihAlF5xRFLuTYhfR0yfCTm0WTQSQttkMSptRfGk= | ||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= | ||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= | ||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= | ||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= | ||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= | ||
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= | ||
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= | ||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= | ||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= |
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,39 @@ | ||
/* | ||
* Copyright © 2024 Kaleido, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package noto | ||
|
||
import ( | ||
"log" | ||
"reflect" | ||
|
||
pb "github.com/kaleido-io/paladin/kata/pkg/proto" | ||
) | ||
|
||
func HandleDomainMessage(message *pb.Message) error { | ||
body, err := message.Body.UnmarshalNew() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch m := body.(type) { | ||
case *pb.ConfigureDomainRequest: | ||
log.Printf("Configuring domain: %s", m.Name) | ||
default: | ||
log.Printf("Unknown type: %s", reflect.TypeOf(m)) | ||
} | ||
|
||
return nil | ||
} |
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,128 @@ | ||
/* | ||
* Copyright © 2024 Kaleido, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"log" | ||
"time" | ||
|
||
pb "github.com/kaleido-io/paladin/kata/pkg/proto" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/ffresty" | ||
"github.com/hyperledger/firefly-signer/pkg/rpcbackend" | ||
"github.com/kaleido-io/paladin/domains/noto/internal/noto" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
var ( | ||
dest = "to-domain" | ||
testbedAddr = "http://127.0.0.1:49603" | ||
grpcAddr = "unix:/tmp/testbed.paladin.1542386773.sock" | ||
) | ||
|
||
func connectGRPC(ctx context.Context) (*grpc.ClientConn, pb.KataMessageService_ListenClient, error) { | ||
var opts []grpc.DialOption | ||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
conn, err := grpc.NewClient(grpcAddr, opts...) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to connect gRPC: %v", err) | ||
} | ||
|
||
client := pb.NewKataMessageServiceClient(conn) | ||
status, err := client.Status(ctx, &pb.StatusRequest{}) | ||
|
||
delay := 0 | ||
for !status.GetOk() { | ||
time.Sleep(time.Second) | ||
delay++ | ||
status, err = client.Status(ctx, &pb.StatusRequest{}) | ||
if delay > 2 { | ||
return nil, nil, fmt.Errorf("server was not ready after 2 seconds") | ||
} | ||
} | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
if !status.GetOk() { | ||
return nil, nil, fmt.Errorf("got non OK status from server") | ||
} | ||
|
||
stream, err := client.Listen(ctx, &pb.ListenRequest{Destination: dest}) | ||
if err != nil { | ||
return nil, nil, fmt.Errorf("failed to listen for domain events: %v", err) | ||
} | ||
return conn, stream, nil | ||
} | ||
|
||
func listenGRPC(stream pb.KataMessageService_ListenClient, closed chan struct{}) { | ||
for { | ||
in, err := stream.Recv() | ||
if err == io.EOF { | ||
close(closed) | ||
return | ||
} | ||
if err != nil { | ||
log.Fatalf("Failed to receive a message: %v", err) | ||
} | ||
err = noto.HandleDomainMessage(in) | ||
if err != nil { | ||
log.Printf("Error handling message: %s", err) | ||
close(closed) | ||
return | ||
} | ||
} | ||
} | ||
|
||
func runTest(ctx context.Context) error { | ||
conn, stream, err := connectGRPC(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
|
||
log.Printf("Listening for gRPC messages on %s", dest) | ||
closed := make(chan struct{}) | ||
go listenGRPC(stream, closed) | ||
|
||
conf := ffresty.Config{URL: testbedAddr} | ||
rest := ffresty.NewWithConfig(ctx, conf) | ||
rpc := rpcbackend.NewRPCClient(rest) | ||
|
||
log.Printf("Calling testbed_configureInit") | ||
var result map[string]interface{} | ||
rpcerr := rpc.CallRPC(ctx, &result, "testbed_configureInit", "noto", `{}`) | ||
if rpcerr != nil { | ||
return fmt.Errorf("fail to call JSON RPC: %v", rpcerr) | ||
} | ||
|
||
log.Printf("Closing stream") | ||
_ = stream.CloseSend() | ||
log.Printf("Awaiting close") | ||
<-closed | ||
return nil | ||
} | ||
|
||
func main() { | ||
ctx := context.Background() | ||
err := runTest(ctx) | ||
if err != nil { | ||
log.Fatalf("%s", err) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
go 1.22.5 | ||
|
||
use ( | ||
./domains/noto | ||
./kata | ||
./talaria | ||
./testinfra | ||
|
Oops, something went wrong.