Skip to content

Commit

Permalink
Add golint to test (#255)
Browse files Browse the repository at this point in the history
* Add a new lint rule to the Makefile

Signed-off-by: Kenfe-Mickael Laventure <[email protected]>

* Fix linter errors

Signed-off-by: Kenfe-Mickael Laventure <[email protected]>

* Allow replacing the default apt mirror

Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
  • Loading branch information
mlaventure authored and crosbymichael committed Jun 3, 2016
1 parent 4176ba7 commit 5624732
Show file tree
Hide file tree
Showing 38 changed files with 297 additions and 151 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
FROM debian:jessie

# allow replacing httpredir mirror
ARG APT_MIRROR=httpredir.debian.org
RUN sed -i s/httpredir.debian.org/$APT_MIRROR/g /etc/apt/sources.list

RUN apt-get update && apt-get install -y \
build-essential \
ca-certificates \
Expand All @@ -18,6 +22,20 @@ RUN curl -sSL "https://storage.googleapis.com/golang/go${GO_VERSION}.linux-amd6
ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go:/go/src/github.com/docker/containerd/vendor

ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
# Grab Go's cover tool for dead-simple code coverage testing
# Grab Go's vet tool for examining go code to find suspicious constructs
# and help prevent errors that the compiler might not catch
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT) \
&& go install -v golang.org/x/tools/cmd/cover \
&& go install -v golang.org/x/tools/cmd/vet
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint

WORKDIR /go/src/github.com/docker/containerd

# install seccomp: the version shipped in trusty is too old
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fmt:
@gofmt -s -l . | grep -v vendor | grep -v .pb. | tee /dev/stderr

lint:
@golint ./... | grep -v vendor | grep -v .pb. | tee /dev/stderr
@hack/validate-lint

shell: dbuild
$(DOCKER_RUN) bash
Expand All @@ -95,7 +95,7 @@ endif
bench: shim validate install bundles-rootfs
go test -bench=. -v $(shell go list ./... | grep -v /vendor | grep -v /integration-test)

validate: fmt
validate: fmt lint

uninstall:
$(foreach file,containerd containerd-shim ctr,rm /usr/local/bin/$(file);)
18 changes: 9 additions & 9 deletions api/grpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (s *apiServer) CreateCheckpoint(ctx context.Context, r *types.CreateCheckpo
e.Checkpoint = &runtime.Checkpoint{
Name: r.Checkpoint.Name,
Exit: r.Checkpoint.Exit,
Tcp: r.Checkpoint.Tcp,
TCP: r.Checkpoint.Tcp,
UnixSockets: r.Checkpoint.UnixSockets,
Shell: r.Checkpoint.Shell,
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *apiServer) ListCheckpoint(ctx context.Context, r *types.ListCheckpointR
for _, c := range checkpoints {
out = append(out, &types.Checkpoint{
Name: c.Name,
Tcp: c.Tcp,
Tcp: c.TCP,
Shell: c.Shell,
UnixSockets: c.UnixSockets,
// TODO: figure out timestamp
Expand Down Expand Up @@ -333,15 +333,15 @@ func convertToPb(st *runtime.Stat) *types.StatsResponse {
systemUsage, _ := getSystemCPUUsage()
pbSt.CgroupStats.CpuStats = &types.CpuStats{
CpuUsage: &types.CpuUsage{
TotalUsage: st.Cpu.Usage.Total,
PercpuUsage: st.Cpu.Usage.Percpu,
UsageInKernelmode: st.Cpu.Usage.Kernel,
UsageInUsermode: st.Cpu.Usage.User,
TotalUsage: st.CPU.Usage.Total,
PercpuUsage: st.CPU.Usage.Percpu,
UsageInKernelmode: st.CPU.Usage.Kernel,
UsageInUsermode: st.CPU.Usage.User,
},
ThrottlingData: &types.ThrottlingData{
Periods: st.Cpu.Throttling.Periods,
ThrottledPeriods: st.Cpu.Throttling.ThrottledPeriods,
ThrottledTime: st.Cpu.Throttling.ThrottledTime,
Periods: st.CPU.Throttling.Periods,
ThrottledPeriods: st.CPU.Throttling.ThrottledPeriods,
ThrottledTime: st.CPU.Throttling.ThrottledTime,
},
SystemUsage: systemUsage,
}
Expand Down
2 changes: 2 additions & 0 deletions api/http/pprof/pprof.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package pprof

import (
// expvar init routine adds the "/debug/vars" handler
_ "expvar"
"net/http"
"net/http/pprof"

"github.com/Sirupsen/logrus"
)

// Enable registers the "/debug/pprof" handler
func Enable(address string) {
http.Handle("/", http.RedirectHandler("/debug/pprof", http.StatusMovedPermanently))

Expand Down
3 changes: 3 additions & 0 deletions archutils/epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"syscall"
)

// EpollCreate1 directly calls syscall.EpollCreate1
func EpollCreate1(flag int) (int, error) {
return syscall.EpollCreate1(flag)
}

// EpollCtl directly calls syscall.EpollCtl
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
return syscall.EpollCtl(epfd, op, fd, event)
}

// EpollWait directly calls syscall.EpollWait
func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
return syscall.EpollWait(epfd, events, msec)
}
3 changes: 3 additions & 0 deletions archutils/epoll_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"unsafe"
)

// EpollCreate1 calls a C implementation
func EpollCreate1(flag int) (int, error) {
fd := int(C.EpollCreate1(C.int(flag)))
if fd < 0 {
Expand All @@ -48,6 +49,7 @@ func EpollCreate1(flag int) (int, error) {
return fd, nil
}

// EpollCtl calls a C implementation
func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
errno := C.EpollCtl(C.int(epfd), C.int(syscall.EPOLL_CTL_ADD), C.int(fd), C.int(event.Events), C.int(event.Fd))
if errno < 0 {
Expand All @@ -56,6 +58,7 @@ func EpollCtl(epfd int, op int, fd int, event *syscall.EpollEvent) error {
return nil
}

// EpollWait calls a C implementation
func EpollWait(epfd int, events []syscall.EpollEvent, msec int) (int, error) {
var c_events [128]C.struct_event_t
n := int(C.run_epoll_wait(C.int(epfd), (*C.struct_event_t)(unsafe.Pointer(&c_events))))
Expand Down
7 changes: 4 additions & 3 deletions containerd-shim/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type checkpoint struct {
Created time.Time `json:"created"`
// Name is the name of the checkpoint
Name string `json:"name"`
// Tcp checkpoints open tcp connections
Tcp bool `json:"tcp"`
// TCP checkpoints open tcp connections
TCP bool `json:"tcp"`
// UnixSockets persists unix sockets in the checkpoint
UnixSockets bool `json:"unixSockets"`
// Shell persists tty sessions in the checkpoint
Expand Down Expand Up @@ -140,7 +140,7 @@ func (p *process) start() error {
if p.checkpoint.Shell {
add("--shell-job")
}
if p.checkpoint.Tcp {
if p.checkpoint.TCP {
add("--tcp-established")
}
if p.checkpoint.UnixSockets {
Expand Down Expand Up @@ -292,6 +292,7 @@ func (p *process) openIO() error {
return nil
}

// IO holds all 3 standard io Reader/Writer (stdin,stdout,stderr)
type IO struct {
Stdin io.WriteCloser
Stdout io.ReadCloser
Expand Down
6 changes: 3 additions & 3 deletions ctr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import (

const usage = `High performance container daemon cli`

type Exit struct {
type exit struct {
Code int
}

func main() {
// We want our defer functions to be run when calling fatal()
defer func() {
if e := recover(); e != nil {
if ex, ok := e.(Exit); ok == true {
if ex, ok := e.(exit); ok == true {
os.Exit(ex.Code)
}
panic(e)
Expand Down Expand Up @@ -86,5 +86,5 @@ var versionCommand = cli.Command{

func fatal(err string, code int) {
fmt.Fprintf(os.Stderr, "[ctr] %s\n", err)
panic(Exit{code})
panic(exit{code})
}
9 changes: 9 additions & 0 deletions hack/validate-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

lint_error=$(golint ./... | grep -v vendor | grep -v .pb. | tee /dev/stderr)

if [ "$lint_error" != "" ]; then
exit 1
fi

exit 0
12 changes: 6 additions & 6 deletions integration-test/bundle_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions integration-test/container_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 5624732

Please sign in to comment.