Przeglądaj źródła

Merge pull request #32222 from unclejack/small_cleanup

Small cleanup
Sebastiaan van Stijn 8 lat temu
rodzic
commit
9c0473fa65

+ 1 - 1
pkg/archive/archive.go

@@ -145,7 +145,7 @@ func DetectCompression(source []byte) Compression {
 			logrus.Debug("Len too short")
 			logrus.Debug("Len too short")
 			continue
 			continue
 		}
 		}
-		if bytes.Compare(m, source[:len(m)]) == 0 {
+		if bytes.Equal(m, source[:len(m)]) {
 			return compression
 			return compression
 		}
 		}
 	}
 	}

+ 1 - 4
pkg/archive/archive_unix.go

@@ -107,10 +107,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
 		mode |= syscall.S_IFIFO
 		mode |= syscall.S_IFIFO
 	}
 	}
 
 
-	if err := system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor))); err != nil {
-		return err
-	}
-	return nil
+	return system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor)))
 }
 }
 
 
 func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
 func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {

+ 2 - 2
pkg/archive/changes.go

@@ -267,7 +267,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
 	}
 	}
 
 
 	for name, newChild := range info.children {
 	for name, newChild := range info.children {
-		oldChild, _ := oldChildren[name]
+		oldChild := oldChildren[name]
 		if oldChild != nil {
 		if oldChild != nil {
 			// change?
 			// change?
 			oldStat := oldChild.stat
 			oldStat := oldChild.stat
@@ -279,7 +279,7 @@ func (info *FileInfo) addChanges(oldInfo *FileInfo, changes *[]Change) {
 			// breaks down is if some code intentionally hides a change by setting
 			// breaks down is if some code intentionally hides a change by setting
 			// back mtime
 			// back mtime
 			if statDifferent(oldStat, newStat) ||
 			if statDifferent(oldStat, newStat) ||
-				bytes.Compare(oldChild.capability, newChild.capability) != 0 {
+				!bytes.Equal(oldChild.capability, newChild.capability) {
 				change := Change{
 				change := Change{
 					Path: newChild.path(),
 					Path: newChild.path(),
 					Kind: ChangeModify,
 					Kind: ChangeModify,

+ 1 - 1
pkg/chrootarchive/archive_test.go

@@ -77,7 +77,7 @@ func TestChrootUntarWithHugeExcludesList(t *testing.T) {
 	options := &archive.TarOptions{}
 	options := &archive.TarOptions{}
 	//65534 entries of 64-byte strings ~= 4MB of environment space which should overflow
 	//65534 entries of 64-byte strings ~= 4MB of environment space which should overflow
 	//on most systems when passed via environment or command line arguments
 	//on most systems when passed via environment or command line arguments
-	excludes := make([]string, 65534, 65534)
+	excludes := make([]string, 65534)
 	for i := 0; i < 65534; i++ {
 	for i := 0; i < 65534; i++ {
 		excludes[i] = strings.Repeat(string(i), 64)
 		excludes[i] = strings.Repeat(string(i), 64)
 	}
 	}

+ 2 - 2
pkg/filenotify/poller.go

@@ -44,7 +44,7 @@ func (w *filePoller) Add(name string) error {
 	w.mu.Lock()
 	w.mu.Lock()
 	defer w.mu.Unlock()
 	defer w.mu.Unlock()
 
 
-	if w.closed == true {
+	if w.closed {
 		return errPollerClosed
 		return errPollerClosed
 	}
 	}
 
 
@@ -78,7 +78,7 @@ func (w *filePoller) Remove(name string) error {
 }
 }
 
 
 func (w *filePoller) remove(name string) error {
 func (w *filePoller) remove(name string) error {
-	if w.closed == true {
+	if w.closed {
 		return errPollerClosed
 		return errPollerClosed
 	}
 	}
 
 

+ 9 - 9
pkg/fileutils/fileutils_test.go

@@ -208,7 +208,7 @@ func TestReadSymlinkedDirectoryToFile(t *testing.T) {
 
 
 func TestWildcardMatches(t *testing.T) {
 func TestWildcardMatches(t *testing.T) {
 	match, _ := Matches("fileutils.go", []string{"*"})
 	match, _ := Matches("fileutils.go", []string{"*"})
-	if match != true {
+	if !match {
 		t.Errorf("failed to get a wildcard match, got %v", match)
 		t.Errorf("failed to get a wildcard match, got %v", match)
 	}
 	}
 }
 }
@@ -216,7 +216,7 @@ func TestWildcardMatches(t *testing.T) {
 // A simple pattern match should return true.
 // A simple pattern match should return true.
 func TestPatternMatches(t *testing.T) {
 func TestPatternMatches(t *testing.T) {
 	match, _ := Matches("fileutils.go", []string{"*.go"})
 	match, _ := Matches("fileutils.go", []string{"*.go"})
-	if match != true {
+	if !match {
 		t.Errorf("failed to get a match, got %v", match)
 		t.Errorf("failed to get a match, got %v", match)
 	}
 	}
 }
 }
@@ -224,7 +224,7 @@ func TestPatternMatches(t *testing.T) {
 // An exclusion followed by an inclusion should return true.
 // An exclusion followed by an inclusion should return true.
 func TestExclusionPatternMatchesPatternBefore(t *testing.T) {
 func TestExclusionPatternMatchesPatternBefore(t *testing.T) {
 	match, _ := Matches("fileutils.go", []string{"!fileutils.go", "*.go"})
 	match, _ := Matches("fileutils.go", []string{"!fileutils.go", "*.go"})
-	if match != true {
+	if !match {
 		t.Errorf("failed to get true match on exclusion pattern, got %v", match)
 		t.Errorf("failed to get true match on exclusion pattern, got %v", match)
 	}
 	}
 }
 }
@@ -232,7 +232,7 @@ func TestExclusionPatternMatchesPatternBefore(t *testing.T) {
 // A folder pattern followed by an exception should return false.
 // A folder pattern followed by an exception should return false.
 func TestPatternMatchesFolderExclusions(t *testing.T) {
 func TestPatternMatchesFolderExclusions(t *testing.T) {
 	match, _ := Matches("docs/README.md", []string{"docs", "!docs/README.md"})
 	match, _ := Matches("docs/README.md", []string{"docs", "!docs/README.md"})
-	if match != false {
+	if match {
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 	}
 	}
 }
 }
@@ -240,7 +240,7 @@ func TestPatternMatchesFolderExclusions(t *testing.T) {
 // A folder pattern followed by an exception should return false.
 // A folder pattern followed by an exception should return false.
 func TestPatternMatchesFolderWithSlashExclusions(t *testing.T) {
 func TestPatternMatchesFolderWithSlashExclusions(t *testing.T) {
 	match, _ := Matches("docs/README.md", []string{"docs/", "!docs/README.md"})
 	match, _ := Matches("docs/README.md", []string{"docs/", "!docs/README.md"})
-	if match != false {
+	if match {
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 	}
 	}
 }
 }
@@ -248,7 +248,7 @@ func TestPatternMatchesFolderWithSlashExclusions(t *testing.T) {
 // A folder pattern followed by an exception should return false.
 // A folder pattern followed by an exception should return false.
 func TestPatternMatchesFolderWildcardExclusions(t *testing.T) {
 func TestPatternMatchesFolderWildcardExclusions(t *testing.T) {
 	match, _ := Matches("docs/README.md", []string{"docs/*", "!docs/README.md"})
 	match, _ := Matches("docs/README.md", []string{"docs/*", "!docs/README.md"})
-	if match != false {
+	if match {
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 		t.Errorf("failed to get a false match on exclusion pattern, got %v", match)
 	}
 	}
 }
 }
@@ -256,7 +256,7 @@ func TestPatternMatchesFolderWildcardExclusions(t *testing.T) {
 // A pattern followed by an exclusion should return false.
 // A pattern followed by an exclusion should return false.
 func TestExclusionPatternMatchesPatternAfter(t *testing.T) {
 func TestExclusionPatternMatchesPatternAfter(t *testing.T) {
 	match, _ := Matches("fileutils.go", []string{"*.go", "!fileutils.go"})
 	match, _ := Matches("fileutils.go", []string{"*.go", "!fileutils.go"})
-	if match != false {
+	if match {
 		t.Errorf("failed to get false match on exclusion pattern, got %v", match)
 		t.Errorf("failed to get false match on exclusion pattern, got %v", match)
 	}
 	}
 }
 }
@@ -264,7 +264,7 @@ func TestExclusionPatternMatchesPatternAfter(t *testing.T) {
 // A filename evaluating to . should return false.
 // A filename evaluating to . should return false.
 func TestExclusionPatternMatchesWholeDirectory(t *testing.T) {
 func TestExclusionPatternMatchesWholeDirectory(t *testing.T) {
 	match, _ := Matches(".", []string{"*.go"})
 	match, _ := Matches(".", []string{"*.go"})
-	if match != false {
+	if match {
 		t.Errorf("failed to get false match on ., got %v", match)
 		t.Errorf("failed to get false match on ., got %v", match)
 	}
 	}
 }
 }
@@ -573,7 +573,7 @@ func TestMatch(t *testing.T) {
 		pattern := tt.pattern
 		pattern := tt.pattern
 		s := tt.s
 		s := tt.s
 		if runtime.GOOS == "windows" {
 		if runtime.GOOS == "windows" {
-			if strings.Index(pattern, "\\") >= 0 {
+			if strings.Contains(pattern, "\\") {
 				// no escape allowed on windows.
 				// no escape allowed on windows.
 				continue
 				continue
 			}
 			}

+ 2 - 2
pkg/ioutils/fswriters_test.go

@@ -37,7 +37,7 @@ func TestAtomicWriteToFile(t *testing.T) {
 		t.Fatalf("Error reading from file: %v", err)
 		t.Fatalf("Error reading from file: %v", err)
 	}
 	}
 
 
-	if bytes.Compare(actual, expected) != 0 {
+	if !bytes.Equal(actual, expected) {
 		t.Fatalf("Data mismatch, expected %q, got %q", expected, actual)
 		t.Fatalf("Data mismatch, expected %q, got %q", expected, actual)
 	}
 	}
 
 
@@ -85,7 +85,7 @@ func TestAtomicWriteSetCommit(t *testing.T) {
 		t.Fatalf("Error reading from file: %v", err)
 		t.Fatalf("Error reading from file: %v", err)
 	}
 	}
 
 
-	if bytes.Compare(actual, expected) != 0 {
+	if !bytes.Equal(actual, expected) {
 		t.Fatalf("Data mismatch, expected %q, got %q", expected, actual)
 		t.Fatalf("Data mismatch, expected %q, got %q", expected, actual)
 	}
 	}
 
 

+ 1 - 1
pkg/ioutils/multireader_test.go

@@ -193,7 +193,7 @@ func TestMultiReadSeekerCurAfterSet(t *testing.T) {
 func TestMultiReadSeekerSmallReads(t *testing.T) {
 func TestMultiReadSeekerSmallReads(t *testing.T) {
 	readers := []io.ReadSeeker{}
 	readers := []io.ReadSeeker{}
 	for i := 0; i < 10; i++ {
 	for i := 0; i < 10; i++ {
-		integer := make([]byte, 4, 4)
+		integer := make([]byte, 4)
 		binary.BigEndian.PutUint32(integer, uint32(i))
 		binary.BigEndian.PutUint32(integer, uint32(i))
 		readers = append(readers, bytes.NewReader(integer))
 		readers = append(readers, bytes.NewReader(integer))
 	}
 	}

+ 1 - 1
pkg/jsonlog/jsonlogbytes.go

@@ -30,7 +30,7 @@ func (mj *JSONLogs) MarshalJSONBuf(buf *bytes.Buffer) error {
 		ffjsonWriteJSONBytesAsString(buf, mj.Log)
 		ffjsonWriteJSONBytesAsString(buf, mj.Log)
 	}
 	}
 	if len(mj.Stream) != 0 {
 	if len(mj.Stream) != 0 {
-		if first == true {
+		if first {
 			first = false
 			first = false
 		} else {
 		} else {
 			buf.WriteString(`,`)
 			buf.WriteString(`,`)

+ 1 - 1
pkg/listeners/group_unix.go

@@ -23,7 +23,7 @@ func lookupGID(name string) (int, error) {
 	if err != nil {
 	if err != nil {
 		return -1, errors.Wrapf(err, "error parsing groups for %s", name)
 		return -1, errors.Wrapf(err, "error parsing groups for %s", name)
 	}
 	}
-	if groups != nil && len(groups) > 0 {
+	if len(groups) > 0 {
 		return groups[0].Gid, nil
 		return groups[0].Gid, nil
 	}
 	}
 	gid, err := strconv.Atoi(name)
 	gid, err := strconv.Atoi(name)

+ 1 - 4
pkg/mount/mount.go

@@ -46,10 +46,7 @@ func Mount(device, target, mType, options string) error {
 // flags.go for supported option flags.
 // flags.go for supported option flags.
 func ForceMount(device, target, mType, options string) error {
 func ForceMount(device, target, mType, options string) error {
 	flag, data := parseOptions(options)
 	flag, data := parseOptions(options)
-	if err := mount(device, target, mType, uintptr(flag), data); err != nil {
-		return err
-	}
-	return nil
+	return mount(device, target, mType, uintptr(flag), data)
 }
 }
 
 
 // Unmount will unmount the target filesystem, so long as it is mounted.
 // Unmount will unmount the target filesystem, so long as it is mounted.

+ 1 - 1
pkg/plugins/discovery_test.go

@@ -66,7 +66,7 @@ func TestFileSpecPlugin(t *testing.T) {
 			t.Fatalf("Expected plugin addr `%s`, got %s\n", c.addr, p.Addr)
 			t.Fatalf("Expected plugin addr `%s`, got %s\n", c.addr, p.Addr)
 		}
 		}
 
 
-		if p.TLSConfig.InsecureSkipVerify != true {
+		if !p.TLSConfig.InsecureSkipVerify {
 			t.Fatalf("Expected TLS verification to be skipped")
 			t.Fatalf("Expected TLS verification to be skipped")
 		}
 		}
 	}
 	}

+ 1 - 1
pkg/plugins/discovery_unix_test.go

@@ -53,7 +53,7 @@ func TestLocalSocket(t *testing.T) {
 		if p.Addr != addr {
 		if p.Addr != addr {
 			t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr)
 			t.Fatalf("Expected plugin addr `%s`, got %s\n", addr, p.Addr)
 		}
 		}
-		if p.TLSConfig.InsecureSkipVerify != true {
+		if !p.TLSConfig.InsecureSkipVerify {
 			t.Fatalf("Expected TLS verification to be skipped")
 			t.Fatalf("Expected TLS verification to be skipped")
 		}
 		}
 		l.Close()
 		l.Close()

+ 1 - 1
pkg/progress/progressreader_test.go

@@ -14,7 +14,7 @@ func TestOutputOnPrematureClose(t *testing.T) {
 
 
 	pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
 	pr := NewProgressReader(reader, ChanOutput(progressChan), int64(len(content)), "Test", "Read")
 
 
-	part := make([]byte, 4, 4)
+	part := make([]byte, 4)
 	_, err := io.ReadFull(pr, part)
 	_, err := io.ReadFull(pr, part)
 	if err != nil {
 	if err != nil {
 		pr.Close()
 		pr.Close()

+ 1 - 3
pkg/registrar/registrar.go

@@ -100,9 +100,7 @@ func (r *Registrar) GetNames(key string) ([]string, error) {
 	}
 	}
 
 
 	ls := make([]string, 0, len(names))
 	ls := make([]string, 0, len(names))
-	for _, n := range names {
-		ls = append(ls, n)
-	}
+	ls = append(ls, names...)
 	return ls, nil
 	return ls, nil
 }
 }
 
 

+ 6 - 6
pkg/urlutil/urlutil_test.go

@@ -29,13 +29,13 @@ var (
 
 
 func TestValidGitTransport(t *testing.T) {
 func TestValidGitTransport(t *testing.T) {
 	for _, url := range gitUrls {
 	for _, url := range gitUrls {
-		if IsGitTransport(url) == false {
+		if !IsGitTransport(url) {
 			t.Fatalf("%q should be detected as valid Git prefix", url)
 			t.Fatalf("%q should be detected as valid Git prefix", url)
 		}
 		}
 	}
 	}
 
 
 	for _, url := range incompleteGitUrls {
 	for _, url := range incompleteGitUrls {
-		if IsGitTransport(url) == true {
+		if IsGitTransport(url) {
 			t.Fatalf("%q should not be detected as valid Git prefix", url)
 			t.Fatalf("%q should not be detected as valid Git prefix", url)
 		}
 		}
 	}
 	}
@@ -43,19 +43,19 @@ func TestValidGitTransport(t *testing.T) {
 
 
 func TestIsGIT(t *testing.T) {
 func TestIsGIT(t *testing.T) {
 	for _, url := range gitUrls {
 	for _, url := range gitUrls {
-		if IsGitURL(url) == false {
+		if !IsGitURL(url) {
 			t.Fatalf("%q should be detected as valid Git url", url)
 			t.Fatalf("%q should be detected as valid Git url", url)
 		}
 		}
 	}
 	}
 
 
 	for _, url := range incompleteGitUrls {
 	for _, url := range incompleteGitUrls {
-		if IsGitURL(url) == false {
+		if !IsGitURL(url) {
 			t.Fatalf("%q should be detected as valid Git url", url)
 			t.Fatalf("%q should be detected as valid Git url", url)
 		}
 		}
 	}
 	}
 
 
 	for _, url := range invalidGitUrls {
 	for _, url := range invalidGitUrls {
-		if IsGitURL(url) == true {
+		if IsGitURL(url) {
 			t.Fatalf("%q should not be detected as valid Git prefix", url)
 			t.Fatalf("%q should not be detected as valid Git prefix", url)
 		}
 		}
 	}
 	}
@@ -63,7 +63,7 @@ func TestIsGIT(t *testing.T) {
 
 
 func TestIsTransport(t *testing.T) {
 func TestIsTransport(t *testing.T) {
 	for _, url := range transportUrls {
 	for _, url := range transportUrls {
-		if IsTransportURL(url) == false {
+		if !IsTransportURL(url) {
 			t.Fatalf("%q should be detected as valid Transport url", url)
 			t.Fatalf("%q should be detected as valid Transport url", url)
 		}
 		}
 	}
 	}