-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implemented ExecutionEngine * refactor test suite to spin up/down ExecutionEngine Git issue references: Gamelan music currently playing: Golek Lambangsari
- Loading branch information
connorwalsh
committed
Mar 22, 2018
1 parent
6b4b61d
commit d3ae0a2
Showing
10 changed files
with
211 additions
and
78 deletions.
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
sudo: required | ||
|
||
services: | ||
- docker | ||
|
||
language: go | ||
go: | ||
- "1.9" |
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
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,25 +1,29 @@ | ||
package dockerlang | ||
|
||
import ( | ||
"testing" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
func TestLoadSourceCode_NoSuchFile(t *testing.T) { | ||
type CompterpreterSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (s *CompterpreterSuite) AfterTest(suiteName, testName string) { | ||
ShutdownExecutionEngine() | ||
} | ||
|
||
func (s *CompterpreterSuite) TestLoadSourceCode_NoSuchFile() { | ||
conf := &Config{SrcFileName: "nonexistent_test_src.doc"} | ||
compt := NewCompterpreter(conf) | ||
|
||
err := compt.LoadSourceCode() | ||
if err == nil { | ||
t.Error("failed to fail to find file") | ||
} | ||
s.Error(err) | ||
} | ||
|
||
func TestLoadSourceCode(t *testing.T) { | ||
func (s *CompterpreterSuite) TestLoadSourceCode() { | ||
conf := &Config{SrcFileName: "test/test.doc"} | ||
compt := NewCompterpreter(conf) | ||
|
||
err := compt.LoadSourceCode() | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
s.NoError(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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package dockerlang | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
var ( | ||
executer *ExecutionEngine | ||
) | ||
|
||
type ExecutionEngine struct { | ||
Docker *client.Client | ||
Guillotine string | ||
Network string | ||
} | ||
|
||
// constructs an ExecutionEngine and binds to the globally scoped executer. | ||
func NewExecutionEngine() error { | ||
// set the API version to use in an environment variable | ||
// TODO it would be nice to configure based on the docker version | ||
// a user currently has.... not enough time right now so skipping that. | ||
err := os.Setenv("DOCKER_API_VERSION", "1.35") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dockerClient, err := client.NewEnvClient() | ||
if err != nil { | ||
// this is probably because the person who is using dockerlang | ||
// hasn't installed or started docker on their system -____- | ||
// unclear why anyone would *not* have docker in their life. | ||
return err | ||
} | ||
|
||
// define unique network name | ||
networkName := fmt.Sprintf("dockerlang.%s", uuid.NewV4().String()) | ||
|
||
// bind new ExecutionEngine to globally scoped variable | ||
executer = &ExecutionEngine{ | ||
Docker: dockerClient, | ||
Guillotine: "robespierre", | ||
Network: networkName, | ||
} | ||
|
||
// setup container bridge network if one doesn't already exist. | ||
response, err := executer.Docker.NetworkCreate( | ||
context.TODO(), | ||
networkName, | ||
types.NetworkCreate{}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(response) | ||
|
||
return nil | ||
} | ||
|
||
func ShutdownExecutionEngine() error { | ||
err := executer.Docker.NetworkRemove(context.TODO(), executer.Network) | ||
if err != nil && !client.IsErrNotFound(err) { | ||
// something is very wrong here | ||
panic(err) | ||
} | ||
|
||
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,35 @@ | ||
package dockerlang | ||
|
||
import ( | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ExecutionSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (s *ExecutionSuite) AfterTest(suiteName, testName string) { | ||
ShutdownExecutionEngine() | ||
} | ||
|
||
// NOTE: for these tests to run, we need to ensure that docker is running on the | ||
// host machine! | ||
func (s *ExecutionSuite) TestNewExecutionEngine() { | ||
err := NewExecutionEngine() | ||
s.NoError(err) | ||
} | ||
|
||
func (s *ExecutionSuite) TestShutdownExecutionEngine() { | ||
err := NewExecutionEngine() | ||
s.NoError(err) | ||
|
||
err = ShutdownExecutionEngine() | ||
s.NoError(err) | ||
} | ||
|
||
func (s *ExecutionSuite) TestShutdownExecutionEngine_NonExistent() { | ||
executer.Network = "non-existent network" | ||
|
||
err := ShutdownExecutionEngine() | ||
s.NoError(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
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
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
Oops, something went wrong.