PoC: Network simulation framework (#1555)
* simv2: wip * simulation: exec adapter start/stop * simulation: add node status to exec adapter * simulation: initial simulation code * simulation: exec adapter, configure path to executable * simulation: initial docker adapter * simulation: wip kubernetes adapter * simulation: kubernetes adapter proxy * simulation: implement GetAll/StartAll/StopAll * simulation: kuberentes adapter - set env vars and resource limits * simulation: discovery test * simulation: remove port definitions within docker adapter * simulation: simplify wait for healthy loop * simulation: get nat ip addr from interface * simulation: pull docker images automatically * simulation: NodeStatus -> NodeInfo * simulation: move discovery test to example dir * simulation: example snapshot usage * simulation: add goclient specific simulation * simulation: add peer connections to snapshot * simulation: close rpc client * simulation: don't export kubernetes proxy server * simulation: merge simulation code * simulation: don't export nodemap * simulation: rename SimulationSnapshot -> Snapshot * simulation: linting fixes * simulation: add k8s available helper func * simulation: vendor * simulation: fix 'no non-test Go files' when building * simulation: remove errors from interface methods where non were returned * simulation: run getHealthInfo check in parallel
This commit is contained in:
53
simulation/docker_test.go
Normal file
53
simulation/docker_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
)
|
||||
|
||||
func TestDockerAdapterBuild(t *testing.T) {
|
||||
if !IsDockerAvailable(client.DefaultDockerHost) {
|
||||
t.Skip("could not connect to the docker daemon")
|
||||
}
|
||||
|
||||
// Create a docker client
|
||||
c, err := dockerClient()
|
||||
if err != nil {
|
||||
t.Fatalf("could not create docker client: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
imageTag := "test-docker-adapter-build:latest"
|
||||
|
||||
config := DefaultDockerAdapterConfig()
|
||||
|
||||
// Build based on a Dockerfile
|
||||
config.BuildContext = &DockerBuildContext{
|
||||
Directory: "../",
|
||||
Dockerfile: "Dockerfile",
|
||||
Tag: imageTag,
|
||||
}
|
||||
|
||||
// Create docker adapter: This will build the image
|
||||
_, err = NewDockerAdapter(config)
|
||||
if err != nil {
|
||||
t.Fatalf("could not create docker adapter: %v", err)
|
||||
}
|
||||
|
||||
// Cleanup image
|
||||
_, err = c.ImageRemove(context.Background(), imageTag, types.ImageRemoveOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("could not delete docker image: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create docker client
|
||||
func dockerClient() (*client.Client, error) {
|
||||
return client.NewClientWithOpts(
|
||||
client.WithHost(client.DefaultDockerHost),
|
||||
client.WithAPIVersionNegotiation(),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user