Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3e2580c

Browse files
authored
Merge pull request #115 from gtardif/grpc_e2e
First e2e test running grpc e2e test (js test client)
2 parents cf1be96 + 0738326 commit 3e2580c

File tree

8 files changed

+2269
-1
lines changed

8 files changed

+2269
-1
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,14 @@ jobs:
5151
- name: Build
5252
run: make -f builder.Makefile cli
5353

54+
- name: Install Protoc
55+
uses: arduino/setup-protoc@master
56+
with:
57+
version: '3.9.1'
58+
59+
- uses: actions/setup-node@v1
60+
with:
61+
node-version: '10.x'
62+
5463
- name: E2E Test
55-
run: make e2e-local
64+
run: make e2e-local

tests/e2e/e2e.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package main
22

33
import (
4+
"os"
5+
"os/exec"
46
"time"
57

68
. "github.com/onsi/gomega"
@@ -93,4 +95,28 @@ func main() {
9395
output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
9496
Expect(output).To(ContainSubstring("Running container \"nginx\" with name"))
9597
})
98+
99+
It("can run 'serve' command", func() {
100+
server, err := startCliServer()
101+
Expect(err).To(BeNil())
102+
defer killCliServer(server)
103+
104+
NewCommand("yarn", "install").WithinDirectory("tests/node-client").ExecOrDie()
105+
output := NewCommand("yarn", "run", "start", "test-example").WithinDirectory("tests/node-client").ExecOrDie()
106+
Expect(output).To(ContainSubstring("nginx"))
107+
})
108+
}
109+
110+
func killCliServer(process *os.Process) {
111+
err := process.Kill()
112+
Expect(err).To(BeNil())
113+
}
114+
115+
func startCliServer() (*os.Process, error) {
116+
cmd := exec.Command("./bin/docker", "serve", "--address", "unix:///tmp/backend.sock")
117+
err := cmd.Start()
118+
if err != nil {
119+
return nil, err
120+
}
121+
return cmd.Process, nil
96122
}

tests/node-client/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

tests/node-client/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules/.bin/grpc_tools_node_protoc \
2+
--js_out=import_style=commonjs,binary:./grpc \
3+
--grpc_out=generate_package_definition:./grpc \
4+
-I ../../cli/v1 \
5+
-I ../../containers/v1 \
6+
../../cli/v1/*.proto \
7+
../../containers/v1/*.proto
8+
9+
# generate d.ts codes
10+
protoc \
11+
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
12+
--ts_out=generate_package_definition:./grpc \
13+
-I ../../cli/v1 \
14+
-I ../../containers/v1 \
15+
../../cli/v1/*.proto \
16+
../../containers/v1/*.proto

tests/node-client/grpc/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/node-client/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as grpc from '@grpc/grpc-js';
2+
import * as continersPb from "./grpc/containers_grpc_pb";
3+
import { IContainersClient } from './grpc/containers_grpc_pb';
4+
import { ListRequest, ListResponse } from "./grpc/containers_pb";
5+
6+
const ContainersServiceClient = grpc.makeClientConstructor(continersPb["com.docker.api.containers.v1.Containers"], "ContainersClient");
7+
const client = new ContainersServiceClient("unix:///tmp/backend.sock", grpc.credentials.createInsecure()) as unknown as IContainersClient;
8+
9+
let backend = process.argv[2] || "moby";
10+
const meta = new grpc.Metadata();
11+
meta.set("CONTEXT_KEY", backend);
12+
13+
client.list(new ListRequest(), meta, (err: any, response: ListResponse) => {
14+
if (err != null) {
15+
console.error(err);
16+
return;
17+
}
18+
19+
const containers = response.getContainersList();
20+
21+
containers.forEach(container => {
22+
console.log(container.getId(), container.getImage());
23+
});
24+
});

tests/node-client/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "ts-test-api",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"scripts": {
7+
"start": "ts-node index.ts",
8+
"prestart": "./build.sh"
9+
},
10+
"dependencies": {
11+
"@grpc/grpc-js": "^1.0.3",
12+
"grpc": "^1.24.2",
13+
"grpc-tools": "^1.8.1",
14+
"grpc_tools_node_protoc_ts": "^3.0.0",
15+
"ts-node": "^8.9.1",
16+
"typescript": "^3.8.3"
17+
}
18+
}

0 commit comments

Comments
 (0)