From 020f62b41ae3952b322d2fc95ce9c1950dfeefe9 Mon Sep 17 00:00:00 2001 From: Rafid Bin Mostofa Date: Thu, 17 Aug 2023 18:22:40 +0600 Subject: [PATCH] fix: format with ``go fmt ./...`` --- cmd/chisel/cmd_version.go | 3 +- cmd/chisel/main.go | 3 -- cmd/chisel/main_test.go | 8 +++--- internal/archive/archive_test.go | 8 +++--- internal/archive/export_test.go | 1 + internal/cache/cache_test.go | 3 +- internal/control/control.go | 1 - internal/control/helpers.go | 2 +- internal/control/helpers_test.go | 8 +++--- internal/control/suite_test.go | 1 - internal/deb/extract_test.go | 8 +++--- internal/deb/version.go | 7 +++-- internal/deb/version_test.go | 44 +++++++++++++++--------------- internal/fsutil/create_test.go | 2 +- internal/jsonwall/jsonwall.go | 42 ++++++++++++++-------------- internal/jsonwall/jsonwall_test.go | 2 +- internal/setup/fetch.go | 4 +-- internal/setup/fetch_test.go | 4 +-- internal/strdist/export_test.go | 1 - internal/strdist/strdist.go | 8 ++---- internal/testutil/exec.go | 9 +++--- internal/testutil/intcheckers.go | 18 ++++++++---- 22 files changed, 92 insertions(+), 95 deletions(-) diff --git a/cmd/chisel/cmd_version.go b/cmd/chisel/cmd_version.go index 2258aebc..703f164b 100644 --- a/cmd/chisel/cmd_version.go +++ b/cmd/chisel/cmd_version.go @@ -1,4 +1,3 @@ - package main import ( @@ -14,7 +13,7 @@ var longVersionHelp = ` The version command displays the versions of the running client and server. ` -type cmdVersion struct {} +type cmdVersion struct{} func init() { addCommand("version", shortVersionHelp, longVersionHelp, func() flags.Commander { return &cmdVersion{} }, nil, nil) diff --git a/cmd/chisel/main.go b/cmd/chisel/main.go index bfaa556b..466d3d1c 100644 --- a/cmd/chisel/main.go +++ b/cmd/chisel/main.go @@ -1,4 +1,3 @@ - package main import ( @@ -18,9 +17,7 @@ import ( "github.com/canonical/chisel/internal/deb" "github.com/canonical/chisel/internal/setup" "github.com/canonical/chisel/internal/slicer" - //"github.com/canonical/chisel/internal/logger" - ) var ( diff --git a/cmd/chisel/main_test.go b/cmd/chisel/main_test.go index eb0e0d0a..afcdc1ae 100644 --- a/cmd/chisel/main_test.go +++ b/cmd/chisel/main_test.go @@ -20,10 +20,10 @@ func Test(t *testing.T) { TestingT(t) } type BaseChiselSuite struct { testutil.BaseTest - stdin *bytes.Buffer - stdout *bytes.Buffer - stderr *bytes.Buffer - password string + stdin *bytes.Buffer + stdout *bytes.Buffer + stderr *bytes.Buffer + password string } func (s *BaseChiselSuite) readPassword(fd int) ([]byte, error) { diff --git a/internal/archive/archive_test.go b/internal/archive/archive_test.go index a94c73a3..37b97ac5 100644 --- a/internal/archive/archive_test.go +++ b/internal/archive/archive_test.go @@ -142,10 +142,10 @@ var optionErrorTests = []optionErrorTest{{ error: `archive has no component "other"`, }, { options: archive.Options{ - Label: "ubuntu", - Version: "22.04", - Arch: "amd64", - Suites: []string{"jammy"}, + Label: "ubuntu", + Version: "22.04", + Arch: "amd64", + Suites: []string{"jammy"}, }, error: "archive options missing components", }, { diff --git a/internal/archive/export_test.go b/internal/archive/export_test.go index fe7c62fb..cd75d5f4 100644 --- a/internal/archive/export_test.go +++ b/internal/archive/export_test.go @@ -16,5 +16,6 @@ func FakeDo(do func(req *http.Request) (*http.Response, error)) (restore func()) } type Credentials = credentials + var FindCredentials = findCredentials var FindCredentialsInDir = findCredentialsInDir diff --git a/internal/cache/cache_test.go b/internal/cache/cache_test.go index f8ee78d3..381edcda 100644 --- a/internal/cache/cache_test.go +++ b/internal/cache/cache_test.go @@ -42,7 +42,6 @@ func (s *S) TestDefaultDir(c *C) { c.Assert(strings.HasSuffix(defaultDir, "/foo/bar"), Equals, true) } - func (s *S) TestCacheEmpty(c *C) { cc := cache.Cache{c.MkDir()} @@ -129,7 +128,7 @@ func (s *S) TestCacheWrongDigest(c *C) { _, err := w.Write([]byte("data2")) errClose := w.Close() c.Assert(err, IsNil) - c.Assert(errClose, ErrorMatches, "expected digest " + data1Digest + ", got " + data2Digest) + c.Assert(errClose, ErrorMatches, "expected digest "+data1Digest+", got "+data2Digest) _, err = cc.Read(data1Digest) c.Assert(err, Equals, cache.MissErr) diff --git a/internal/control/control.go b/internal/control/control.go index adb4b757..5bcb4446 100644 --- a/internal/control/control.go +++ b/internal/control/control.go @@ -7,7 +7,6 @@ import ( "strings" ) - // The logic in this file is supposed to be fast so that parsing large data // files feels instantaneous. It does that by performing a fast scan once to // index the sections, and then rather than parsing the individual sections it diff --git a/internal/control/helpers.go b/internal/control/helpers.go index b2183d3a..118c98c2 100644 --- a/internal/control/helpers.go +++ b/internal/control/helpers.go @@ -11,7 +11,7 @@ var pathInfoExp = regexp.MustCompile(`([a-f0-9]{32,}) +([0-9]+) +\S+`) func ParsePathInfo(table, path string) (digest string, size int, ok bool) { pos := strings.Index(table, " "+path+"\n") if pos == -1 { - if !strings.HasSuffix(table, " " + path) { + if !strings.HasSuffix(table, " "+path) { return "", -1, false } pos = len(table) - len(path) diff --git a/internal/control/helpers_test.go b/internal/control/helpers_test.go index dd81666d..00d78ea3 100644 --- a/internal/control/helpers_test.go +++ b/internal/control/helpers_test.go @@ -39,21 +39,21 @@ var parsePathInfoTests = []parsePathInfoTest{{ size: 2, digest: "0123456789abcdef0123456789abcdef", }, { - table: `0123456789abcdef0123456789abcdef 0 /the/path`, + table: `0123456789abcdef0123456789abcdef 0 /the/path`, path: "/the/path", size: 0, digest: "0123456789abcdef0123456789abcdef", }, { - table: `0123456789abcdef0123456789abcdef 555 /the/path`, + table: `0123456789abcdef0123456789abcdef 555 /the/path`, path: "/the/path", size: 555, digest: "0123456789abcdef0123456789abcdef", }, { - table: `deadbeef 0 /the/path`, + table: `deadbeef 0 /the/path`, path: "/the/path", digest: "", }, { - table: `bad-data 0 /the/path`, + table: `bad-data 0 /the/path`, path: "/the/path", digest: "", }} diff --git a/internal/control/suite_test.go b/internal/control/suite_test.go index 16fc7777..0cfdcc6a 100644 --- a/internal/control/suite_test.go +++ b/internal/control/suite_test.go @@ -11,4 +11,3 @@ func Test(t *testing.T) { TestingT(t) } type S struct{} var _ = Suite(&S{}) - diff --git a/internal/deb/extract_test.go b/internal/deb/extract_test.go index 9cc79df9..3147dc36 100644 --- a/internal/deb/extract_test.go +++ b/internal/deb/extract_test.go @@ -149,10 +149,10 @@ var extractTests = []extractTest{{ }, }, result: map[string]string{ - "/etc/": "dir 0755", - "/etc/dpkg/": "dir 0755", - "/etc/default/": "dir 0755", - "/etc/debian_version": "file 0644 cce26cfe", + "/etc/": "dir 0755", + "/etc/dpkg/": "dir 0755", + "/etc/default/": "dir 0755", + "/etc/debian_version": "file 0644 cce26cfe", }, globbed: map[string][]string{ "/etc/dp*/": []string{"/etc/dpkg/"}, diff --git a/internal/deb/version.go b/internal/deb/version.go index dbaf4500..13d6d604 100644 --- a/internal/deb/version.go +++ b/internal/deb/version.go @@ -150,9 +150,10 @@ func compareSubversion(va, vb string) int { // CompareVersions compare two version strings that follow the debian // version policy and // Returns: -// -1 if a is smaller than b -// 0 if a equals b -// +1 if a is bigger than b +// +// -1 if a is smaller than b +// 0 if a equals b +// +1 if a is bigger than b func CompareVersions(va, vb string) int { var sa, sb string if ia := strings.IndexByte(va, '-'); ia < 0 { diff --git a/internal/deb/version_test.go b/internal/deb/version_test.go index 1596bb3f..5af10151 100644 --- a/internal/deb/version_test.go +++ b/internal/deb/version_test.go @@ -71,28 +71,28 @@ func (s *VersionTestSuite) TestVersionCompare(c *C) { {"1.0", "1.0-0+b1", -1}, {"1.0", "1.0-0~", 1}, // from the old perl cupt - {"1.2.3", "1.2.3", 0}, // identical - {"4.4.3-2", "4.4.3-2", 0}, // identical - {"1.2.3", "1.2.3-0", 0}, // zero revision - {"009", "9", 0}, // zeroes… - {"009ab5", "9ab5", 0}, // there as well - {"1.2.3", "1.2.3-1", -1}, // added non-zero revision - {"1.2.3", "1.2.4", -1}, // just bigger - {"1.2.4", "1.2.3", 1}, // order doesn't matter - {"1.2.24", "1.2.3", 1}, // bigger, eh? - {"0.10.0", "0.8.7", 1}, // bigger, eh? - {"3.2", "2.3", 1}, // major number rocks - {"1.3.2a", "1.3.2", 1}, // letters rock - {"0.5.0~git", "0.5.0~git2", -1}, // numbers rock - {"2a", "21", -1}, // but not in all places - {"1.2a+~bCd3", "1.2a++", -1}, // tilde doesn't rock - {"1.2a+~bCd3", "1.2a+~", 1}, // but first is longer! - {"5.10.0", "5.005", 1}, // preceding zeroes don't matters - {"3a9.8", "3.10.2", -1}, // letters are before all letter symbols - {"3a9.8", "3~10", 1}, // but after the tilde - {"1.4+OOo3.0.0~", "1.4+OOo3.0.0-4", -1}, // another tilde check - {"2.4.7-1", "2.4.7-z", -1}, // revision comparing - {"1.002-1+b2", "1.00", 1}, // whatever... + {"1.2.3", "1.2.3", 0}, // identical + {"4.4.3-2", "4.4.3-2", 0}, // identical + {"1.2.3", "1.2.3-0", 0}, // zero revision + {"009", "9", 0}, // zeroes… + {"009ab5", "9ab5", 0}, // there as well + {"1.2.3", "1.2.3-1", -1}, // added non-zero revision + {"1.2.3", "1.2.4", -1}, // just bigger + {"1.2.4", "1.2.3", 1}, // order doesn't matter + {"1.2.24", "1.2.3", 1}, // bigger, eh? + {"0.10.0", "0.8.7", 1}, // bigger, eh? + {"3.2", "2.3", 1}, // major number rocks + {"1.3.2a", "1.3.2", 1}, // letters rock + {"0.5.0~git", "0.5.0~git2", -1}, // numbers rock + {"2a", "21", -1}, // but not in all places + {"1.2a+~bCd3", "1.2a++", -1}, // tilde doesn't rock + {"1.2a+~bCd3", "1.2a+~", 1}, // but first is longer! + {"5.10.0", "5.005", 1}, // preceding zeroes don't matters + {"3a9.8", "3.10.2", -1}, // letters are before all letter symbols + {"3a9.8", "3~10", 1}, // but after the tilde + {"1.4+OOo3.0.0~", "1.4+OOo3.0.0-4", -1}, // another tilde check + {"2.4.7-1", "2.4.7-z", -1}, // revision comparing + {"1.002-1+b2", "1.00", 1}, // whatever... {"12-20220319-1ubuntu1", "12-20220319-1ubuntu2", -1}, // libgcc-s1 {"1:13.0.1-2ubuntu2", "1:13.0.1-2ubuntu3", -1}, } { diff --git a/internal/fsutil/create_test.go b/internal/fsutil/create_test.go index fe9f2a4d..238a8d34 100644 --- a/internal/fsutil/create_test.go +++ b/internal/fsutil/create_test.go @@ -53,7 +53,7 @@ var createTests = []createTest{{ Mode: fs.ModeDir | fs.ModeSticky | 0775, }, result: map[string]string{ - "/tmp/": "dir 01775", + "/tmp/": "dir 01775", }, }} diff --git a/internal/jsonwall/jsonwall.go b/internal/jsonwall/jsonwall.go index cd601826..668eb69f 100644 --- a/internal/jsonwall/jsonwall.go +++ b/internal/jsonwall/jsonwall.go @@ -1,4 +1,3 @@ -// // Package jsonwall provides an interface to work with database files in the simple // "jsonwall" format, which consists of a text file with one JSON object per line, // where both the individual JSON fields and the lines themselves are sorted to @@ -6,17 +5,17 @@ // // For example, the following content represents a valid jsonwall database: // -// {"jsonwall":"1.0","count":3} -// {"kind":"app","name":"chisel","version":"1.0"} -// {"kind":"app","name":"pebble","version":"1.2"} +// {"jsonwall":"1.0","count":3} +// {"kind":"app","name":"chisel","version":"1.0"} +// {"kind":"app","name":"pebble","version":"1.2"} // // The entries in this database might be manipulated with a type such as: // -// type AppEntry struct { -// Kind string `json:"kind"` -// Name string `json:"name,omitempty"` -// Version string `json:"version,omitempty"` -// } +// type AppEntry struct { +// Kind string `json:"kind"` +// Name string `json:"name,omitempty"` +// Version string `json:"version,omitempty"` +// } // // Such data types have two important characteristics: fields must be defined in // the order that will be used when searching, and every optional field must be @@ -24,22 +23,21 @@ // // With that in place, the database may be accessed as: // -// app := AppEntry{Kind: "app", Name: "chisel"} -// if db.Get(&app) == nil { -// fmt.Println(app.Name, "version:", app.Version) -// } +// app := AppEntry{Kind: "app", Name: "chisel"} +// if db.Get(&app) == nil { +// fmt.Println(app.Name, "version:", app.Version) +// } // // Iteration works similarly: // -// app := AppEntry{Kind: "app"} -// if iter, err := db.Iter(&app); err == nil { -// for iter.Next() { -// if iter.Get(&app) == nil { -// fmt.Println(app.Name, "version:", app.Version) -// } -// } -// } -// +// app := AppEntry{Kind: "app"} +// if iter, err := db.Iter(&app); err == nil { +// for iter.Next() { +// if iter.Get(&app) == nil { +// fmt.Println(app.Name, "version:", app.Version) +// } +// } +// } package jsonwall import ( diff --git a/internal/jsonwall/jsonwall_test.go b/internal/jsonwall/jsonwall_test.go index 8a71dbbf..9e436ed1 100644 --- a/internal/jsonwall/jsonwall_test.go +++ b/internal/jsonwall/jsonwall_test.go @@ -150,7 +150,7 @@ var dataTypeTests = []struct { }}, }, { summary: "Invalid add request", - values: []any{ + values: []any{ 42, }, dbError: "invalid database value: 42", diff --git a/internal/setup/fetch.go b/internal/setup/fetch.go index a18190e6..b39409fe 100644 --- a/internal/setup/fetch.go +++ b/internal/setup/fetch.go @@ -38,7 +38,7 @@ func FetchRelease(options *FetchOptions) (*Release, error) { cacheDir = cache.DefaultDir("chisel") } - dirName := filepath.Join(cacheDir, "releases", options.Label + "-" + options.Version) + dirName := filepath.Join(cacheDir, "releases", options.Label+"-"+options.Version) err := os.MkdirAll(dirName, 0755) if err == nil { lockFile := fslock.New(filepath.Join(cacheDir, "releases", ".lock")) @@ -57,7 +57,7 @@ func FetchRelease(options *FetchOptions) (*Release, error) { return nil, err } - req, err := http.NewRequest("GET", baseURL + options.Label + "-" + options.Version, nil) + req, err := http.NewRequest("GET", baseURL+options.Label+"-"+options.Version, nil) if err != nil { return nil, fmt.Errorf("cannot create request for release information: %w", err) } diff --git a/internal/setup/fetch_test.go b/internal/setup/fetch_test.go index 6c50d9b6..f9fcdb75 100644 --- a/internal/setup/fetch_test.go +++ b/internal/setup/fetch_test.go @@ -14,8 +14,8 @@ import ( func (s *S) TestFetch(c *C) { options := &setup.FetchOptions{ - Label: "ubuntu", - Version: "22.04", + Label: "ubuntu", + Version: "22.04", CacheDir: c.MkDir(), } diff --git a/internal/strdist/export_test.go b/internal/strdist/export_test.go index 70eab754..1e983bb0 100644 --- a/internal/strdist/export_test.go +++ b/internal/strdist/export_test.go @@ -1,4 +1,3 @@ package strdist - var GlobCost = globCost diff --git a/internal/strdist/strdist.go b/internal/strdist/strdist.go index 8fc9afae..cd4ae3f2 100644 --- a/internal/strdist/strdist.go +++ b/internal/strdist/strdist.go @@ -103,10 +103,9 @@ func Distance(a, b string, f CostFunc, cut int64) int64 { // // Supported wildcards: // -// ? - Any one character, except for / -// * - Any zero or more characters, execept for / -// ** - Any zero or more characrers, including / -// +// ? - Any one character, except for / +// * - Any zero or more characters, execept for / +// ** - Any zero or more characrers, including / func GlobPath(a, b string) bool { a = strings.ReplaceAll(a, "**", "⁑") b = strings.ReplaceAll(b, "**", "⁑") @@ -128,4 +127,3 @@ func globCost(ar, br rune) Cost { } return Cost{SwapAB: 1, DeleteA: 1, InsertB: 1} } - diff --git a/internal/testutil/exec.go b/internal/testutil/exec.go index 066f5457..9003aa8f 100644 --- a/internal/testutil/exec.go +++ b/internal/testutil/exec.go @@ -157,10 +157,11 @@ func (cmd *FakeCmd) Restore() { // Calls returns a list of calls that were made to the fake command. // of the form: -// [][]string{ -// {"cmd", "arg1", "arg2"}, // first invocation of "cmd" -// {"cmd", "arg1", "arg2"}, // second invocation of "cmd" -// } +// +// [][]string{ +// {"cmd", "arg1", "arg2"}, // first invocation of "cmd" +// {"cmd", "arg1", "arg2"}, // second invocation of "cmd" +// } func (cmd *FakeCmd) Calls() [][]string { raw, err := ioutil.ReadFile(cmd.logFile) if os.IsNotExist(err) { diff --git a/internal/testutil/intcheckers.go b/internal/testutil/intcheckers.go index c2944d82..b0db10f8 100644 --- a/internal/testutil/intcheckers.go +++ b/internal/testutil/intcheckers.go @@ -59,35 +59,41 @@ func (checker *intChecker) Check(params []interface{}, names []string) (result b // IntLessThan checker verifies that one integer is less than other integer. // // For example: -// c.Assert(1, IntLessThan, 2) +// +// c.Assert(1, IntLessThan, 2) var IntLessThan = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntLessThan", Params: []string{"a", "b"}}, rel: "<"} // IntLessEqual checker verifies that one integer is less than or equal to other integer. // // For example: -// c.Assert(1, IntLessEqual, 1) +// +// c.Assert(1, IntLessEqual, 1) var IntLessEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntLessEqual", Params: []string{"a", "b"}}, rel: "<="} // IntEqual checker verifies that one integer is equal to other integer. // // For example: -// c.Assert(1, IntEqual, 1) +// +// c.Assert(1, IntEqual, 1) var IntEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntEqual", Params: []string{"a", "b"}}, rel: "=="} // IntNotEqual checker verifies that one integer is not equal to other integer. // // For example: -// c.Assert(1, IntNotEqual, 2) +// +// c.Assert(1, IntNotEqual, 2) var IntNotEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntNotEqual", Params: []string{"a", "b"}}, rel: "!="} // IntGreaterThan checker verifies that one integer is greater than other integer. // // For example: -// c.Assert(2, IntGreaterThan, 1) +// +// c.Assert(2, IntGreaterThan, 1) var IntGreaterThan = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntGreaterThan", Params: []string{"a", "b"}}, rel: ">"} // IntGreaterEqual checker verifies that one integer is greater than or equal to other integer. // // For example: -// c.Assert(1, IntGreaterEqual, 2) +// +// c.Assert(1, IntGreaterEqual, 2) var IntGreaterEqual = &intChecker{CheckerInfo: &check.CheckerInfo{Name: "IntGreaterEqual", Params: []string{"a", "b"}}, rel: ">="}