Skip to content

Commit

Permalink
fix: format with go fmt ./...
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornplusplus committed Aug 17, 2023
1 parent f39d70d commit 020f62b
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 95 deletions.
3 changes: 1 addition & 2 deletions cmd/chisel/cmd_version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package main

import (
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions cmd/chisel/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package main

import (
Expand All @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions cmd/chisel/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions internal/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}, {
Expand Down
1 change: 1 addition & 0 deletions internal/archive/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions internal/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion internal/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/control/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/control/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
}}
Expand Down
1 change: 0 additions & 1 deletion internal/control/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ func Test(t *testing.T) { TestingT(t) }
type S struct{}

var _ = Suite(&S{})

8 changes: 4 additions & 4 deletions internal/deb/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/"},
Expand Down
7 changes: 4 additions & 3 deletions internal/deb/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
44 changes: 22 additions & 22 deletions internal/deb/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
} {
Expand Down
2 changes: 1 addition & 1 deletion internal/fsutil/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var createTests = []createTest{{
Mode: fs.ModeDir | fs.ModeSticky | 0775,
},
result: map[string]string{
"/tmp/": "dir 01775",
"/tmp/": "dir 01775",
},
}}

Expand Down
42 changes: 20 additions & 22 deletions internal/jsonwall/jsonwall.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
//
// 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
// optimize for searching and iteration.
//
// 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
// tagged with `omitempty`.
//
// 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 (
Expand Down
2 changes: 1 addition & 1 deletion internal/jsonwall/jsonwall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var dataTypeTests = []struct {
}},
}, {
summary: "Invalid add request",
values: []any{
values: []any{
42,
},
dbError: "invalid database value: 42",
Expand Down
4 changes: 2 additions & 2 deletions internal/setup/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/setup/fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}

Expand Down
1 change: 0 additions & 1 deletion internal/strdist/export_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package strdist


var GlobCost = globCost
8 changes: 3 additions & 5 deletions internal/strdist/strdist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "**", "⁑")
Expand All @@ -128,4 +127,3 @@ func globCost(ar, br rune) Cost {
}
return Cost{SwapAB: 1, DeleteA: 1, InsertB: 1}
}

9 changes: 5 additions & 4 deletions internal/testutil/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 020f62b

Please sign in to comment.