Update gometalinter
Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -17,20 +17,13 @@ import ( |
| 17 | 17 |
|
| 18 | 18 |
// WriteLogStream writes an encoded byte stream of log messages from the |
| 19 | 19 |
// messages channel, multiplexing them with a stdcopy.Writer if mux is true |
| 20 |
-func WriteLogStream(ctx context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
|
|
| 20 |
+func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
|
|
| 21 | 21 |
wf := ioutils.NewWriteFlusher(w) |
| 22 | 22 |
defer wf.Close() |
| 23 | 23 |
|
| 24 | 24 |
wf.Flush() |
| 25 | 25 |
|
| 26 |
- // this might seem like doing below is clear: |
|
| 27 |
- // var outStream io.Writer = wf |
|
| 28 |
- // however, this GREATLY DISPLEASES golint, and if you do that, it will |
|
| 29 |
- // fail CI. we need outstream to be type writer because if we mux streams, |
|
| 30 |
- // we will need to reassign all of the streams to be stdwriters, which only |
|
| 31 |
- // conforms to the io.Writer interface. |
|
| 32 |
- var outStream io.Writer |
|
| 33 |
- outStream = wf |
|
| 26 |
+ outStream := io.Writer(wf) |
|
| 34 | 27 |
errStream := outStream |
| 35 | 28 |
sysErrStream := errStream |
| 36 | 29 |
if mux {
|
| ... | ... |
@@ -427,11 +427,7 @@ func (sr *swarmRouter) updateSecret(ctx context.Context, w http.ResponseWriter, |
| 427 | 427 |
} |
| 428 | 428 |
|
| 429 | 429 |
id := vars["id"] |
| 430 |
- if err := sr.backend.UpdateSecret(id, version, secret); err != nil {
|
|
| 431 |
- return err |
|
| 432 |
- } |
|
| 433 |
- |
|
| 434 |
- return nil |
|
| 430 |
+ return sr.backend.UpdateSecret(id, version, secret) |
|
| 435 | 431 |
} |
| 436 | 432 |
|
| 437 | 433 |
func (sr *swarmRouter) getConfigs(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
| ... | ... |
@@ -498,9 +494,5 @@ func (sr *swarmRouter) updateConfig(ctx context.Context, w http.ResponseWriter, |
| 498 | 498 |
} |
| 499 | 499 |
|
| 500 | 500 |
id := vars["id"] |
| 501 |
- if err := sr.backend.UpdateConfig(id, version, config); err != nil {
|
|
| 502 |
- return err |
|
| 503 |
- } |
|
| 504 |
- |
|
| 505 |
- return nil |
|
| 501 |
+ return sr.backend.UpdateConfig(id, version, config) |
|
| 506 | 502 |
} |
| ... | ... |
@@ -182,7 +182,7 @@ func TestArgsMatchKVList(t *testing.T) {
|
| 182 | 182 |
} |
| 183 | 183 |
|
| 184 | 184 |
for args, field := range matches {
|
| 185 |
- if args.MatchKVList(field, sources) != true {
|
|
| 185 |
+ if !args.MatchKVList(field, sources) {
|
|
| 186 | 186 |
t.Fatalf("Expected true for %v on %v, got false", sources, args)
|
| 187 | 187 |
} |
| 188 | 188 |
} |
| ... | ... |
@@ -202,7 +202,7 @@ func TestArgsMatchKVList(t *testing.T) {
|
| 202 | 202 |
} |
| 203 | 203 |
|
| 204 | 204 |
for args, field := range differs {
|
| 205 |
- if args.MatchKVList(field, sources) != false {
|
|
| 205 |
+ if args.MatchKVList(field, sources) {
|
|
| 206 | 206 |
t.Fatalf("Expected false for %v on %v, got true", sources, args)
|
| 207 | 207 |
} |
| 208 | 208 |
} |
| ... | ... |
@@ -29,10 +29,8 @@ func GetTimestamp(value string, reference time.Time) (string, error) {
|
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 | 31 |
var format string |
| 32 |
- var parseInLocation bool |
|
| 33 |
- |
|
| 34 | 32 |
// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation |
| 35 |
- parseInLocation = !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3) |
|
| 33 |
+ parseInLocation := !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3) |
|
| 36 | 34 |
|
| 37 | 35 |
if strings.Contains(value, ".") {
|
| 38 | 36 |
if parseInLocation {
|
| ... | ... |
@@ -34,10 +34,10 @@ func TestBuilderFlags(t *testing.T) {
|
| 34 | 34 |
t.Fatalf("Test3 of %q was supposed to work: %s", bf.Args, err)
|
| 35 | 35 |
} |
| 36 | 36 |
|
| 37 |
- if flStr1.IsUsed() == true {
|
|
| 37 |
+ if flStr1.IsUsed() {
|
|
| 38 | 38 |
t.Fatal("Test3 - str1 was not used!")
|
| 39 | 39 |
} |
| 40 |
- if flBool1.IsUsed() == true {
|
|
| 40 |
+ if flBool1.IsUsed() {
|
|
| 41 | 41 |
t.Fatal("Test3 - bool1 was not used!")
|
| 42 | 42 |
} |
| 43 | 43 |
|
| ... | ... |
@@ -58,10 +58,10 @@ func TestBuilderFlags(t *testing.T) {
|
| 58 | 58 |
if flBool1.IsTrue() {
|
| 59 | 59 |
t.Fatal("Bool1 was supposed to default to: false")
|
| 60 | 60 |
} |
| 61 |
- if flStr1.IsUsed() == true {
|
|
| 61 |
+ if flStr1.IsUsed() {
|
|
| 62 | 62 |
t.Fatal("Str1 was not used!")
|
| 63 | 63 |
} |
| 64 |
- if flBool1.IsUsed() == true {
|
|
| 64 |
+ if flBool1.IsUsed() {
|
|
| 65 | 65 |
t.Fatal("Bool1 was not used!")
|
| 66 | 66 |
} |
| 67 | 67 |
|
| ... | ... |
@@ -206,10 +206,7 @@ func lookupUser(userStr, filepath string) (int, error) {
|
| 206 | 206 |
return uid, nil |
| 207 | 207 |
} |
| 208 | 208 |
users, err := lcUser.ParsePasswdFileFilter(filepath, func(u lcUser.User) bool {
|
| 209 |
- if u.Name == userStr {
|
|
| 210 |
- return true |
|
| 211 |
- } |
|
| 212 |
- return false |
|
| 209 |
+ return u.Name == userStr |
|
| 213 | 210 |
}) |
| 214 | 211 |
if err != nil {
|
| 215 | 212 |
return 0, err |
| ... | ... |
@@ -228,10 +225,7 @@ func lookupGroup(groupStr, filepath string) (int, error) {
|
| 228 | 228 |
return gid, nil |
| 229 | 229 |
} |
| 230 | 230 |
groups, err := lcUser.ParseGroupFileFilter(filepath, func(g lcUser.Group) bool {
|
| 231 |
- if g.Name == groupStr {
|
|
| 232 |
- return true |
|
| 233 |
- } |
|
| 234 |
- return false |
|
| 231 |
+ return g.Name == groupStr |
|
| 235 | 232 |
}) |
| 236 | 233 |
if err != nil {
|
| 237 | 234 |
return 0, err |
| ... | ... |
@@ -143,7 +143,7 @@ func (d *Directive) possibleParserDirective(line string) error {
|
| 143 | 143 |
if len(tecMatch) != 0 {
|
| 144 | 144 |
for i, n := range tokenEscapeCommand.SubexpNames() {
|
| 145 | 145 |
if n == "escapechar" {
|
| 146 |
- if d.escapeSeen == true {
|
|
| 146 |
+ if d.escapeSeen {
|
|
| 147 | 147 |
return errors.New("only one escape parser directive can be used")
|
| 148 | 148 |
} |
| 149 | 149 |
d.escapeSeen = true |
| ... | ... |
@@ -159,7 +159,7 @@ func (d *Directive) possibleParserDirective(line string) error {
|
| 159 | 159 |
if len(tpcMatch) != 0 {
|
| 160 | 160 |
for i, n := range tokenPlatformCommand.SubexpNames() {
|
| 161 | 161 |
if n == "platform" {
|
| 162 |
- if d.platformSeen == true {
|
|
| 162 |
+ if d.platformSeen {
|
|
| 163 | 163 |
return errors.New("only one platform parser directive can be used")
|
| 164 | 164 |
} |
| 165 | 165 |
d.platformSeen = true |
| ... | ... |
@@ -21,7 +21,7 @@ const ( |
| 21 | 21 |
const shouldStayFilename = "should_stay" |
| 22 | 22 |
|
| 23 | 23 |
func extractFilenames(files []os.FileInfo) []string {
|
| 24 |
- filenames := make([]string, len(files), len(files)) |
|
| 24 |
+ filenames := make([]string, len(files)) |
|
| 25 | 25 |
|
| 26 | 26 |
for i, file := range files {
|
| 27 | 27 |
filenames[i] = file.Name() |
| ... | ... |
@@ -116,7 +116,7 @@ func inspectResponse(ct string, r io.Reader, clen int64) (string, io.ReadCloser, |
| 116 | 116 |
plen = maxPreambleLength |
| 117 | 117 |
} |
| 118 | 118 |
|
| 119 |
- preamble := make([]byte, plen, plen) |
|
| 119 |
+ preamble := make([]byte, plen) |
|
| 120 | 120 |
rlen, err := r.Read(preamble) |
| 121 | 121 |
if rlen == 0 {
|
| 122 | 122 |
return ct, ioutil.NopCloser(r), errors.New("empty response")
|
| ... | ... |
@@ -70,7 +70,7 @@ func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Con |
| 70 | 70 |
timeout := dialer.Timeout |
| 71 | 71 |
|
| 72 | 72 |
if !dialer.Deadline.IsZero() {
|
| 73 |
- deadlineTimeout := dialer.Deadline.Sub(time.Now()) |
|
| 73 |
+ deadlineTimeout := time.Until(dialer.Deadline) |
|
| 74 | 74 |
if timeout == 0 || deadlineTimeout < timeout {
|
| 75 | 75 |
timeout = deadlineTimeout |
| 76 | 76 |
} |
| ... | ... |
@@ -467,7 +467,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
|
| 467 | 467 |
return nil, err |
| 468 | 468 |
} |
| 469 | 469 |
|
| 470 |
- if conf.V2Only == false {
|
|
| 470 |
+ if !conf.V2Only {
|
|
| 471 | 471 |
logrus.Warnf(`The "disable-legacy-registry" option is deprecated and wil be removed in Docker v17.12. Interacting with legacy (v1) registries will no longer be supported in Docker v17.12"`) |
| 472 | 472 |
} |
| 473 | 473 |
|
| ... | ... |
@@ -203,10 +203,7 @@ func (db *memDB) ReserveName(name, containerID string) error {
|
| 203 | 203 |
// Once released, a name can be reserved again |
| 204 | 204 |
func (db *memDB) ReleaseName(name string) error {
|
| 205 | 205 |
return db.withTxn(func(txn *memdb.Txn) error {
|
| 206 |
- if err := txn.Delete(memdbNamesTable, nameAssociation{name: name}); err != nil {
|
|
| 207 |
- return err |
|
| 208 |
- } |
|
| 209 |
- return nil |
|
| 206 |
+ return txn.Delete(memdbNamesTable, nameAssociation{name: name})
|
|
| 210 | 207 |
}) |
| 211 | 208 |
} |
| 212 | 209 |
|
| ... | ... |
@@ -90,14 +90,12 @@ func main() {
|
| 90 | 90 |
fmt.Printf("Sector size: %d\n", status.SectorSize)
|
| 91 | 91 |
fmt.Printf("Data use: %d of %d (%.1f %%)\n", status.Data.Used, status.Data.Total, 100.0*float64(status.Data.Used)/float64(status.Data.Total))
|
| 92 | 92 |
fmt.Printf("Metadata use: %d of %d (%.1f %%)\n", status.Metadata.Used, status.Metadata.Total, 100.0*float64(status.Metadata.Used)/float64(status.Metadata.Total))
|
| 93 |
- break |
|
| 94 | 93 |
case "list": |
| 95 | 94 |
ids := devices.List() |
| 96 | 95 |
sort.Strings(ids) |
| 97 | 96 |
for _, id := range ids {
|
| 98 | 97 |
fmt.Println(id) |
| 99 | 98 |
} |
| 100 |
- break |
|
| 101 | 99 |
case "device": |
| 102 | 100 |
if flag.NArg() < 2 {
|
| 103 | 101 |
usage() |
| ... | ... |
@@ -113,7 +111,6 @@ func main() {
|
| 113 | 113 |
fmt.Printf("Size in Sectors: %d\n", status.SizeInSectors)
|
| 114 | 114 |
fmt.Printf("Mapped Sectors: %d\n", status.MappedSectors)
|
| 115 | 115 |
fmt.Printf("Highest Mapped Sector: %d\n", status.HighestMappedSector)
|
| 116 |
- break |
|
| 117 | 116 |
case "resize": |
| 118 | 117 |
if flag.NArg() < 2 {
|
| 119 | 118 |
usage() |
| ... | ... |
@@ -131,7 +128,6 @@ func main() {
|
| 131 | 131 |
os.Exit(1) |
| 132 | 132 |
} |
| 133 | 133 |
|
| 134 |
- break |
|
| 135 | 134 |
case "snap": |
| 136 | 135 |
if flag.NArg() < 3 {
|
| 137 | 136 |
usage() |
| ... | ... |
@@ -142,7 +138,6 @@ func main() {
|
| 142 | 142 |
fmt.Println("Can't create snap device: ", err)
|
| 143 | 143 |
os.Exit(1) |
| 144 | 144 |
} |
| 145 |
- break |
|
| 146 | 145 |
case "remove": |
| 147 | 146 |
if flag.NArg() < 2 {
|
| 148 | 147 |
usage() |
| ... | ... |
@@ -153,7 +148,6 @@ func main() {
|
| 153 | 153 |
fmt.Println("Can't remove device: ", err)
|
| 154 | 154 |
os.Exit(1) |
| 155 | 155 |
} |
| 156 |
- break |
|
| 157 | 156 |
case "mount": |
| 158 | 157 |
if flag.NArg() < 3 {
|
| 159 | 158 |
usage() |
| ... | ... |
@@ -164,13 +158,10 @@ func main() {
|
| 164 | 164 |
fmt.Println("Can't mount device: ", err)
|
| 165 | 165 |
os.Exit(1) |
| 166 | 166 |
} |
| 167 |
- break |
|
| 168 | 167 |
default: |
| 169 | 168 |
fmt.Printf("Unknown command %s\n", args[0])
|
| 170 | 169 |
usage() |
| 171 | 170 |
|
| 172 | 171 |
os.Exit(1) |
| 173 | 172 |
} |
| 174 |
- |
|
| 175 |
- return |
|
| 176 | 173 |
} |
| ... | ... |
@@ -40,11 +40,7 @@ func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) er |
| 40 | 40 |
|
| 41 | 41 |
func (nc *networkAttacherController) Prepare(ctx context.Context) error {
|
| 42 | 42 |
// Make sure all the networks that the task needs are created. |
| 43 |
- if err := nc.adapter.createNetworks(ctx); err != nil {
|
|
| 44 |
- return err |
|
| 45 |
- } |
|
| 46 |
- |
|
| 47 |
- return nil |
|
| 43 |
+ return nc.adapter.createNetworks(ctx) |
|
| 48 | 44 |
} |
| 49 | 45 |
|
| 50 | 46 |
func (nc *networkAttacherController) Start(ctx context.Context) error {
|
| ... | ... |
@@ -69,11 +65,7 @@ func (nc *networkAttacherController) Terminate(ctx context.Context) error {
|
| 69 | 69 |
func (nc *networkAttacherController) Remove(ctx context.Context) error {
|
| 70 | 70 |
// Try removing the network referenced in this task in case this |
| 71 | 71 |
// task is the last one referencing it |
| 72 |
- if err := nc.adapter.removeNetworks(ctx); err != nil {
|
|
| 73 |
- return err |
|
| 74 |
- } |
|
| 75 |
- |
|
| 76 |
- return nil |
|
| 72 |
+ return nc.adapter.removeNetworks(ctx) |
|
| 77 | 73 |
} |
| 78 | 74 |
|
| 79 | 75 |
func (nc *networkAttacherController) Close() error {
|
| ... | ... |
@@ -6,7 +6,7 @@ import ( |
| 6 | 6 |
"testing" |
| 7 | 7 |
|
| 8 | 8 |
"github.com/docker/docker/opts" |
| 9 |
- "github.com/docker/go-units" |
|
| 9 |
+ units "github.com/docker/go-units" |
|
| 10 | 10 |
"github.com/gotestyourself/gotestyourself/fs" |
| 11 | 11 |
"github.com/spf13/pflag" |
| 12 | 12 |
"github.com/stretchr/testify/assert" |
| ... | ... |
@@ -14,7 +14,7 @@ import ( |
| 14 | 14 |
) |
| 15 | 15 |
|
| 16 | 16 |
func TestGetConflictFreeConfiguration(t *testing.T) {
|
| 17 |
- configFileData := string([]byte(` |
|
| 17 |
+ configFileData := ` |
|
| 18 | 18 |
{
|
| 19 | 19 |
"debug": true, |
| 20 | 20 |
"default-ulimits": {
|
| ... | ... |
@@ -27,7 +27,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) {
|
| 27 | 27 |
"log-opts": {
|
| 28 | 28 |
"tag": "test_tag" |
| 29 | 29 |
} |
| 30 |
- }`)) |
|
| 30 |
+ }` |
|
| 31 | 31 |
|
| 32 | 32 |
file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData)) |
| 33 | 33 |
defer file.Remove() |
| ... | ... |
@@ -55,7 +55,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) {
|
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
func TestDaemonConfigurationMerge(t *testing.T) {
|
| 58 |
- configFileData := string([]byte(` |
|
| 58 |
+ configFileData := ` |
|
| 59 | 59 |
{
|
| 60 | 60 |
"debug": true, |
| 61 | 61 |
"default-ulimits": {
|
| ... | ... |
@@ -68,7 +68,7 @@ func TestDaemonConfigurationMerge(t *testing.T) {
|
| 68 | 68 |
"log-opts": {
|
| 69 | 69 |
"tag": "test_tag" |
| 70 | 70 |
} |
| 71 |
- }`)) |
|
| 71 |
+ }` |
|
| 72 | 72 |
|
| 73 | 73 |
file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData)) |
| 74 | 74 |
defer file.Remove() |
| ... | ... |
@@ -115,10 +115,7 @@ func TestDaemonConfigurationMerge(t *testing.T) {
|
| 115 | 115 |
} |
| 116 | 116 |
|
| 117 | 117 |
func TestDaemonConfigurationMergeShmSize(t *testing.T) {
|
| 118 |
- data := string([]byte(` |
|
| 119 |
- {
|
|
| 120 |
- "default-shm-size": "1g" |
|
| 121 |
- }`)) |
|
| 118 |
+ data := `{"default-shm-size": "1g"}`
|
|
| 122 | 119 |
|
| 123 | 120 |
file := fs.NewFile(t, "docker-config", fs.WithContent(data)) |
| 124 | 121 |
defer file.Remove() |
| ... | ... |
@@ -133,7 +130,5 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) {
|
| 133 | 133 |
require.NoError(t, err) |
| 134 | 134 |
|
| 135 | 135 |
expectedValue := 1 * 1024 * 1024 * 1024 |
| 136 |
- if cc.ShmSize.Value() != int64(expectedValue) {
|
|
| 137 |
- t.Fatalf("expected default shm size %d, got %d", expectedValue, cc.ShmSize.Value())
|
|
| 138 |
- } |
|
| 136 |
+ assert.Equal(t, int64(expectedValue), cc.ShmSize.Value()) |
|
| 139 | 137 |
} |
| ... | ... |
@@ -75,7 +75,7 @@ type Store struct {
|
| 75 | 75 |
|
| 76 | 76 |
// NewStore initializes a new exec store. |
| 77 | 77 |
func NewStore() *Store {
|
| 78 |
- return &Store{commands: make(map[string]*Config, 0)}
|
|
| 78 |
+ return &Store{commands: make(map[string]*Config)}
|
|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 | 81 |
// Commands returns the exec configurations in the store. |
| ... | ... |
@@ -18,6 +18,8 @@ import ( |
| 18 | 18 |
"github.com/docker/docker/pkg/archive" |
| 19 | 19 |
"github.com/docker/docker/pkg/reexec" |
| 20 | 20 |
"github.com/docker/docker/pkg/stringid" |
| 21 |
+ "github.com/stretchr/testify/assert" |
|
| 22 |
+ "github.com/stretchr/testify/require" |
|
| 21 | 23 |
) |
| 22 | 24 |
|
| 23 | 25 |
var ( |
| ... | ... |
@@ -179,9 +181,8 @@ func TestCleanupWithNoDirs(t *testing.T) {
|
| 179 | 179 |
d := newDriver(t) |
| 180 | 180 |
defer os.RemoveAll(tmp) |
| 181 | 181 |
|
| 182 |
- if err := d.Cleanup(); err != nil {
|
|
| 183 |
- t.Fatal(err) |
|
| 184 |
- } |
|
| 182 |
+ err := d.Cleanup() |
|
| 183 |
+ assert.NoError(t, err) |
|
| 185 | 184 |
} |
| 186 | 185 |
|
| 187 | 186 |
func TestCleanupWithDir(t *testing.T) {
|
| ... | ... |
@@ -201,18 +202,12 @@ func TestMountedFalseResponse(t *testing.T) {
|
| 201 | 201 |
d := newDriver(t) |
| 202 | 202 |
defer os.RemoveAll(tmp) |
| 203 | 203 |
|
| 204 |
- if err := d.Create("1", "", nil); err != nil {
|
|
| 205 |
- t.Fatal(err) |
|
| 206 |
- } |
|
| 204 |
+ err := d.Create("1", "", nil)
|
|
| 205 |
+ require.NoError(t, err) |
|
| 207 | 206 |
|
| 208 | 207 |
response, err := d.mounted(d.getDiffPath("1"))
|
| 209 |
- if err != nil {
|
|
| 210 |
- t.Fatal(err) |
|
| 211 |
- } |
|
| 212 |
- |
|
| 213 |
- if response != false {
|
|
| 214 |
- t.Fatal("Response if dir id 1 is mounted should be false")
|
|
| 215 |
- } |
|
| 208 |
+ require.NoError(t, err) |
|
| 209 |
+ assert.False(t, response) |
|
| 216 | 210 |
} |
| 217 | 211 |
|
| 218 | 212 |
func TestMountedTrueResponse(t *testing.T) {
|
| ... | ... |
@@ -220,26 +215,17 @@ func TestMountedTrueResponse(t *testing.T) {
|
| 220 | 220 |
defer os.RemoveAll(tmp) |
| 221 | 221 |
defer d.Cleanup() |
| 222 | 222 |
|
| 223 |
- if err := d.Create("1", "", nil); err != nil {
|
|
| 224 |
- t.Fatal(err) |
|
| 225 |
- } |
|
| 226 |
- if err := d.Create("2", "1", nil); err != nil {
|
|
| 227 |
- t.Fatal(err) |
|
| 228 |
- } |
|
| 223 |
+ err := d.Create("1", "", nil)
|
|
| 224 |
+ require.NoError(t, err) |
|
| 225 |
+ err = d.Create("2", "1", nil)
|
|
| 226 |
+ require.NoError(t, err) |
|
| 229 | 227 |
|
| 230 |
- _, err := d.Get("2", "")
|
|
| 231 |
- if err != nil {
|
|
| 232 |
- t.Fatal(err) |
|
| 233 |
- } |
|
| 228 |
+ _, err = d.Get("2", "")
|
|
| 229 |
+ require.NoError(t, err) |
|
| 234 | 230 |
|
| 235 | 231 |
response, err := d.mounted(d.pathCache["2"]) |
| 236 |
- if err != nil {
|
|
| 237 |
- t.Fatal(err) |
|
| 238 |
- } |
|
| 239 |
- |
|
| 240 |
- if response != true {
|
|
| 241 |
- t.Fatal("Response if dir id 2 is mounted should be true")
|
|
| 242 |
- } |
|
| 232 |
+ require.NoError(t, err) |
|
| 233 |
+ assert.True(t, response) |
|
| 243 | 234 |
} |
| 244 | 235 |
|
| 245 | 236 |
func TestMountWithParent(t *testing.T) {
|
| ... | ... |
@@ -574,9 +560,8 @@ func TestStatus(t *testing.T) {
|
| 574 | 574 |
} |
| 575 | 575 |
|
| 576 | 576 |
status := d.Status() |
| 577 |
- if status == nil || len(status) == 0 {
|
|
| 578 |
- t.Fatal("Status should not be nil or empty")
|
|
| 579 |
- } |
|
| 577 |
+ assert.Len(t, status, 4) |
|
| 578 |
+ |
|
| 580 | 579 |
rootDir := status[0] |
| 581 | 580 |
dirs := status[2] |
| 582 | 581 |
if rootDir[0] != "Root Dir" {
|
| ... | ... |
@@ -677,27 +662,19 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
|
| 677 | 677 |
} |
| 678 | 678 |
current = hash(current) |
| 679 | 679 |
|
| 680 |
- if err := d.CreateReadWrite(current, parent, nil); err != nil {
|
|
| 681 |
- t.Logf("Current layer %d", i)
|
|
| 682 |
- t.Error(err) |
|
| 683 |
- } |
|
| 680 |
+ err := d.CreateReadWrite(current, parent, nil) |
|
| 681 |
+ require.NoError(t, err, "current layer %d", i) |
|
| 682 |
+ |
|
| 684 | 683 |
point, err := d.Get(current, "") |
| 685 |
- if err != nil {
|
|
| 686 |
- t.Logf("Current layer %d", i)
|
|
| 687 |
- t.Error(err) |
|
| 688 |
- } |
|
| 684 |
+ require.NoError(t, err, "current layer %d", i) |
|
| 685 |
+ |
|
| 689 | 686 |
f, err := os.Create(path.Join(point, current)) |
| 690 |
- if err != nil {
|
|
| 691 |
- t.Logf("Current layer %d", i)
|
|
| 692 |
- t.Error(err) |
|
| 693 |
- } |
|
| 687 |
+ require.NoError(t, err, "current layer %d", i) |
|
| 694 | 688 |
f.Close() |
| 695 | 689 |
|
| 696 | 690 |
if i%10 == 0 {
|
| 697 |
- if err := os.Remove(path.Join(point, parent)); err != nil {
|
|
| 698 |
- t.Logf("Current layer %d", i)
|
|
| 699 |
- t.Error(err) |
|
| 700 |
- } |
|
| 691 |
+ err := os.Remove(path.Join(point, parent)) |
|
| 692 |
+ require.NoError(t, err, "current layer %d", i) |
|
| 701 | 693 |
expected-- |
| 702 | 694 |
} |
| 703 | 695 |
last = current |
| ... | ... |
@@ -705,20 +682,14 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
|
| 705 | 705 |
|
| 706 | 706 |
// Perform the actual mount for the top most image |
| 707 | 707 |
point, err := d.Get(last, "") |
| 708 |
- if err != nil {
|
|
| 709 |
- t.Error(err) |
|
| 710 |
- } |
|
| 708 |
+ require.NoError(t, err) |
|
| 711 | 709 |
files, err := ioutil.ReadDir(point) |
| 712 |
- if err != nil {
|
|
| 713 |
- t.Error(err) |
|
| 714 |
- } |
|
| 715 |
- if len(files) != expected {
|
|
| 716 |
- t.Errorf("Expected %d got %d", expected, len(files))
|
|
| 717 |
- } |
|
| 710 |
+ require.NoError(t, err) |
|
| 711 |
+ assert.Len(t, files, expected) |
|
| 718 | 712 |
} |
| 719 | 713 |
|
| 720 | 714 |
func TestMountMoreThan42Layers(t *testing.T) {
|
| 721 |
- os.RemoveAll(tmpOuter) |
|
| 715 |
+ defer os.RemoveAll(tmpOuter) |
|
| 722 | 716 |
testMountMoreThan42Layers(t, tmp) |
| 723 | 717 |
} |
| 724 | 718 |
|
| ... | ... |
@@ -1254,14 +1254,13 @@ func (devices *DeviceSet) setupBaseImage() error {
|
| 1254 | 1254 |
} |
| 1255 | 1255 |
|
| 1256 | 1256 |
func setCloseOnExec(name string) {
|
| 1257 |
- if fileInfos, _ := ioutil.ReadDir("/proc/self/fd"); fileInfos != nil {
|
|
| 1258 |
- for _, i := range fileInfos {
|
|
| 1259 |
- link, _ := os.Readlink(filepath.Join("/proc/self/fd", i.Name()))
|
|
| 1260 |
- if link == name {
|
|
| 1261 |
- fd, err := strconv.Atoi(i.Name()) |
|
| 1262 |
- if err == nil {
|
|
| 1263 |
- unix.CloseOnExec(fd) |
|
| 1264 |
- } |
|
| 1257 |
+ fileInfos, _ := ioutil.ReadDir("/proc/self/fd")
|
|
| 1258 |
+ for _, i := range fileInfos {
|
|
| 1259 |
+ link, _ := os.Readlink(filepath.Join("/proc/self/fd", i.Name()))
|
|
| 1260 |
+ if link == name {
|
|
| 1261 |
+ fd, err := strconv.Atoi(i.Name()) |
|
| 1262 |
+ if err == nil {
|
|
| 1263 |
+ unix.CloseOnExec(fd) |
|
| 1265 | 1264 |
} |
| 1266 | 1265 |
} |
| 1267 | 1266 |
} |
| ... | ... |
@@ -69,18 +69,18 @@ func (d *Driver) Status() [][2]string {
|
| 69 | 69 |
|
| 70 | 70 |
status := [][2]string{
|
| 71 | 71 |
{"Pool Name", s.PoolName},
|
| 72 |
- {"Pool Blocksize", fmt.Sprintf("%s", units.HumanSize(float64(s.SectorSize)))},
|
|
| 73 |
- {"Base Device Size", fmt.Sprintf("%s", units.HumanSize(float64(s.BaseDeviceSize)))},
|
|
| 72 |
+ {"Pool Blocksize", units.HumanSize(float64(s.SectorSize))},
|
|
| 73 |
+ {"Base Device Size", units.HumanSize(float64(s.BaseDeviceSize))},
|
|
| 74 | 74 |
{"Backing Filesystem", s.BaseDeviceFS},
|
| 75 | 75 |
{"Data file", s.DataFile},
|
| 76 | 76 |
{"Metadata file", s.MetadataFile},
|
| 77 |
- {"Data Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Used)))},
|
|
| 78 |
- {"Data Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Total)))},
|
|
| 79 |
- {"Data Space Available", fmt.Sprintf("%s", units.HumanSize(float64(s.Data.Available)))},
|
|
| 80 |
- {"Metadata Space Used", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Used)))},
|
|
| 81 |
- {"Metadata Space Total", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Total)))},
|
|
| 82 |
- {"Metadata Space Available", fmt.Sprintf("%s", units.HumanSize(float64(s.Metadata.Available)))},
|
|
| 83 |
- {"Thin Pool Minimum Free Space", fmt.Sprintf("%s", units.HumanSize(float64(s.MinFreeSpace)))},
|
|
| 77 |
+ {"Data Space Used", units.HumanSize(float64(s.Data.Used))},
|
|
| 78 |
+ {"Data Space Total", units.HumanSize(float64(s.Data.Total))},
|
|
| 79 |
+ {"Data Space Available", units.HumanSize(float64(s.Data.Available))},
|
|
| 80 |
+ {"Metadata Space Used", units.HumanSize(float64(s.Metadata.Used))},
|
|
| 81 |
+ {"Metadata Space Total", units.HumanSize(float64(s.Metadata.Total))},
|
|
| 82 |
+ {"Metadata Space Available", units.HumanSize(float64(s.Metadata.Available))},
|
|
| 83 |
+ {"Thin Pool Minimum Free Space", units.HumanSize(float64(s.MinFreeSpace))},
|
|
| 84 | 84 |
{"Udev Sync Supported", fmt.Sprintf("%v", s.UdevSyncSupported)},
|
| 85 | 85 |
{"Deferred Removal Enabled", fmt.Sprintf("%v", s.DeferredRemoveEnabled)},
|
| 86 | 86 |
{"Deferred Deletion Enabled", fmt.Sprintf("%v", s.DeferredDeleteEnabled)},
|
| ... | ... |
@@ -159,13 +159,7 @@ func (d *Driver) Remove(id string) error {
|
| 159 | 159 |
if err := d.DeviceSet.DeleteDevice(id, false); err != nil {
|
| 160 | 160 |
return fmt.Errorf("failed to remove device %s: %v", id, err)
|
| 161 | 161 |
} |
| 162 |
- |
|
| 163 |
- mp := path.Join(d.home, "mnt", id) |
|
| 164 |
- if err := system.EnsureRemoveAll(mp); err != nil {
|
|
| 165 |
- return err |
|
| 166 |
- } |
|
| 167 |
- |
|
| 168 |
- return nil |
|
| 162 |
+ return system.EnsureRemoveAll(path.Join(d.home, "mnt", id)) |
|
| 169 | 163 |
} |
| 170 | 164 |
|
| 171 | 165 |
// Get mounts a device with given id into the root filesystem |
| ... | ... |
@@ -94,7 +94,7 @@ func (gdw *NaiveDiffDriver) Diff(id, parent string) (arch io.ReadCloser, err err |
| 94 | 94 |
// are extracted from tar's with full second precision on modified time. |
| 95 | 95 |
// We need this hack here to make sure calls within same second receive |
| 96 | 96 |
// correct result. |
| 97 |
- time.Sleep(startTime.Truncate(time.Second).Add(time.Second).Sub(time.Now())) |
|
| 97 |
+ time.Sleep(time.Until(startTime.Truncate(time.Second).Add(time.Second))) |
|
| 98 | 98 |
return err |
| 99 | 99 |
}), nil |
| 100 | 100 |
} |
| ... | ... |
@@ -3,13 +3,13 @@ |
| 3 | 3 |
package graphtest |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
- "bytes" |
|
| 7 | 6 |
"io" |
| 8 | 7 |
"io/ioutil" |
| 9 | 8 |
"path/filepath" |
| 10 | 9 |
"testing" |
| 11 | 10 |
|
| 12 | 11 |
"github.com/docker/docker/pkg/stringid" |
| 12 |
+ "github.com/stretchr/testify/require" |
|
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
// DriverBenchExists benchmarks calls to exist |
| ... | ... |
@@ -251,9 +251,7 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d |
| 251 | 251 |
} |
| 252 | 252 |
|
| 253 | 253 |
b.StopTimer() |
| 254 |
- if bytes.Compare(c, content) != 0 {
|
|
| 255 |
- b.Fatalf("Wrong content in file %v, expected %v", c, content)
|
|
| 256 |
- } |
|
| 254 |
+ require.Equal(b, content, c) |
|
| 257 | 255 |
b.StartTimer() |
| 258 | 256 |
} |
| 259 | 257 |
} |
| ... | ... |
@@ -269,10 +269,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr |
| 269 | 269 |
|
| 270 | 270 |
// Toplevel images are just a "root" dir |
| 271 | 271 |
if parent == "" {
|
| 272 |
- if err := idtools.MkdirAs(path.Join(dir, "root"), 0755, rootUID, rootGID); err != nil {
|
|
| 273 |
- return err |
|
| 274 |
- } |
|
| 275 |
- return nil |
|
| 272 |
+ return idtools.MkdirAndChown(path.Join(dir, "root"), 0755, idtools.IDPair{rootUID, rootGID})
|
|
| 276 | 273 |
} |
| 277 | 274 |
|
| 278 | 275 |
parentDir := d.dir(parent) |
| ... | ... |
@@ -103,10 +103,7 @@ func (d *Driver) dir(id string) string {
|
| 103 | 103 |
|
| 104 | 104 |
// Remove deletes the content from the directory for a given id. |
| 105 | 105 |
func (d *Driver) Remove(id string) error {
|
| 106 |
- if err := system.EnsureRemoveAll(d.dir(id)); err != nil {
|
|
| 107 |
- return err |
|
| 108 |
- } |
|
| 109 |
- return nil |
|
| 106 |
+ return system.EnsureRemoveAll(d.dir(id)) |
|
| 110 | 107 |
} |
| 111 | 108 |
|
| 112 | 109 |
// Get returns the directory for the given id. |
| ... | ... |
@@ -301,12 +301,10 @@ func (daemon *Daemon) SquashImage(id, parent string) (string, error) {
|
| 301 | 301 |
} |
| 302 | 302 |
defer daemon.stores[img.Platform()].layerStore.Release(newL) |
| 303 | 303 |
|
| 304 |
- var newImage image.Image |
|
| 305 |
- newImage = *img |
|
| 304 |
+ newImage := *img |
|
| 306 | 305 |
newImage.RootFS = nil |
| 307 | 306 |
|
| 308 |
- var rootFS image.RootFS |
|
| 309 |
- rootFS = *parentImg.RootFS |
|
| 307 |
+ rootFS := *parentImg.RootFS |
|
| 310 | 308 |
rootFS.DiffIDs = append(rootFS.DiffIDs, newL.DiffID()) |
| 311 | 309 |
newImage.RootFS = &rootFS |
| 312 | 310 |
|
| ... | ... |
@@ -137,8 +137,7 @@ func newSectionReader(f *os.File) (*io.SectionReader, error) {
|
| 137 | 137 |
} |
| 138 | 138 |
|
| 139 | 139 |
func tailFile(f io.ReadSeeker, logWatcher *logger.LogWatcher, tail int, since time.Time) {
|
| 140 |
- var rdr io.Reader |
|
| 141 |
- rdr = f |
|
| 140 |
+ rdr := io.Reader(f) |
|
| 142 | 141 |
if tail > 0 {
|
| 143 | 142 |
ls, err := tailfile.TailFile(f, tail) |
| 144 | 143 |
if err != nil {
|
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"time" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/daemon/logger" |
| 11 |
+ "github.com/stretchr/testify/require" |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 13 | 14 |
// Validate options |
| ... | ... |
@@ -125,7 +126,7 @@ func TestDefault(t *testing.T) {
|
| 125 | 125 |
splunkLoggerDriver.nullMessage.Source != "" || |
| 126 | 126 |
splunkLoggerDriver.nullMessage.SourceType != "" || |
| 127 | 127 |
splunkLoggerDriver.nullMessage.Index != "" || |
| 128 |
- splunkLoggerDriver.gzipCompression != false || |
|
| 128 |
+ splunkLoggerDriver.gzipCompression || |
|
| 129 | 129 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 130 | 130 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| 131 | 131 |
splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || |
| ... | ... |
@@ -255,7 +256,7 @@ func TestInlineFormatWithNonDefaultOptions(t *testing.T) {
|
| 255 | 255 |
splunkLoggerDriver.nullMessage.Source != "mysource" || |
| 256 | 256 |
splunkLoggerDriver.nullMessage.SourceType != "mysourcetype" || |
| 257 | 257 |
splunkLoggerDriver.nullMessage.Index != "myindex" || |
| 258 |
- splunkLoggerDriver.gzipCompression != true || |
|
| 258 |
+ !splunkLoggerDriver.gzipCompression || |
|
| 259 | 259 |
splunkLoggerDriver.gzipCompressionLevel != gzip.DefaultCompression || |
| 260 | 260 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 261 | 261 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| ... | ... |
@@ -355,7 +356,7 @@ func TestJsonFormat(t *testing.T) {
|
| 355 | 355 |
splunkLoggerDriver.nullMessage.Source != "" || |
| 356 | 356 |
splunkLoggerDriver.nullMessage.SourceType != "" || |
| 357 | 357 |
splunkLoggerDriver.nullMessage.Index != "" || |
| 358 |
- splunkLoggerDriver.gzipCompression != true || |
|
| 358 |
+ !splunkLoggerDriver.gzipCompression || |
|
| 359 | 359 |
splunkLoggerDriver.gzipCompressionLevel != gzip.BestSpeed || |
| 360 | 360 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 361 | 361 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| ... | ... |
@@ -448,14 +449,10 @@ func TestRawFormat(t *testing.T) {
|
| 448 | 448 |
} |
| 449 | 449 |
|
| 450 | 450 |
hostname, err := info.Hostname() |
| 451 |
- if err != nil {
|
|
| 452 |
- t.Fatal(err) |
|
| 453 |
- } |
|
| 451 |
+ require.NoError(t, err) |
|
| 454 | 452 |
|
| 455 | 453 |
loggerDriver, err := New(info) |
| 456 |
- if err != nil {
|
|
| 457 |
- t.Fatal(err) |
|
| 458 |
- } |
|
| 454 |
+ require.NoError(t, err) |
|
| 459 | 455 |
|
| 460 | 456 |
if !hec.connectionVerified {
|
| 461 | 457 |
t.Fatal("By default connection should be verified")
|
| ... | ... |
@@ -472,7 +469,7 @@ func TestRawFormat(t *testing.T) {
|
| 472 | 472 |
splunkLoggerDriver.nullMessage.Source != "" || |
| 473 | 473 |
splunkLoggerDriver.nullMessage.SourceType != "" || |
| 474 | 474 |
splunkLoggerDriver.nullMessage.Index != "" || |
| 475 |
- splunkLoggerDriver.gzipCompression != false || |
|
| 475 |
+ splunkLoggerDriver.gzipCompression || |
|
| 476 | 476 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 477 | 477 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| 478 | 478 |
splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || |
| ... | ... |
@@ -586,7 +583,7 @@ func TestRawFormatWithLabels(t *testing.T) {
|
| 586 | 586 |
splunkLoggerDriver.nullMessage.Source != "" || |
| 587 | 587 |
splunkLoggerDriver.nullMessage.SourceType != "" || |
| 588 | 588 |
splunkLoggerDriver.nullMessage.Index != "" || |
| 589 |
- splunkLoggerDriver.gzipCompression != false || |
|
| 589 |
+ splunkLoggerDriver.gzipCompression || |
|
| 590 | 590 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 591 | 591 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| 592 | 592 |
splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || |
| ... | ... |
@@ -698,7 +695,7 @@ func TestRawFormatWithoutTag(t *testing.T) {
|
| 698 | 698 |
splunkLoggerDriver.nullMessage.Source != "" || |
| 699 | 699 |
splunkLoggerDriver.nullMessage.SourceType != "" || |
| 700 | 700 |
splunkLoggerDriver.nullMessage.Index != "" || |
| 701 |
- splunkLoggerDriver.gzipCompression != false || |
|
| 701 |
+ splunkLoggerDriver.gzipCompression || |
|
| 702 | 702 |
splunkLoggerDriver.postMessagesFrequency != defaultPostMessagesFrequency || |
| 703 | 703 |
splunkLoggerDriver.postMessagesBatchSize != defaultPostMessagesBatchSize || |
| 704 | 704 |
splunkLoggerDriver.bufferMaximum != defaultBufferMaximum || |
| ... | ... |
@@ -115,6 +115,7 @@ var ( |
| 115 | 115 |
func (daemon *Daemon) startIngressWorker() {
|
| 116 | 116 |
ingressJobsChannel = make(chan *ingressJob, 100) |
| 117 | 117 |
go func() {
|
| 118 |
+ // nolint: gosimple |
|
| 118 | 119 |
for {
|
| 119 | 120 |
select {
|
| 120 | 121 |
case r := <-ingressJobsChannel: |
| ... | ... |
@@ -232,7 +233,6 @@ func (daemon *Daemon) releaseIngress(id string) {
|
| 232 | 232 |
logrus.Errorf("Failed to delete ingress network %s: %v", n.ID(), err)
|
| 233 | 233 |
return |
| 234 | 234 |
} |
| 235 |
- return |
|
| 236 | 235 |
} |
| 237 | 236 |
|
| 238 | 237 |
// SetNetworkBootstrapKeys sets the bootstrap keys. |
| ... | ... |
@@ -12,6 +12,7 @@ import ( |
| 12 | 12 |
"github.com/docker/docker/pkg/discovery" |
| 13 | 13 |
_ "github.com/docker/docker/pkg/discovery/memory" |
| 14 | 14 |
"github.com/docker/docker/registry" |
| 15 |
+ "github.com/stretchr/testify/assert" |
|
| 15 | 16 |
) |
| 16 | 17 |
|
| 17 | 18 |
func TestDaemonReloadLabels(t *testing.T) {
|
| ... | ... |
@@ -85,15 +86,11 @@ func TestDaemonReloadAllowNondistributableArtifacts(t *testing.T) {
|
| 85 | 85 |
for _, value := range serviceConfig.AllowNondistributableArtifactsCIDRs {
|
| 86 | 86 |
actual = append(actual, value.String()) |
| 87 | 87 |
} |
| 88 |
- for _, value := range serviceConfig.AllowNondistributableArtifactsHostnames {
|
|
| 89 |
- actual = append(actual, value) |
|
| 90 |
- } |
|
| 88 |
+ actual = append(actual, serviceConfig.AllowNondistributableArtifactsHostnames...) |
|
| 91 | 89 |
|
| 92 | 90 |
sort.Strings(registries) |
| 93 | 91 |
sort.Strings(actual) |
| 94 |
- if !reflect.DeepEqual(registries, actual) {
|
|
| 95 |
- t.Fatalf("expected %v, got %v\n", registries, actual)
|
|
| 96 |
- } |
|
| 92 |
+ assert.Equal(t, registries, actual) |
|
| 97 | 93 |
} |
| 98 | 94 |
|
| 99 | 95 |
func TestDaemonReloadMirrors(t *testing.T) {
|
| ... | ... |
@@ -16,6 +16,7 @@ func validatePSArgs(psArgs string) error {
|
| 16 | 16 |
// NOTE: \\s does not detect unicode whitespaces. |
| 17 | 17 |
// So we use fieldsASCII instead of strings.Fields in parsePSOutput. |
| 18 | 18 |
// See https://github.com/docker/docker/pull/24358 |
| 19 |
+ // nolint: gosimple |
|
| 19 | 20 |
re := regexp.MustCompile("\\s+([^\\s]*)=\\s*(PID[^\\s]*)")
|
| 20 | 21 |
for _, group := range re.FindAllStringSubmatch(psArgs, -1) {
|
| 21 | 22 |
if len(group) >= 3 {
|
| ... | ... |
@@ -395,12 +395,7 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress. |
| 395 | 395 |
defer layerUpload.Close() |
| 396 | 396 |
|
| 397 | 397 |
// upload the blob |
| 398 |
- desc, err := pd.uploadUsingSession(ctx, progressOutput, diffID, layerUpload) |
|
| 399 |
- if err != nil {
|
|
| 400 |
- return desc, err |
|
| 401 |
- } |
|
| 402 |
- |
|
| 403 |
- return desc, nil |
|
| 398 |
+ return pd.uploadUsingSession(ctx, progressOutput, diffID, layerUpload) |
|
| 404 | 399 |
} |
| 405 | 400 |
|
| 406 | 401 |
func (pd *v2PushDescriptor) SetRemoteDescriptor(descriptor distribution.Descriptor) {
|
| ... | ... |
@@ -9,15 +9,14 @@ |
| 9 | 9 |
"api/types/container/container_.*", |
| 10 | 10 |
"integration-cli/" |
| 11 | 11 |
], |
| 12 |
- "Skip": [ |
|
| 13 |
- "integration-cli/" |
|
| 14 |
- ], |
|
| 12 |
+ "Skip": ["integration-cli/"], |
|
| 15 | 13 |
|
| 16 | 14 |
"Enable": [ |
| 17 | 15 |
"deadcode", |
| 18 | 16 |
"gofmt", |
| 19 | 17 |
"goimports", |
| 20 | 18 |
"golint", |
| 19 |
+ "gosimple", |
|
| 21 | 20 |
"ineffassign", |
| 22 | 21 |
"interfacer", |
| 23 | 22 |
"unconvert", |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package image |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "bytes" |
|
| 5 | 4 |
"crypto/rand" |
| 6 | 5 |
"crypto/sha256" |
| 7 | 6 |
"encoding/hex" |
| ... | ... |
@@ -12,7 +11,7 @@ import ( |
| 12 | 12 |
"testing" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/docker/docker/internal/testutil" |
| 15 |
- "github.com/opencontainers/go-digest" |
|
| 15 |
+ digest "github.com/opencontainers/go-digest" |
|
| 16 | 16 |
"github.com/stretchr/testify/assert" |
| 17 | 17 |
) |
| 18 | 18 |
|
| ... | ... |
@@ -112,9 +111,7 @@ func TestFSMetadataGetSet(t *testing.T) {
|
| 112 | 112 |
actual, err := store.GetMetadata(tc.id, tc.key) |
| 113 | 113 |
assert.NoError(t, err) |
| 114 | 114 |
|
| 115 |
- if bytes.Compare(actual, tc.value) != 0 {
|
|
| 116 |
- t.Fatalf("Metadata expected %q, got %q", tc.value, actual)
|
|
| 117 |
- } |
|
| 115 |
+ assert.Equal(t, tc.value, actual) |
|
| 118 | 116 |
} |
| 119 | 117 |
|
| 120 | 118 |
_, err = store.GetMetadata(id2, "tkey2") |
| ... | ... |
@@ -183,9 +180,7 @@ func TestFSGetSet(t *testing.T) {
|
| 183 | 183 |
for _, tc := range tcases {
|
| 184 | 184 |
data, err := store.Get(tc.expected) |
| 185 | 185 |
assert.NoError(t, err) |
| 186 |
- if bytes.Compare(data, tc.input) != 0 {
|
|
| 187 |
- t.Fatalf("expected data %q, got %q", tc.input, data)
|
|
| 188 |
- } |
|
| 186 |
+ assert.Equal(t, tc.input, data) |
|
| 189 | 187 |
} |
| 190 | 188 |
} |
| 191 | 189 |
|
| ... | ... |
@@ -82,8 +82,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool) |
| 82 | 82 |
if err := checkCompatibleOS(img.OS); err != nil {
|
| 83 | 83 |
return err |
| 84 | 84 |
} |
| 85 |
- var rootFS image.RootFS |
|
| 86 |
- rootFS = *img.RootFS |
|
| 85 |
+ rootFS := *img.RootFS |
|
| 87 | 86 |
rootFS.DiffIDs = nil |
| 88 | 87 |
|
| 89 | 88 |
if expected, actual := len(m.Layers), len(img.RootFS.DiffIDs); expected != actual {
|
| ... | ... |
@@ -296,10 +296,7 @@ func (clnt *client) UpdateResources(containerID string, resources Resources) err |
| 296 | 296 |
Pid: InitFriendlyName, |
| 297 | 297 |
Resources: (*containerd.UpdateResource)(&resources), |
| 298 | 298 |
}) |
| 299 |
- if err != nil {
|
|
| 300 |
- return err |
|
| 301 |
- } |
|
| 302 |
- return nil |
|
| 299 |
+ return err |
|
| 303 | 300 |
} |
| 304 | 301 |
|
| 305 | 302 |
func (clnt *client) getExitNotifier(containerID string) *exitNotifier {
|
| ... | ... |
@@ -158,7 +158,7 @@ func sendBody(url string, header http.Header) bool {
|
| 158 | 158 |
|
| 159 | 159 |
// headers returns flatten version of the http headers excluding authorization |
| 160 | 160 |
func headers(header http.Header) map[string]string {
|
| 161 |
- v := make(map[string]string, 0) |
|
| 161 |
+ v := make(map[string]string) |
|
| 162 | 162 |
for k, values := range header {
|
| 163 | 163 |
// Skip authorization headers |
| 164 | 164 |
if strings.EqualFold(k, "Authorization") || strings.EqualFold(k, "X-Registry-Config") || strings.EqualFold(k, "X-Registry-Auth") {
|
| ... | ... |
@@ -351,8 +351,7 @@ func RemoveDeviceDeferred(name string) error {
|
| 351 | 351 |
// disable udev dm rules and delete the symlink under /dev/mapper by itself, |
| 352 | 352 |
// even if the removal is deferred by the kernel. |
| 353 | 353 |
cookie := new(uint) |
| 354 |
- var flags uint16 |
|
| 355 |
- flags = DmUdevDisableLibraryFallback |
|
| 354 |
+ flags := uint16(DmUdevDisableLibraryFallback) |
|
| 356 | 355 |
if err := task.setCookie(cookie, flags); err != nil {
|
| 357 | 356 |
return fmt.Errorf("devicemapper: Can not set cookie: %s", err)
|
| 358 | 357 |
} |
| ... | ... |
@@ -465,8 +464,7 @@ func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize |
| 465 | 465 |
} |
| 466 | 466 |
|
| 467 | 467 |
cookie := new(uint) |
| 468 |
- var flags uint16 |
|
| 469 |
- flags = DmUdevDisableSubsystemRulesFlag | DmUdevDisableDiskRulesFlag | DmUdevDisableOtherRulesFlag |
|
| 468 |
+ flags := uint16(DmUdevDisableSubsystemRulesFlag | DmUdevDisableDiskRulesFlag | DmUdevDisableOtherRulesFlag) |
|
| 470 | 469 |
if err := task.setCookie(cookie, flags); err != nil {
|
| 471 | 470 |
return fmt.Errorf("devicemapper: Can't set cookie %s", err)
|
| 472 | 471 |
} |
| ... | ... |
@@ -11,7 +11,6 @@ import ( |
| 11 | 11 |
"github.com/docker/docker/pkg/discovery" |
| 12 | 12 |
"github.com/docker/libkv" |
| 13 | 13 |
"github.com/docker/libkv/store" |
| 14 |
- |
|
| 15 | 14 |
"github.com/go-check/check" |
| 16 | 15 |
) |
| 17 | 16 |
|
| ... | ... |
@@ -130,7 +129,6 @@ func (s *Mock) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
|
| 130 | 130 |
|
| 131 | 131 |
// Close mock |
| 132 | 132 |
func (s *Mock) Close() {
|
| 133 |
- return |
|
| 134 | 133 |
} |
| 135 | 134 |
|
| 136 | 135 |
func (ds *DiscoverySuite) TestInitializeWithCerts(c *check.C) {
|
| ... | ... |
@@ -17,10 +17,7 @@ func ioctlLoopCtlGetFree(fd uintptr) (int, error) {
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
func ioctlLoopSetFd(loopFd, sparseFd uintptr) error {
|
| 20 |
- if err := unix.IoctlSetInt(int(loopFd), LoopSetFd, int(sparseFd)); err != nil {
|
|
| 21 |
- return err |
|
| 22 |
- } |
|
| 23 |
- return nil |
|
| 20 |
+ return unix.IoctlSetInt(int(loopFd), LoopSetFd, int(sparseFd)) |
|
| 24 | 21 |
} |
| 25 | 22 |
|
| 26 | 23 |
func ioctlLoopSetStatus64(loopFd uintptr, loopInfo *loopInfo64) error {
|
| ... | ... |
@@ -47,8 +44,5 @@ func ioctlLoopGetStatus64(loopFd uintptr) (*loopInfo64, error) {
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
func ioctlLoopSetCapacity(loopFd uintptr, value int) error {
|
| 50 |
- if err := unix.IoctlSetInt(int(loopFd), LoopSetCapacity, value); err != nil {
|
|
| 51 |
- return err |
|
| 52 |
- } |
|
| 53 |
- return nil |
|
| 50 |
+ return unix.IoctlSetInt(int(loopFd), LoopSetCapacity, value) |
|
| 54 | 51 |
} |
| ... | ... |
@@ -6,6 +6,9 @@ import ( |
| 6 | 6 |
"io" |
| 7 | 7 |
"strings" |
| 8 | 8 |
"testing" |
| 9 |
+ |
|
| 10 |
+ "github.com/stretchr/testify/assert" |
|
| 11 |
+ "github.com/stretchr/testify/require" |
|
| 9 | 12 |
) |
| 10 | 13 |
|
| 11 | 14 |
func TestBufioReaderPoolGetWithNoReaderShouldCreateOne(t *testing.T) {
|
| ... | ... |
@@ -92,22 +95,16 @@ func TestBufioWriterPoolPutAndGet(t *testing.T) {
|
| 92 | 92 |
buf := new(bytes.Buffer) |
| 93 | 93 |
bw := bufio.NewWriter(buf) |
| 94 | 94 |
writer := BufioWriter32KPool.Get(bw) |
| 95 |
- if writer == nil {
|
|
| 96 |
- t.Fatalf("BufioReaderPool should not return a nil writer.")
|
|
| 97 |
- } |
|
| 95 |
+ require.NotNil(t, writer) |
|
| 96 |
+ |
|
| 98 | 97 |
written, err := writer.Write([]byte("foobar"))
|
| 99 |
- if err != nil {
|
|
| 100 |
- t.Fatal(err) |
|
| 101 |
- } |
|
| 102 |
- if written != 6 {
|
|
| 103 |
- t.Fatalf("Should have written 6 bytes, but wrote %v bytes", written)
|
|
| 104 |
- } |
|
| 98 |
+ require.NoError(t, err) |
|
| 99 |
+ assert.Equal(t, 6, written) |
|
| 100 |
+ |
|
| 105 | 101 |
// Make sure we Flush all the way ? |
| 106 | 102 |
writer.Flush() |
| 107 | 103 |
bw.Flush() |
| 108 |
- if len(buf.Bytes()) != 6 {
|
|
| 109 |
- t.Fatalf("The buffer should contain 6 bytes ('foobar') but contains %v ('%v')", buf.Bytes(), string(buf.Bytes()))
|
|
| 110 |
- } |
|
| 104 |
+ assert.Len(t, buf.Bytes(), 6) |
|
| 111 | 105 |
// Reset the buffer |
| 112 | 106 |
buf.Reset() |
| 113 | 107 |
BufioWriter32KPool.Put(writer) |
| ... | ... |
@@ -306,19 +306,19 @@ func TestAddDeleteGet(t *testing.T) {
|
| 306 | 306 |
} |
| 307 | 307 |
|
| 308 | 308 |
// Delete a few references |
| 309 |
- if deleted, err := store.Delete(ref1); err != nil || deleted != true {
|
|
| 309 |
+ if deleted, err := store.Delete(ref1); err != nil || !deleted {
|
|
| 310 | 310 |
t.Fatal("Delete failed")
|
| 311 | 311 |
} |
| 312 | 312 |
if _, err := store.Get(ref1); err != ErrDoesNotExist {
|
| 313 | 313 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 314 | 314 |
} |
| 315 |
- if deleted, err := store.Delete(ref5); err != nil || deleted != true {
|
|
| 315 |
+ if deleted, err := store.Delete(ref5); err != nil || !deleted {
|
|
| 316 | 316 |
t.Fatal("Delete failed")
|
| 317 | 317 |
} |
| 318 | 318 |
if _, err := store.Get(ref5); err != ErrDoesNotExist {
|
| 319 | 319 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 320 | 320 |
} |
| 321 |
- if deleted, err := store.Delete(nameOnly); err != nil || deleted != true {
|
|
| 321 |
+ if deleted, err := store.Delete(nameOnly); err != nil || !deleted {
|
|
| 322 | 322 |
t.Fatal("Delete failed")
|
| 323 | 323 |
} |
| 324 | 324 |
if _, err := store.Get(nameOnly); err != ErrDoesNotExist {
|
| ... | ... |
@@ -75,7 +75,7 @@ func newServiceConfig(options ServiceOptions) *serviceConfig {
|
| 75 | 75 |
config := &serviceConfig{
|
| 76 | 76 |
ServiceConfig: registrytypes.ServiceConfig{
|
| 77 | 77 |
InsecureRegistryCIDRs: make([]*registrytypes.NetIPNet, 0), |
| 78 |
- IndexConfigs: make(map[string]*registrytypes.IndexInfo, 0), |
|
| 78 |
+ IndexConfigs: make(map[string]*registrytypes.IndexInfo), |
|
| 79 | 79 |
// Hack: Bypass setting the mirrors to IndexConfigs since they are going away |
| 80 | 80 |
// and Mirrors are only for the official registry anyways. |
| 81 | 81 |
}, |
| ... | ... |
@@ -171,7 +171,7 @@ func (config *serviceConfig) LoadInsecureRegistries(registries []string) error {
|
| 171 | 171 |
originalIndexInfos := config.ServiceConfig.IndexConfigs |
| 172 | 172 |
|
| 173 | 173 |
config.ServiceConfig.InsecureRegistryCIDRs = make([]*registrytypes.NetIPNet, 0) |
| 174 |
- config.ServiceConfig.IndexConfigs = make(map[string]*registrytypes.IndexInfo, 0) |
|
| 174 |
+ config.ServiceConfig.IndexConfigs = make(map[string]*registrytypes.IndexInfo) |
|
| 175 | 175 |
|
| 176 | 176 |
skip: |
| 177 | 177 |
for _, r := range registries {
|
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/distribution/registry/client/transport" |
| 15 | 15 |
"github.com/docker/docker/api/types" |
| 16 | 16 |
registrytypes "github.com/docker/docker/api/types/registry" |
| 17 |
+ "github.com/stretchr/testify/assert" |
|
| 17 | 18 |
) |
| 18 | 19 |
|
| 19 | 20 |
var ( |
| ... | ... |
@@ -747,16 +748,12 @@ func TestSearchRepositories(t *testing.T) {
|
| 747 | 747 |
func TestTrustedLocation(t *testing.T) {
|
| 748 | 748 |
for _, url := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} {
|
| 749 | 749 |
req, _ := http.NewRequest("GET", url, nil)
|
| 750 |
- if trustedLocation(req) == true {
|
|
| 751 |
- t.Fatalf("'%s' shouldn't be detected as a trusted location", url)
|
|
| 752 |
- } |
|
| 750 |
+ assert.False(t, trustedLocation(req)) |
|
| 753 | 751 |
} |
| 754 | 752 |
|
| 755 | 753 |
for _, url := range []string{"https://docker.io", "https://test.docker.com:80"} {
|
| 756 | 754 |
req, _ := http.NewRequest("GET", url, nil)
|
| 757 |
- if trustedLocation(req) == false {
|
|
| 758 |
- t.Fatalf("'%s' should be detected as a trusted location", url)
|
|
| 759 |
- } |
|
| 755 |
+ assert.True(t, trustedLocation(req)) |
|
| 760 | 756 |
} |
| 761 | 757 |
} |
| 762 | 758 |
|
| ... | ... |
@@ -68,7 +68,7 @@ func validateNetContainerMode(c *container.Config, hc *container.HostConfig) err |
| 68 | 68 |
return ErrConflictContainerNetworkAndMac |
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 |
- if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts == true) {
|
|
| 71 |
+ if hc.NetworkMode.IsContainer() && (len(hc.PortBindings) > 0 || hc.PublishAllPorts) {
|
|
| 72 | 72 |
return ErrConflictNetworkPublishPorts |
| 73 | 73 |
} |
| 74 | 74 |
|
| ... | ... |
@@ -195,9 +195,7 @@ func TestDecodeHostConfig(t *testing.T) {
|
| 195 | 195 |
t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err))
|
| 196 | 196 |
} |
| 197 | 197 |
|
| 198 |
- if c.Privileged != false {
|
|
| 199 |
- t.Fatalf("Expected privileged false, found %v\n", c.Privileged)
|
|
| 200 |
- } |
|
| 198 |
+ assert.False(t, c.Privileged) |
|
| 201 | 199 |
|
| 202 | 200 |
if l := len(c.Binds); l != 1 {
|
| 203 | 201 |
t.Fatalf("Expected 1 bind, found %d\n", l)
|