Browse code

integration-cli: use raw strings for regexes (gosimple)

```
14:26:43 integration-cli/docker_cli_build_test.go:3430:15: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
14:26:43 outRegexp := regexp.MustCompile("^(sha256:|)[a-z0-9]{64}\\n$")
14:26:43 ^
14:26:43 integration-cli/docker_cli_by_digest_test.go:26:20: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
14:26:43 pushDigestRegex = regexp.MustCompile("[\\S]+: digest: ([\\S]+) size: [0-9]+")
14:26:43 ^
14:26:43 integration-cli/docker_cli_by_digest_test.go:27:20: S1007: should use raw string (`...`) with regexp.MustCompile to avoid having to escape twice (gosimple)
14:26:43 digestRegex = regexp.MustCompile("Digest: ([\\S]+)")
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/08/05 23:53:46
Showing 5 changed files
... ...
@@ -3427,7 +3427,7 @@ func (s *DockerSuite) TestBuildLabelsCache(c *testing.T) {
3427 3427
 func (s *DockerSuite) TestBuildNotVerboseSuccess(c *testing.T) {
3428 3428
 	// This test makes sure that -q works correctly when build is successful:
3429 3429
 	// stdout has only the image ID (long image ID) and stderr is empty.
3430
-	outRegexp := regexp.MustCompile("^(sha256:|)[a-z0-9]{64}\\n$")
3430
+	outRegexp := regexp.MustCompile(`^(sha256:|)[a-z0-9]{64}\n$`)
3431 3431
 	buildFlags := cli.WithFlags("-q")
3432 3432
 
3433 3433
 	tt := []struct {
... ...
@@ -22,8 +22,8 @@ import (
22 22
 var (
23 23
 	remoteRepoName  = "dockercli/busybox-by-dgst"
24 24
 	repoName        = fmt.Sprintf("%s/%s", privateRegistryURL, remoteRepoName)
25
-	pushDigestRegex = regexp.MustCompile("[\\S]+: digest: ([\\S]+) size: [0-9]+")
26
-	digestRegex     = regexp.MustCompile("Digest: ([\\S]+)")
25
+	pushDigestRegex = regexp.MustCompile(`[\S]+: digest: ([\S]+) size: [0-9]+`)
26
+	digestRegex     = regexp.MustCompile(`Digest: ([\S]+)`)
27 27
 )
28 28
 
29 29
 func setupImage(c *testing.T) (digest.Digest, error) {
... ...
@@ -110,7 +110,7 @@ func (s *DockerSuite) TestImportFileWithMessage(c *testing.T) {
110 110
 	split := strings.Split(out, "\n")
111 111
 
112 112
 	assert.Equal(c, len(split), 3, "expected 3 lines from image history")
113
-	r := regexp.MustCompile("[\\s]{2,}")
113
+	r := regexp.MustCompile(`[\s]{2,}`)
114 114
 	split = r.Split(split[1], -1)
115 115
 
116 116
 	assert.Equal(c, message, split[3], "didn't get expected value in commit message")
... ...
@@ -45,7 +45,7 @@ func regexpCheckUA(c *testing.T, ua string) {
45 45
 	// check upstreamUA looks correct
46 46
 	// Expecting something like:  Docker-Client/1.11.0-dev (linux)
47 47
 	upstreamUA := unescapeBackslashSemicolonParens(upstreamUAEscaped)
48
-	reUpstreamUA := regexp.MustCompile("^\\(Docker-Client/[0-9A-Za-z+]")
48
+	reUpstreamUA := regexp.MustCompile(`^\(Docker-Client/[0-9A-Za-z+]`)
49 49
 	bMatchUpstreamUA := reUpstreamUA.MatchString(upstreamUA)
50 50
 	assert.Assert(c, bMatchUpstreamUA, "(Upstream) Docker Client User-Agent malformed")
51 51
 }
... ...
@@ -236,7 +236,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *testing.T) {
236 236
 	lines := strings.Split(strings.TrimSpace(out), "\n")
237 237
 	var actual []string
238 238
 	for _, l := range lines {
239
-		if regexp.MustCompile("^[a-f0-9]{64}\\.json$").Match([]byte(l)) {
239
+		if regexp.MustCompile(`^[a-f0-9]{64}\.json$`).Match([]byte(l)) {
240 240
 			actual = append(actual, strings.TrimSuffix(l, ".json"))
241 241
 		}
242 242
 	}