Skip to content

Commit 83ed550

Browse files
authored
Merge pull request #74 from gruntwork-io/yori-fix-allcaps
Run goimports and update all caps constants to idiomatic go
2 parents a61cd66 + effb92e commit 83ed550

File tree

9 files changed

+102
-101
lines changed

9 files changed

+102
-101
lines changed

checksum.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
func verifyChecksumOfReleaseAsset(assetPath string, checksumMap map[string]bool, algorithm string) *FetchError {
1515
computedChecksum, err := computeChecksum(assetPath, algorithm)
1616
if err != nil {
17-
return newError(ERROR_WHILE_COMPUTING_CHECKSUM, err.Error())
17+
return newError(errorWhileComputingChecksum, err.Error())
1818
}
1919
if found, _ := checksumMap[computedChecksum]; !found {
2020
keys := reflect.ValueOf(checksumMap).MapKeys()
21-
return newError(CHECKSUM_DOES_NOT_MATCH, fmt.Sprintf("Expected to checksum value to be one of %s, but instead got %s for Release Asset at %s. This means that either you are using the wrong checksum value in your call to fetch, (e.g. did you update the version of the module you're installing but not the checksum?) or that someone has replaced the asset with a potentially dangerous one and you should be very careful about proceeding.", keys, computedChecksum, assetPath))
21+
return newError(checksumDoesNotMatch, fmt.Sprintf("Expected to checksum value to be one of %s, but instead got %s for Release Asset at %s. This means that either you are using the wrong checksum value in your call to fetch, (e.g. did you update the version of the module you're installing but not the checksum?) or that someone has replaced the asset with a potentially dangerous one and you should be very careful about proceeding.", keys, computedChecksum, assetPath))
2222
}
2323
fmt.Printf("Release asset checksum verified for %s\n", assetPath)
2424

fetch_error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func (e *FetchError) Error() string {
1717
func newError(errorCode int, details string) *FetchError {
1818
return &FetchError{
1919
errorCode: errorCode,
20-
details: details,
21-
err: nil,
20+
details: details,
21+
err: nil,
2222
}
2323
}
2424

@@ -28,7 +28,7 @@ func wrapError(err error) *FetchError {
2828
}
2929
return &FetchError{
3030
errorCode: -1,
31-
details: err.Error(),
32-
err: err,
31+
details: err.Error(),
32+
err: err,
3333
}
3434
}

fetch_error_constants.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

3-
const INVALID_TAG_CONSTRAINT_EXPRESSION = 100
3+
const invalidTagConstraintExpression = 100
44

5-
const GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE = 300
5+
const githubRepoUrlMalformedOrNotParseable = 300
66

7-
const INVALID_GITHUB_TOKEN_OR_ACCESS_DENIED = 401
8-
const REPO_DOES_NOT_EXIST_OR_ACCESS_DENIED = 404
7+
const invalidGithubTokenOrAccessDenied = 401
8+
const repoDoesNotExistOrAccessDenied = 404
99

10-
const FAILED_TO_DOWNLOAD_FILE = 500
11-
const CHECKSUM_DOES_NOT_MATCH = 510
12-
const ERROR_WHILE_COMPUTING_CHECKSUM = 520
10+
const failedToDownloadFile = 500
11+
const checksumDoesNotMatch = 510
12+
const errorWhileComputingChecksum = 520

fetch_error_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ func TestNewError(t *testing.T) {
88
t.Parallel()
99

1010
_ = newError(1, "My error details")
11-
}
11+
}

file.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package main
22

33
import (
4-
"io/ioutil"
5-
"os"
4+
"archive/zip"
5+
"bytes"
66
"fmt"
7+
"io/ioutil"
78
"net/http"
9+
"os"
810
"path/filepath"
9-
"bytes"
10-
"archive/zip"
1111
"strings"
1212
)
1313

@@ -38,10 +38,10 @@ func downloadGithubZipFile(gitHubCommit GitHubCommit, gitHubToken string, instan
3838
return zipFilePath, wrapError(err)
3939
}
4040
if resp.StatusCode != http.StatusOK {
41-
return zipFilePath, newError(FAILED_TO_DOWNLOAD_FILE, fmt.Sprintf("Failed to download file at the url %s. Received HTTP Response %d.", req.URL.String(), resp.StatusCode))
41+
return zipFilePath, newError(failedToDownloadFile, fmt.Sprintf("Failed to download file at the url %s. Received HTTP Response %d.", req.URL.String(), resp.StatusCode))
4242
}
4343
if resp.Header.Get("Content-Type") != "application/zip" {
44-
return zipFilePath, newError(FAILED_TO_DOWNLOAD_FILE, fmt.Sprintf("Failed to download file at the url %s. Expected HTTP Response's \"Content-Type\" header to be \"application/zip\", but was \"%s\"", req.URL.String(), resp.Header.Get("Content-Type")))
44+
return zipFilePath, newError(failedToDownloadFile, fmt.Sprintf("Failed to download file at the url %s. Expected HTTP Response's \"Content-Type\" header to be \"application/zip\", but was \"%s\"", req.URL.String(), resp.Header.Get("Content-Type")))
4545
}
4646

4747
// Copy the contents of the downloaded file to our empty file
@@ -78,7 +78,7 @@ func shouldExtractPathInZip(pathPrefix string, zipPath *zip.File) bool {
7878
// Check if (pathPrefix + "/") is a prefix in f.Name, if yes, we extract this file.
7979

8080
zipPathIsFile := !zipPath.FileInfo().IsDir()
81-
return (zipPathIsFile && zipPath.Name == pathPrefix) || strings.Index(zipPath.Name, pathPrefix + "/") == 0
81+
return (zipPathIsFile && zipPath.Name == pathPrefix) || strings.Index(zipPath.Name, pathPrefix+"/") == 0
8282
}
8383

8484
// Decompress the file at zipFileAbsPath and move only those files under filesToExtractFromZipPath to localPath

file_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

33
import (
4+
"fmt"
5+
"io/ioutil"
46
"os"
5-
"testing"
67
"path/filepath"
7-
"io/ioutil"
8-
"fmt"
98
"strings"
9+
"testing"
1010
)
1111

1212
// Although other tests besides those in this file require this env var, this init() func will cover all tests.
@@ -28,11 +28,11 @@ func TestDownloadGitTagZipFile(t *testing.T) {
2828

2929
enterpriseGitHubExample := GitHubInstance{
3030
BaseUrl: "github.acme.com",
31-
ApiUrl: "github.acme.com/api/v3",
31+
ApiUrl: "github.acme.com/api/v3",
3232
}
3333

3434
cases := []struct {
35-
instance GitHubInstance
35+
instance GitHubInstance
3636
repoOwner string
3737
repoName string
3838
gitTag string
@@ -47,7 +47,7 @@ func TestDownloadGitTagZipFile(t *testing.T) {
4747
gitHubCommit := GitHubCommit{
4848
Repo: GitHubRepo{
4949
Owner: tc.repoOwner,
50-
Name: tc.repoName,
50+
Name: tc.repoName,
5151
},
5252
GitTag: tc.gitTag,
5353
}
@@ -95,7 +95,7 @@ func TestDownloadGitBranchZipFile(t *testing.T) {
9595
}
9696

9797
cases := []struct {
98-
instance GitHubInstance
98+
instance GitHubInstance
9999
repoOwner string
100100
repoName string
101101
branchName string
@@ -109,7 +109,7 @@ func TestDownloadGitBranchZipFile(t *testing.T) {
109109
gitHubCommit := GitHubCommit{
110110
Repo: GitHubRepo{
111111
Owner: tc.repoOwner,
112-
Name: tc.repoName,
112+
Name: tc.repoName,
113113
},
114114
BranchName: tc.branchName,
115115
}
@@ -135,7 +135,7 @@ func TestDownloadBadGitBranchZipFile(t *testing.T) {
135135
}
136136

137137
cases := []struct {
138-
instance GitHubInstance
138+
instance GitHubInstance
139139
repoOwner string
140140
repoName string
141141
branchName string
@@ -148,7 +148,7 @@ func TestDownloadBadGitBranchZipFile(t *testing.T) {
148148
gitHubCommit := GitHubCommit{
149149
Repo: GitHubRepo{
150150
Owner: tc.repoOwner,
151-
Name: tc.repoName,
151+
Name: tc.repoName,
152152
},
153153
BranchName: tc.branchName,
154154
}
@@ -170,7 +170,7 @@ func TestDownloadGitCommitFile(t *testing.T) {
170170
}
171171

172172
cases := []struct {
173-
instance GitHubInstance
173+
instance GitHubInstance
174174
repoOwner string
175175
repoName string
176176
commitSha string
@@ -186,7 +186,7 @@ func TestDownloadGitCommitFile(t *testing.T) {
186186
gitHubCommit := GitHubCommit{
187187
Repo: GitHubRepo{
188188
Owner: tc.repoOwner,
189-
Name: tc.repoName,
189+
Name: tc.repoName,
190190
},
191191
CommitSha: tc.commitSha,
192192
}
@@ -212,7 +212,7 @@ func TestDownloadBadGitCommitFile(t *testing.T) {
212212
}
213213

214214
cases := []struct {
215-
instance GitHubInstance
215+
instance GitHubInstance
216216
repoOwner string
217217
repoName string
218218
commitSha string
@@ -230,7 +230,7 @@ func TestDownloadBadGitCommitFile(t *testing.T) {
230230
gitHubCommit := GitHubCommit{
231231
Repo: GitHubRepo{
232232
Owner: tc.repoOwner,
233-
Name: tc.repoName,
233+
Name: tc.repoName,
234234
},
235235
CommitSha: tc.commitSha,
236236
}
@@ -252,7 +252,7 @@ func TestDownloadZipFileWithBadRepoValues(t *testing.T) {
252252
}
253253

254254
cases := []struct {
255-
instance GitHubInstance
255+
instance GitHubInstance
256256
repoOwner string
257257
repoName string
258258
gitTag string
@@ -265,7 +265,7 @@ func TestDownloadZipFileWithBadRepoValues(t *testing.T) {
265265
gitHubCommit := GitHubCommit{
266266
Repo: GitHubRepo{
267267
Owner: tc.repoOwner,
268-
Name: tc.repoName,
268+
Name: tc.repoName,
269269
},
270270
GitTag: tc.gitTag,
271271
}
@@ -286,17 +286,17 @@ func TestExtractFiles(t *testing.T) {
286286
}
287287

288288
cases := []struct {
289-
instance GitHubInstance
289+
instance GitHubInstance
290290
localFilePath string
291291
filePathToExtract string
292292
expectedNumFiles int
293293
nonemptyFiles []string
294294
}{
295295
{publicGitHub, "test-fixtures/fetch-test-public-0.0.1.zip", "/", 1, nil},
296296
{publicGitHub, "test-fixtures/fetch-test-public-0.0.2.zip", "/", 2, nil},
297-
{publicGitHub, "test-fixtures/fetch-test-public-0.0.3.zip", "/", 4, []string{"/README.md"} },
297+
{publicGitHub, "test-fixtures/fetch-test-public-0.0.3.zip", "/", 4, []string{"/README.md"}},
298298
{publicGitHub, "test-fixtures/fetch-test-public-0.0.3.zip", "/folder", 2, nil},
299-
{publicGitHub, "test-fixtures/fetch-test-public-0.0.4.zip", "/aaa", 2, []string{"/hello.txt", "/subaaa/subhello.txt"} },
299+
{publicGitHub, "test-fixtures/fetch-test-public-0.0.4.zip", "/aaa", 2, []string{"/hello.txt", "/subaaa/subhello.txt"}},
300300
}
301301

302302
for _, tc := range cases {
@@ -315,21 +315,21 @@ func TestExtractFiles(t *testing.T) {
315315
// Count the number of files in the directory
316316
var numFiles int
317317
filepath.Walk(tempDir, func(path string, info os.FileInfo, err error) error {
318-
if ! info.IsDir() {
318+
if !info.IsDir() {
319319
numFiles++
320320
}
321321
return nil
322322
})
323323

324-
if (numFiles != tc.expectedNumFiles) {
324+
if numFiles != tc.expectedNumFiles {
325325
t.Fatalf("While extracting %s, expected to find %d file(s), but found %d. Local path = %s", tc.localFilePath, tc.expectedNumFiles, numFiles, tempDir)
326326
}
327327

328328
// Ensure that files declared to be non-empty are in fact non-empty
329329
filepath.Walk(tempDir, func(path string, info os.FileInfo, err error) error {
330330
relativeFilename := strings.TrimPrefix(path, tempDir)
331331

332-
if ! info.IsDir() && stringInSlice(relativeFilename, tc.nonemptyFiles) {
332+
if !info.IsDir() && stringInSlice(relativeFilename, tc.nonemptyFiles) {
333333
if info.Size() == 0 {
334334
t.Fatalf("Expected %s in %s to have non-zero file size, but found file size = %d.\n", relativeFilename, tc.localFilePath, info.Size())
335335
}
@@ -360,7 +360,7 @@ func TestExtractFilesExtractFile(t *testing.T) {
360360
filepath.Walk(tempDir, func(path string, info os.FileInfo, err error) error {
361361
relativeFilename := strings.TrimPrefix(path, tempDir)
362362

363-
if ! info.IsDir() {
363+
if !info.IsDir() {
364364
if relativeFilename != localFileName {
365365
t.Fatalf("Expected local file %s to be created, but not found.\n", localFileName)
366366
}

github.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func ParseUrlIntoGithubInstance(repoUrl string, apiv string) (GitHubInstance, *F
7878

7979
u, err := url.Parse(repoUrl)
8080
if err != nil {
81-
return instance, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", repoUrl))
81+
return instance, newError(githubRepoUrlMalformedOrNotParseable, fmt.Sprintf("GitHub Repo URL %s is malformed.", repoUrl))
8282
}
8383

8484
baseUrl := u.Host
@@ -138,12 +138,12 @@ func ParseUrlIntoGitHubRepo(url string, token string, instance GitHubInstance) (
138138

139139
regex, regexErr := regexp.Compile("https?://(?:www\\.)?" + instance.BaseUrl + "/(.+?)/(.+?)(?:$|\\?|#|/)")
140140
if regexErr != nil {
141-
return gitHubRepo, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s is malformed.", url))
141+
return gitHubRepo, newError(githubRepoUrlMalformedOrNotParseable, fmt.Sprintf("GitHub Repo URL %s is malformed.", url))
142142
}
143143

144144
matches := regex.FindStringSubmatch(url)
145145
if len(matches) != 3 {
146-
return gitHubRepo, newError(GITHUB_REPO_URL_MALFORMED_OR_NOT_PARSEABLE, fmt.Sprintf("GitHub Repo URL %s could not be parsed correctly", url))
146+
return gitHubRepo, newError(githubRepoUrlMalformedOrNotParseable, fmt.Sprintf("GitHub Repo URL %s could not be parsed correctly", url))
147147
}
148148

149149
gitHubRepo = GitHubRepo{
@@ -239,7 +239,7 @@ func callGitHubApi(repo GitHubRepo, path string, customHeaders map[string]string
239239

240240
type writeCounter struct {
241241
written uint64
242-
suffix string // contains " / SIZE MB" if size is known, otherwise empty
242+
suffix string // contains " / SIZE MB" if size is known, otherwise empty
243243
}
244244

245245
func newWriteCounter(total int64) *writeCounter {
@@ -279,7 +279,7 @@ func writeResonseToDisk(resp *http.Response, destPath string, withProgress bool)
279279
defer resp.Body.Close()
280280

281281
var readCloser io.Reader
282-
if withProgress{
282+
if withProgress {
283283
readCloser = io.TeeReader(resp.Body, newWriteCounter(resp.ContentLength))
284284
} else {
285285
readCloser = resp.Body

0 commit comments

Comments
 (0)