Skip to content

Commit

Permalink
refactor: run gofmt across all files
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Nov 5, 2024
1 parent d99d25f commit 36ec534
Show file tree
Hide file tree
Showing 40 changed files with 361 additions and 363 deletions.
2 changes: 0 additions & 2 deletions artifact/image/symlink/symlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"github.com/google/osv-scalibr/artifact/image/symlink"
)

var ()

func TestTargetOutsideRoot(t *testing.T) {

tests := []struct {
Expand Down
20 changes: 10 additions & 10 deletions artifact/image/unpack/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,24 @@ func TestUnpackSquashed(t *testing.T) {
dir: mustMkdirTemp(t),
image: mustImageFromPath(t, filepath.Join("testdata", "basic.tar")),
want: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0644)},
"larger-sample.txt": contentAndMode{content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0644)},
"larger-sample.txt": {content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
},
}, {
name: "large files are skipped",
cfg: unpack.DefaultUnpackerConfig().WithMaxFileBytes(1024),
dir: mustMkdirTemp(t),
image: mustImageFromPath(t, filepath.Join("testdata", "basic.tar")),
want: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0644)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0644)},
},
}, {
name: "image with restricted file permissions",
cfg: unpack.DefaultUnpackerConfig(),
dir: mustMkdirTemp(t),
image: mustImageFromPath(t, filepath.Join("testdata", "permissions.tar")),
want: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0600)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0600)},
},
}, {
name: "image with symlinks",
Expand Down Expand Up @@ -352,12 +352,12 @@ func TestUnpackLayers(t *testing.T) {
want: []digestAndContent{{
digest: "SQUASHED",
content: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0600)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0600)},
},
}, {
digest: "sha256:854d994f7942ac6711ff410417b58270562d322a251be74df7829c15ec31e369",
content: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0600)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0600)},
},
}},
}, {
Expand All @@ -368,18 +368,18 @@ func TestUnpackLayers(t *testing.T) {
want: []digestAndContent{{
digest: "SQUASHED",
content: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0644)},
"larger-sample.txt": contentAndMode{content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0644)},
"larger-sample.txt": {content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
},
}, {
digest: "sha256:abfb541589db284238458b23f1607a184905159aa161c7325b725b4e2eaa1c2c",
content: map[string]contentAndMode{
"sample.txt": contentAndMode{content: "sample text file\n", mode: fs.FileMode(0644)},
"sample.txt": {content: "sample text file\n", mode: fs.FileMode(0644)},
},
}, {
digest: "sha256:c2df653a81c5c96005972035fa076987c9e450e54a03de57aabdadc00e4939c4",
content: map[string]contentAndMode{
"larger-sample.txt": contentAndMode{content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
"larger-sample.txt": {content: strings.Repeat("sample text file\n", 400), mode: fs.FileMode(0644)},
},
}},
}, {
Expand Down
18 changes: 9 additions & 9 deletions artifact/image/whiteout/whiteout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestWhiteout(t *testing.T) {
},
dirs: []string{},
want: map[string]struct{}{
".wh.hello_world.txt": struct{}{},
".wh.hello_world.txt": {},
},
},
{
Expand All @@ -64,8 +64,8 @@ func TestWhiteout(t *testing.T) {
},
dirs: []string{},
want: map[string]struct{}{
".wh.foo.txt": struct{}{},
".wh.bar.txt": struct{}{},
".wh.foo.txt": {},
".wh.bar.txt": {},
},
},
{
Expand All @@ -80,8 +80,8 @@ func TestWhiteout(t *testing.T) {
"dir2",
},
want: map[string]struct{}{
"dir1/.wh.foo.txt": struct{}{},
"dir2/.wh.bar.txt": struct{}{},
"dir1/.wh.foo.txt": {},
"dir2/.wh.bar.txt": {},
},
},
{
Expand All @@ -93,7 +93,7 @@ func TestWhiteout(t *testing.T) {
"dir1",
},
want: map[string]struct{}{
".wh..wh..opa.dir1": struct{}{},
".wh..wh..opa.dir1": {},
},
},
{
Expand All @@ -110,9 +110,9 @@ func TestWhiteout(t *testing.T) {
"dir3/dir4",
},
want: map[string]struct{}{
".wh..wh..opa.dir1": struct{}{},
".wh..wh..opa.dir2": struct{}{},
"dir3/dir4/.wh.bar.txt": struct{}{},
".wh..wh..opa.dir1": {},
".wh..wh..opa.dir2": {},
"dir3/dir4/.wh.bar.txt": {},
},
},
}
Expand Down
60 changes: 30 additions & 30 deletions binary/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,27 +187,27 @@ func TestGetScanConfig_ScanRoots(t *testing.T) {
{
desc: "Default scan roots",
flags: map[string]*cli.Flags{
"darwin": &cli.Flags{},
"linux": &cli.Flags{},
"windows": &cli.Flags{},
"darwin": {},
"linux": {},
"windows": {},
},
wantScanRoots: map[string][]string{
"darwin": []string{"/"},
"linux": []string{"/"},
"windows": []string{"C:\\"},
"darwin": {"/"},
"linux": {"/"},
"windows": {"C:\\"},
},
},
{
desc: "Scan root are provided and used",
flags: map[string]*cli.Flags{
"darwin": &cli.Flags{Root: "/root"},
"linux": &cli.Flags{Root: "/root"},
"windows": &cli.Flags{Root: "C:\\myroot"},
"darwin": {Root: "/root"},
"linux": {Root: "/root"},
"windows": {Root: "C:\\myroot"},
},
wantScanRoots: map[string][]string{
"darwin": []string{"/root"},
"linux": []string{"/root"},
"windows": []string{"C:\\myroot"},
"darwin": {"/root"},
"linux": {"/root"},
"windows": {"C:\\myroot"},
},
},
} {
Expand Down Expand Up @@ -246,58 +246,58 @@ func TestGetScanConfig_DirsToSkip(t *testing.T) {
{
desc: "Skip default dirs",
flags: map[string]*cli.Flags{
"darwin": &cli.Flags{Root: "/"},
"linux": &cli.Flags{Root: "/"},
"windows": &cli.Flags{Root: "C:\\"},
"darwin": {Root: "/"},
"linux": {Root: "/"},
"windows": {Root: "C:\\"},
},
wantDirsToSkip: map[string][]string{
"darwin": []string{"/dev", "/proc", "/sys"},
"linux": []string{"/dev", "/proc", "/sys"},
"windows": []string{"C:\\Windows"},
"darwin": {"/dev", "/proc", "/sys"},
"linux": {"/dev", "/proc", "/sys"},
"windows": {"C:\\Windows"},
},
},
{
desc: "Skip additional dirs",
flags: map[string]*cli.Flags{
"darwin": &cli.Flags{
"darwin": {
Root: "/",
DirsToSkip: []string{"/boot,/mnt,C:\\boot", "C:\\mnt"},
},
"linux": &cli.Flags{
"linux": {
Root: "/",
DirsToSkip: []string{"/boot,/mnt", "C:\\boot,C:\\mnt"},
},
"windows": &cli.Flags{
"windows": {
Root: "C:\\",
DirsToSkip: []string{"C:\\boot,C:\\mnt"},
},
},
wantDirsToSkip: map[string][]string{
"darwin": []string{"/dev", "/proc", "/sys", "/boot", "/mnt"},
"linux": []string{"/dev", "/proc", "/sys", "/boot", "/mnt"},
"windows": []string{"C:\\Windows", "C:\\boot", "C:\\mnt"},
"darwin": {"/dev", "/proc", "/sys", "/boot", "/mnt"},
"linux": {"/dev", "/proc", "/sys", "/boot", "/mnt"},
"windows": {"C:\\Windows", "C:\\boot", "C:\\mnt"},
},
},
{
desc: "Ignore paths outside root",
flags: map[string]*cli.Flags{
"darwin": &cli.Flags{
"darwin": {
Root: "/root",
DirsToSkip: []string{"/root/dir1,/dir2"},
},
"linux": &cli.Flags{
"linux": {
Root: "/root",
DirsToSkip: []string{"/root/dir1,/dir2"},
},
"windows": &cli.Flags{
"windows": {
Root: "C:\\root",
DirsToSkip: []string{"C:\\root\\dir1,c:\\dir2"},
},
},
wantDirsToSkip: map[string][]string{
"darwin": []string{"/root/dir1"},
"linux": []string{"/root/dir1"},
"windows": []string{"C:\\root\\dir1"},
"darwin": {"/root/dir1"},
"linux": {"/root/dir1"},
"windows": {"C:\\root\\dir1"},
},
},
} {
Expand Down
Loading

0 comments on commit 36ec534

Please sign in to comment.