First e2e test running grpc e2e test (js test client)

This commit is contained in:
Guillaume Tardif 2020-05-18 15:55:21 +02:00
parent 20009c55c3
commit 073832631f
8 changed files with 2269 additions and 1 deletions

View File

@ -51,5 +51,14 @@ jobs:
- name: Build
run: make -f builder.Makefile cli
- name: Install Protoc
uses: arduino/setup-protoc@master
with:
version: '3.9.1'
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: E2E Test
run: make e2e-local
run: make e2e-local

View File

@ -1,6 +1,8 @@
package main
import (
"os"
"os/exec"
"time"
. "github.com/onsi/gomega"
@ -84,4 +86,28 @@ func main() {
output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
Expect(output).To(ContainSubstring("Running container \"nginx\" with name"))
})
It("can run 'serve' command", func() {
server, err := startCliServer()
Expect(err).To(BeNil())
defer killCliServer(server)
NewCommand("yarn", "install").WithinDirectory("tests/node-client").ExecOrDie()
output := NewCommand("yarn", "run", "start", "test-example").WithinDirectory("tests/node-client").ExecOrDie()
Expect(output).To(ContainSubstring("nginx"))
})
}
func killCliServer(process *os.Process) {
err := process.Kill()
Expect(err).To(BeNil())
}
func startCliServer() (*os.Process, error) {
cmd := exec.Command("./bin/docker", "serve", "--address", "unix:///tmp/backend.sock")
err := cmd.Start()
if err != nil {
return nil, err
}
return cmd.Process, nil
}

1
tests/node-client/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

16
tests/node-client/build.sh Executable file
View File

@ -0,0 +1,16 @@
node_modules/.bin/grpc_tools_node_protoc \
--js_out=import_style=commonjs,binary:./grpc \
--grpc_out=generate_package_definition:./grpc \
-I ../../cli/v1 \
-I ../../containers/v1 \
../../cli/v1/*.proto \
../../containers/v1/*.proto
# generate d.ts codes
protoc \
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
--ts_out=generate_package_definition:./grpc \
-I ../../cli/v1 \
-I ../../containers/v1 \
../../cli/v1/*.proto \
../../containers/v1/*.proto

2
tests/node-client/grpc/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

View File

@ -0,0 +1,24 @@
import * as grpc from '@grpc/grpc-js';
import * as continersPb from "./grpc/containers_grpc_pb";
import { IContainersClient } from './grpc/containers_grpc_pb';
import { ListRequest, ListResponse } from "./grpc/containers_pb";
const ContainersServiceClient = grpc.makeClientConstructor(continersPb["com.docker.api.containers.v1.Containers"], "ContainersClient");
const client = new ContainersServiceClient("unix:///tmp/backend.sock", grpc.credentials.createInsecure()) as unknown as IContainersClient;
let backend = process.argv[2] || "moby";
const meta = new grpc.Metadata();
meta.set("CONTEXT_KEY", backend);
client.list(new ListRequest(), meta, (err: any, response: ListResponse) => {
if (err != null) {
console.error(err);
return;
}
const containers = response.getContainersList();
containers.forEach(container => {
console.log(container.getId(), container.getImage());
});
});

View File

@ -0,0 +1,18 @@
{
"name": "ts-test-api",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "ts-node index.ts",
"prestart": "./build.sh"
},
"dependencies": {
"@grpc/grpc-js": "^1.0.3",
"grpc": "^1.24.2",
"grpc-tools": "^1.8.1",
"grpc_tools_node_protoc_ts": "^3.0.0",
"ts-node": "^8.9.1",
"typescript": "^3.8.3"
}
}

2172
tests/node-client/yarn.lock Normal file

File diff suppressed because it is too large Load Diff