mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Merge pull request #115 from gtardif/grpc_e2e
First e2e test running grpc e2e test (js test client)
This commit is contained in:
commit
3e2580cfdc
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -51,5 +51,14 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: make -f builder.Makefile cli
|
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
|
- name: E2E Test
|
||||||
run: make e2e-local
|
run: make e2e-local
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -93,4 +95,28 @@ func main() {
|
|||||||
output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
|
output := NewDockerCommand("run", "nginx", "-p", "80:80").ExecOrDie()
|
||||||
Expect(output).To(ContainSubstring("Running container \"nginx\" with name"))
|
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
1
tests/node-client/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
16
tests/node-client/build.sh
Executable file
16
tests/node-client/build.sh
Executable 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
2
tests/node-client/grpc/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
24
tests/node-client/index.ts
Normal file
24
tests/node-client/index.ts
Normal 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());
|
||||||
|
});
|
||||||
|
});
|
18
tests/node-client/package.json
Normal file
18
tests/node-client/package.json
Normal 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
2172
tests/node-client/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user