Skip to content

Commit 083b10b

Browse files
authored
Merge pull request containerd#1684 from crosbymichael/lint-final
Enable Go Lint in CI
2 parents 8509569 + 1d298c8 commit 083b10b

File tree

24 files changed

+107
-74
lines changed

24 files changed

+107
-74
lines changed

.appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ before_build:
2626
build_script:
2727
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe setup"
2828
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe fmt"
29+
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:/c/gopath/bin:$PATH ; mingw32-make.exe lint"
2930
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe vet"
3031
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:/c/gopath/bin:$PATH ; mingw32-make.exe ineffassign"
3132
- bash.exe -elc "export PATH=/c/tools/mingw64/bin:$PATH ; mingw32-make.exe build"

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ script:
5353
# Note that `go build -i` requires write permission to GOROOT. (So it is not called in Makefile)
5454
- go build -i .
5555
- make setup
56+
- make lint
5657
- make vet
5758
- make ineffassign
5859
- if [ "$GOOS" = "linux" ]; then make check-protos check-api-descriptors; fi

content/local/store_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestWalkBlobs(t *testing.T) {
137137
)
138138

139139
var (
140-
blobs = populateBlobStore(t, ctx, cs, nblobs, maxsize)
140+
blobs = populateBlobStore(ctx, t, cs, nblobs, maxsize)
141141
expected = map[digest.Digest]struct{}{}
142142
found = map[digest.Digest]struct{}{}
143143
)
@@ -188,7 +188,7 @@ func BenchmarkIngests(b *testing.B) {
188188
b.StartTimer()
189189

190190
for dgst, p := range blobs {
191-
checkWrite(b, ctx, cs, dgst, p)
191+
checkWrite(ctx, b, cs, dgst, p)
192192
}
193193
})
194194
}
@@ -215,11 +215,11 @@ func generateBlobs(t checker, nblobs, maxsize int64) map[digest.Digest][]byte {
215215
return blobs
216216
}
217217

218-
func populateBlobStore(t checker, ctx context.Context, cs content.Store, nblobs, maxsize int64) map[digest.Digest][]byte {
218+
func populateBlobStore(ctx context.Context, t checker, cs content.Store, nblobs, maxsize int64) map[digest.Digest][]byte {
219219
blobs := generateBlobs(t, nblobs, maxsize)
220220

221221
for dgst, p := range blobs {
222-
checkWrite(t, ctx, cs, dgst, p)
222+
checkWrite(ctx, t, cs, dgst, p)
223223
}
224224

225225
return blobs
@@ -282,7 +282,7 @@ func checkBlobPath(t *testing.T, cs content.Store, dgst digest.Digest) string {
282282
return path
283283
}
284284

285-
func checkWrite(t checker, ctx context.Context, cs content.Store, dgst digest.Digest, p []byte) digest.Digest {
285+
func checkWrite(ctx context.Context, t checker, cs content.Store, dgst digest.Digest, p []byte) digest.Digest {
286286
if err := content.WriteBlob(ctx, cs, dgst.String(), bytes.NewReader(p), int64(len(p)), dgst); err != nil {
287287
t.Fatal(err)
288288
}

dialer_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func dialer(address string, timeout time.Duration) (net.Conn, error) {
2424
return winio.DialPipe(address, &timeout)
2525
}
2626

27+
// DialAddress returns the dial address
2728
func DialAddress(address string) string {
2829
return address
2930
}

fs/diff_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestSimpleDiff(t *testing.T) {
3535
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
3636
fstest.Remove("/etc/unexpected"),
3737
)
38-
diff := []testChange{
38+
diff := []TestChange{
3939
Modify("/etc/hosts"),
4040
Modify("/etc/profile"),
4141
Delete("/etc/unexpected"),
@@ -60,7 +60,7 @@ func TestDirectoryReplace(t *testing.T) {
6060
fstest.RemoveAll("/dir1/f2"),
6161
fstest.CreateFile("/dir1/f2", []byte("Now file"), 0666),
6262
)
63-
diff := []testChange{
63+
diff := []TestChange{
6464
Add("/dir1/f11"),
6565
Modify("/dir1/f2"),
6666
}
@@ -79,7 +79,7 @@ func TestRemoveDirectoryTree(t *testing.T) {
7979
l2 := fstest.Apply(
8080
fstest.RemoveAll("/dir1"),
8181
)
82-
diff := []testChange{
82+
diff := []TestChange{
8383
Delete("/dir1"),
8484
}
8585

@@ -97,7 +97,7 @@ func TestFileReplace(t *testing.T) {
9797
fstest.CreateDir("/dir1/dir2", 0755),
9898
fstest.CreateFile("/dir1/dir2/f1", []byte("also a file"), 0644),
9999
)
100-
diff := []testChange{
100+
diff := []TestChange{
101101
Modify("/dir1"),
102102
Add("/dir1/dir2"),
103103
Add("/dir1/dir2/f1"),
@@ -136,7 +136,7 @@ func TestUpdateWithSameTime(t *testing.T) {
136136
fstest.CreateFile("/file-truncated-time-2", []byte("2"), 0644),
137137
fstest.Chtime("/file-truncated-time-2", tt),
138138
)
139-
diff := []testChange{
139+
diff := []TestChange{
140140
// "/file-same-time" excluded because matching non-zero nanosecond values
141141
Modify("/file-modified-time"),
142142
Modify("/file-truncated-time-1"),
@@ -148,7 +148,7 @@ func TestUpdateWithSameTime(t *testing.T) {
148148
}
149149
}
150150

151-
func testDiffWithBase(base, diff fstest.Applier, expected []testChange) error {
151+
func testDiffWithBase(base, diff fstest.Applier, expected []TestChange) error {
152152
t1, err := ioutil.TempDir("", "diff-with-base-lower-")
153153
if err != nil {
154154
return errors.Wrap(err, "failed to create temp dir")
@@ -188,7 +188,7 @@ func TestBaseDirectoryChanges(t *testing.T) {
188188
fstest.CreateDir("/root", 0700),
189189
fstest.CreateFile("/root/.bashrc", []byte("PATH=/usr/sbin:/usr/bin"), 0644),
190190
)
191-
changes := []testChange{
191+
changes := []TestChange{
192192
Add("/etc"),
193193
Add("/etc/hosts"),
194194
Add("/etc/profile"),
@@ -201,7 +201,7 @@ func TestBaseDirectoryChanges(t *testing.T) {
201201
}
202202
}
203203

204-
func testDiffWithoutBase(apply fstest.Applier, expected []testChange) error {
204+
func testDiffWithoutBase(apply fstest.Applier, expected []TestChange) error {
205205
tmp, err := ioutil.TempDir("", "diff-without-base-")
206206
if err != nil {
207207
return errors.Wrap(err, "failed to create temp dir")
@@ -220,7 +220,7 @@ func testDiffWithoutBase(apply fstest.Applier, expected []testChange) error {
220220
return checkChanges(tmp, changes, expected)
221221
}
222222

223-
func checkChanges(root string, changes, expected []testChange) error {
223+
func checkChanges(root string, changes, expected []TestChange) error {
224224
if len(changes) != len(expected) {
225225
return errors.Errorf("Unexpected number of changes:\n%s", diffString(changes, expected))
226226
}
@@ -253,20 +253,20 @@ func checkChanges(root string, changes, expected []testChange) error {
253253
return nil
254254
}
255255

256-
type testChange struct {
256+
type TestChange struct {
257257
Kind ChangeKind
258258
Path string
259259
FileInfo os.FileInfo
260260
Source string
261261
}
262262

263-
func collectChanges(a, b string) ([]testChange, error) {
264-
changes := []testChange{}
263+
func collectChanges(a, b string) ([]TestChange, error) {
264+
changes := []TestChange{}
265265
err := Changes(context.Background(), a, b, func(k ChangeKind, p string, f os.FileInfo, err error) error {
266266
if err != nil {
267267
return err
268268
}
269-
changes = append(changes, testChange{
269+
changes = append(changes, TestChange{
270270
Kind: k,
271271
Path: p,
272272
FileInfo: f,
@@ -281,35 +281,35 @@ func collectChanges(a, b string) ([]testChange, error) {
281281
return changes, nil
282282
}
283283

284-
func diffString(c1, c2 []testChange) string {
284+
func diffString(c1, c2 []TestChange) string {
285285
return fmt.Sprintf("got(%d):\n%s\nexpected(%d):\n%s", len(c1), changesString(c1), len(c2), changesString(c2))
286286

287287
}
288288

289-
func changesString(c []testChange) string {
289+
func changesString(c []TestChange) string {
290290
strs := make([]string, len(c))
291291
for i := range c {
292292
strs[i] = fmt.Sprintf("\t%s\t%s", c[i].Kind, c[i].Path)
293293
}
294294
return strings.Join(strs, "\n")
295295
}
296296

297-
func Add(p string) testChange {
298-
return testChange{
297+
func Add(p string) TestChange {
298+
return TestChange{
299299
Kind: ChangeKindAdd,
300300
Path: p,
301301
}
302302
}
303303

304-
func Delete(p string) testChange {
305-
return testChange{
304+
func Delete(p string) TestChange {
305+
return TestChange{
306306
Kind: ChangeKindDelete,
307307
Path: p,
308308
}
309309
}
310310

311-
func Modify(p string) testChange {
312-
return testChange{
311+
func Modify(p string) TestChange {
312+
return TestChange{
313313
Kind: ChangeKindModify,
314314
Path: p,
315315
}

fs/path_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/pkg/errors"
1313
)
1414

15-
type rootCheck struct {
15+
type RootCheck struct {
1616
unresolved string
1717
expected string
1818
scope func(string) string
@@ -23,7 +23,7 @@ func TestRootPath(t *testing.T) {
2323
tests := []struct {
2424
name string
2525
apply fstest.Applier
26-
checks []rootCheck
26+
checks []RootCheck
2727
scope func(string) (string, error)
2828
}{
2929
{
@@ -201,7 +201,7 @@ func testRootPathSymlinkEmpty(t *testing.T) {
201201
}
202202
}
203203

204-
func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []rootCheck) func(t *testing.T) {
204+
func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []RootCheck) func(t *testing.T) {
205205
return func(t *testing.T) {
206206
applyDir, err := ioutil.TempDir("", "test-root-path-")
207207
if err != nil {
@@ -242,17 +242,17 @@ func makeRootPathTest(t *testing.T, apply fstest.Applier, checks []rootCheck) fu
242242
}
243243
}
244244

245-
func Check(unresolved, expected string) []rootCheck {
246-
return []rootCheck{
245+
func Check(unresolved, expected string) []RootCheck {
246+
return []RootCheck{
247247
{
248248
unresolved: unresolved,
249249
expected: expected,
250250
},
251251
}
252252
}
253253

254-
func CheckWithScope(unresolved, expected, scope string) []rootCheck {
255-
return []rootCheck{
254+
func CheckWithScope(unresolved, expected, scope string) []RootCheck {
255+
return []RootCheck{
256256
{
257257
unresolved: unresolved,
258258
expected: expected,
@@ -263,8 +263,8 @@ func CheckWithScope(unresolved, expected, scope string) []rootCheck {
263263
}
264264
}
265265

266-
func ErrorWithScope(unresolved, scope string, cause error) []rootCheck {
267-
return []rootCheck{
266+
func ErrorWithScope(unresolved, scope string, cause error) []RootCheck {
267+
return []RootCheck{
268268
{
269269
unresolved: unresolved,
270270
cause: cause,
@@ -275,8 +275,8 @@ func ErrorWithScope(unresolved, scope string, cause error) []rootCheck {
275275
}
276276
}
277277

278-
func CheckAll(checks ...[]rootCheck) []rootCheck {
279-
all := make([]rootCheck, 0, len(checks))
278+
func CheckAll(checks ...[]RootCheck) []RootCheck {
279+
all := make([]RootCheck, 0, len(checks))
280280
for _, c := range checks {
281281
all = append(all, c...)
282282
}

gc/gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sync"
1111
)
1212

13-
// Resourcetype represents type of resource at a node
13+
// ResourceType represents type of resource at a node
1414
type ResourceType uint8
1515

1616
// Node presents a resource which has a type and key,

metadata/db.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func (m *DB) Update(fn func(*bolt.Tx) error) error {
190190
return m.db.Update(fn)
191191
}
192192

193+
// GarbageCollect starts garbage collection
193194
func (m *DB) GarbageCollect(ctx context.Context) error {
194195
lt1 := time.Now()
195196
m.wlock.Lock()

metadata/gc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ import (
1212
)
1313

1414
const (
15+
// ResourceUnknown specifies an unknown resource
1516
ResourceUnknown gc.ResourceType = iota
17+
// ResourceContent specifies a content resource
1618
ResourceContent
19+
// ResourceSnapshot specifies a snapshot resource
1720
ResourceSnapshot
21+
// ResourceContainer specifies a container resource
1822
ResourceContainer
23+
// ResourceTask specifies a task resource
1924
ResourceTask
2025
)
2126

mount/mount_windows.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ package mount
33
import "github.com/pkg/errors"
44

55
var (
6+
// ErrNotImplementOnWindows is returned when an action is not implemented for windows
67
ErrNotImplementOnWindows = errors.New("not implemented under windows")
78
)
89

10+
// Mount to the provided target
911
func (m *Mount) Mount(target string) error {
1012
return ErrNotImplementOnWindows
1113
}
1214

15+
// Unmount the mount at the provided path
1316
func Unmount(mount string, flags int) error {
1417
return ErrNotImplementOnWindows
1518
}
1619

20+
// UnmountAll mounts at the provided path
1721
func UnmountAll(mount string, flags int) error {
1822
return ErrNotImplementOnWindows
1923
}

0 commit comments

Comments
 (0)