Add golint to test (#255)

* Add a new lint rule to the Makefile

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Fix linter errors

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>

* Allow replacing the default apt mirror

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickaël Laventure 2016-06-03 15:00:49 -07:00 committed by Michael Crosby
parent 4176ba7b52
commit 5624732128
38 changed files with 297 additions and 151 deletions

View file

@ -44,14 +44,14 @@ func untarRootfs(source string, destination string) error {
func CreateBundleWithFilter(source, name string, args []string, filter func(spec *ocs.Spec)) error {
// Generate the spec
var spec ocs.Spec
if f, err := os.Open(utils.RefOciSpecsPath); err != nil {
f, err := os.Open(utils.RefOciSpecsPath)
if err != nil {
return fmt.Errorf("Failed to open default spec: %v", err)
} else {
if err := json.NewDecoder(f).Decode(&spec); err != nil {
return fmt.Errorf("Failed to load default spec: %v", err)
}
f.Close()
}
if err := json.NewDecoder(f).Decode(&spec); err != nil {
return fmt.Errorf("Failed to load default spec: %v", err)
}
f.Close()
spec.Process.Args = args
spec.Process.Terminal = false

View file

@ -21,10 +21,10 @@ func (cs *ContainerdSuite) ListRunningContainers() ([]*types.Container, error) {
return resp.Containers, nil
}
func (cs *ContainerdSuite) SignalContainerProcess(id string, procId string, sig uint32) error {
func (cs *ContainerdSuite) SignalContainerProcess(id string, procID string, sig uint32) error {
_, err := cs.grpcClient.Signal(context.Background(), &types.SignalRequest{
Id: id,
Pid: procId,
Pid: procID,
Signal: sig,
})
return err
@ -74,8 +74,8 @@ type stdio struct {
stderrBuffer bytes.Buffer
}
type containerProcess struct {
containerId string
type ContainerProcess struct {
containerID string
pid string
bundle *Bundle
io stdio
@ -84,7 +84,7 @@ type containerProcess struct {
hasExited bool
}
func (c *containerProcess) openIo() (err error) {
func (c *ContainerProcess) openIo() (err error) {
defer func() {
if err != nil {
c.Cleanup()
@ -111,11 +111,11 @@ func (c *containerProcess) openIo() (err error) {
return nil
}
func (c *containerProcess) GetEventsChannel() chan *types.Event {
func (c *ContainerProcess) GetEventsChannel() chan *types.Event {
return c.eventsCh
}
func (c *containerProcess) GetNextEvent() *types.Event {
func (c *ContainerProcess) GetNextEvent() *types.Event {
if c.hasExited {
return nil
}
@ -131,16 +131,16 @@ func (c *containerProcess) GetNextEvent() *types.Event {
return e
}
func (c *containerProcess) CloseStdin() error {
func (c *ContainerProcess) CloseStdin() error {
_, err := c.cs.grpcClient.UpdateProcess(context.Background(), &types.UpdateProcessRequest{
Id: c.containerId,
Id: c.containerID,
Pid: c.pid,
CloseStdin: true,
})
return err
}
func (c *containerProcess) Cleanup() {
func (c *ContainerProcess) Cleanup() {
for _, f := range []*os.File{
c.io.stdinf,
c.io.stdoutf,
@ -153,9 +153,9 @@ func (c *containerProcess) Cleanup() {
}
}
func NewContainerProcess(cs *ContainerdSuite, bundle *Bundle, cid, pid string) (c *containerProcess, err error) {
c = &containerProcess{
containerId: cid,
func NewContainerProcess(cs *ContainerdSuite, bundle *Bundle, cid, pid string) (c *ContainerProcess, err error) {
c = &ContainerProcess{
containerID: cid,
pid: "init",
bundle: bundle,
eventsCh: make(chan *types.Event, 8),
@ -181,7 +181,7 @@ func NewContainerProcess(cs *ContainerdSuite, bundle *Bundle, cid, pid string) (
return c, nil
}
func (cs *ContainerdSuite) StartContainerWithEventFilter(id, bundleName string, filter func(*types.Event)) (c *containerProcess, err error) {
func (cs *ContainerdSuite) StartContainerWithEventFilter(id, bundleName string, filter func(*types.Event)) (c *ContainerProcess, err error) {
bundle := GetBundle(bundleName)
if bundle == nil {
return nil, fmt.Errorf("No such bundle '%s'", bundleName)
@ -216,11 +216,11 @@ func (cs *ContainerdSuite) StartContainerWithEventFilter(id, bundleName string,
return c, nil
}
func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *containerProcess, err error) {
func (cs *ContainerdSuite) StartContainer(id, bundleName string) (c *ContainerProcess, err error) {
return cs.StartContainerWithEventFilter(id, bundleName, nil)
}
func (cs *ContainerdSuite) RunContainer(id, bundleName string) (c *containerProcess, err error) {
func (cs *ContainerdSuite) RunContainer(id, bundleName string) (c *ContainerProcess, err error) {
c, err = cs.StartContainer(id, bundleName)
if err != nil {
return nil, err
@ -236,14 +236,14 @@ func (cs *ContainerdSuite) RunContainer(id, bundleName string) (c *containerProc
return c, err
}
func (cs *ContainerdSuite) AddProcessToContainer(init *containerProcess, pid, cwd string, env, args []string, uid, gid uint32) (c *containerProcess, err error) {
c, err = NewContainerProcess(cs, init.bundle, init.containerId, pid)
func (cs *ContainerdSuite) AddProcessToContainer(init *ContainerProcess, pid, cwd string, env, args []string, uid, gid uint32) (c *ContainerProcess, err error) {
c, err = NewContainerProcess(cs, init.bundle, init.containerID, pid)
if err != nil {
return nil, err
}
pr := &types.AddProcessRequest{
Id: init.containerId,
Id: init.containerID,
Pid: pid,
Args: args,
Cwd: cwd,

View file

@ -17,12 +17,12 @@ func (cs *ContainerdSuite) TestBusyboxTopExecEcho(t *check.C) {
var (
err error
initp *containerProcess
echop *containerProcess
initp *ContainerProcess
echop *ContainerProcess
)
containerId := "top"
initp, err = cs.StartContainer(containerId, bundleName)
containerID := "top"
initp, err = cs.StartContainer(containerID, bundleName)
t.Assert(err, checker.Equals, nil)
echop, err = cs.AddProcessToContainer(initp, "echo", "/", []string{"PATH=/bin"}, []string{"sh", "-c", "echo -n Ay Caramba! ; exit 1"}, 0, 0)
@ -31,19 +31,19 @@ func (cs *ContainerdSuite) TestBusyboxTopExecEcho(t *check.C) {
for _, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "start-process",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "echo",
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 1,
Pid: "echo",
},
@ -66,35 +66,35 @@ func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) {
var (
err error
initp *containerProcess
initp *ContainerProcess
)
containerId := "top"
initp, err = cs.StartContainer(containerId, bundleName)
containerID := "top"
initp, err = cs.StartContainer(containerID, bundleName)
t.Assert(err, checker.Equals, nil)
execId := "top1"
_, err = cs.AddProcessToContainer(initp, execId, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
execID := "top1"
_, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
t.Assert(err, checker.Equals, nil)
for idx, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "start-process",
Id: containerId,
Id: containerID,
Status: 0,
Pid: execId,
Pid: execID,
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 137,
Pid: execId,
Pid: execID,
},
} {
ch := initp.GetEventsChannel()
@ -103,7 +103,7 @@ func (cs *ContainerdSuite) TestBusyboxTopExecTop(t *check.C) {
t.Assert(*e, checker.Equals, evt)
if idx == 1 {
// Process Started, kill it
cs.SignalContainerProcess(containerId, "top1", uint32(syscall.SIGKILL))
cs.SignalContainerProcess(containerID, "top1", uint32(syscall.SIGKILL))
}
}
@ -126,39 +126,39 @@ func (cs *ContainerdSuite) TestBusyboxTopExecTopKillInit(t *check.C) {
var (
err error
initp *containerProcess
initp *ContainerProcess
)
containerId := "top"
initp, err = cs.StartContainer(containerId, bundleName)
containerID := "top"
initp, err = cs.StartContainer(containerID, bundleName)
t.Assert(err, checker.Equals, nil)
execId := "top1"
_, err = cs.AddProcessToContainer(initp, execId, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
execID := "top1"
_, err = cs.AddProcessToContainer(initp, execID, "/", []string{"PATH=/usr/bin"}, []string{"top"}, 0, 0)
t.Assert(err, checker.Equals, nil)
for idx, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "start-process",
Id: containerId,
Id: containerID,
Status: 0,
Pid: execId,
Pid: execID,
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 137,
Pid: execId,
Pid: execID,
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 143,
Pid: "init",
},
@ -169,7 +169,7 @@ func (cs *ContainerdSuite) TestBusyboxTopExecTopKillInit(t *check.C) {
t.Assert(*e, checker.Equals, evt)
if idx == 1 {
// Process Started, kill it
cs.SignalContainerProcess(containerId, "init", uint32(syscall.SIGTERM))
cs.SignalContainerProcess(containerID, "init", uint32(syscall.SIGTERM))
}
}
}

View file

@ -79,8 +79,8 @@ func (cs *ContainerdSuite) TestStartBusyboxLsEvents(t *check.C) {
t.Fatal(err)
}
containerId := "ls-events"
c, err := cs.StartContainer(containerId, "busybox-ls")
containerID := "ls-events"
c, err := cs.StartContainer(containerID, "busybox-ls")
if err != nil {
t.Fatal(err)
}
@ -88,13 +88,13 @@ func (cs *ContainerdSuite) TestStartBusyboxLsEvents(t *check.C) {
for _, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "init",
},
@ -144,7 +144,7 @@ func (cs *ContainerdSuite) TestStartBusyboxTopKill(t *check.C) {
t.Fatal(err)
}
containerId := "top"
containerID := "top"
c, err := cs.StartContainer("top", bundleName)
if err != nil {
t.Fatal(err)
@ -152,7 +152,7 @@ func (cs *ContainerdSuite) TestStartBusyboxTopKill(t *check.C) {
<-time.After(1 * time.Second)
err = cs.KillContainer(containerId)
err = cs.KillContainer(containerID)
if err != nil {
t.Fatal(err)
}
@ -160,13 +160,13 @@ func (cs *ContainerdSuite) TestStartBusyboxTopKill(t *check.C) {
for _, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 128 + uint32(syscall.SIGKILL),
Pid: "init",
},
@ -189,7 +189,7 @@ func (cs *ContainerdSuite) TestStartBusyboxTopSignalSigterm(t *check.C) {
t.Fatal(err)
}
containerId := "top"
containerID := "top"
c, err := cs.StartContainer("top", bundleName)
if err != nil {
t.Fatal(err)
@ -197,7 +197,7 @@ func (cs *ContainerdSuite) TestStartBusyboxTopSignalSigterm(t *check.C) {
<-time.After(1 * time.Second)
err = cs.SignalContainer(containerId, uint32(syscall.SIGTERM))
err = cs.SignalContainer(containerID, uint32(syscall.SIGTERM))
if err != nil {
t.Fatal(err)
}
@ -205,13 +205,13 @@ func (cs *ContainerdSuite) TestStartBusyboxTopSignalSigterm(t *check.C) {
for _, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 128 + uint32(syscall.SIGTERM),
Pid: "init",
},
@ -233,13 +233,13 @@ func (cs *ContainerdSuite) TestStartBusyboxTrapUSR1(t *check.C) {
t.Fatal(err)
}
containerId := "trap-usr1"
c, err := cs.StartContainer(containerId, "busybox-trap-usr1")
containerID := "trap-usr1"
c, err := cs.StartContainer(containerID, "busybox-trap-usr1")
if err != nil {
t.Fatal(err)
}
if err := cs.SignalContainer(containerId, uint32(syscall.SIGUSR1)); err != nil {
if err := cs.SignalContainer(containerID, uint32(syscall.SIGUSR1)); err != nil {
t.Fatal(err)
}
@ -259,36 +259,36 @@ func (cs *ContainerdSuite) TestStartBusyboxTopPauseResume(t *check.C) {
t.Fatal(err)
}
containerId := "top"
c, err := cs.StartContainer(containerId, bundleName)
containerID := "top"
c, err := cs.StartContainer(containerID, bundleName)
if err != nil {
t.Fatal(err)
}
if err := cs.PauseContainer(containerId); err != nil {
if err := cs.PauseContainer(containerID); err != nil {
t.Fatal(err)
}
if err := cs.ResumeContainer(containerId); err != nil {
if err := cs.ResumeContainer(containerID); err != nil {
t.Fatal(err)
}
for _, evt := range []types.Event{
{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "pause",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
{
Type: "resume",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
},
@ -323,8 +323,8 @@ func (cs *ContainerdSuite) TestRestart(t *check.C) {
totalCtr := 10
for i := 0; i < totalCtr; i++ {
containerId := fmt.Sprintf("top%d", i)
c, err := cs.StartContainer(containerId, bundleName)
containerID := fmt.Sprintf("top%d", i)
c, err := cs.StartContainer(containerID, bundleName)
if err != nil {
t.Fatal(err)
}
@ -333,7 +333,7 @@ func (cs *ContainerdSuite) TestRestart(t *check.C) {
t.Assert(*e, checker.Equals, types.Event{
Type: "start-container",
Id: containerId,
Id: containerID,
Status: 0,
Pid: "",
Timestamp: e.Timestamp,
@ -369,18 +369,18 @@ func (cs *ContainerdSuite) TestRestart(t *check.C) {
deathChans := make([]chan error, len(killedCtr))
deathChansIdx := 0
for i, _ := range killedCtr {
for i := range killedCtr {
ch := make(chan error, 1)
deathChans[deathChansIdx] = ch
deathChansIdx++
syscall.Kill(int(containers[i].Pids[0]), syscall.SIGKILL)
// Filter to be notified of their death
containerId := fmt.Sprintf("top%d", i)
containerID := fmt.Sprintf("top%d", i)
f = func(event *types.Event) {
expectedEvent := types.Event{
Type: "exit",
Id: containerId,
Id: containerID,
Status: 137,
Pid: "init",
}
@ -391,13 +391,13 @@ func (cs *ContainerdSuite) TestRestart(t *check.C) {
ch <- nil
}
}
cs.SetContainerEventFilter(containerId, f)
cs.SetContainerEventFilter(containerID, f)
}
cs.RestartDaemon(true)
// Ensure we got our events
for i, _ := range deathChans {
for i := range deathChans {
done := false
for done == false {
select {