Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit ba8ee97

Browse files
committed
utils -> util
1 parent 6525657 commit ba8ee97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+114
-114
lines changed

cmd/root.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
"github.com/GoogleCloudPlatform/container-diff/differs"
2828
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
29-
"github.com/GoogleCloudPlatform/container-diff/utils"
29+
"github.com/GoogleCloudPlatform/container-diff/util"
3030
"github.com/docker/docker/client"
3131
"github.com/golang/glog"
3232
"github.com/pkg/errors"
@@ -56,7 +56,7 @@ func NewClient() (*client.Client, error) {
5656
return cli, nil
5757
}
5858

59-
func outputResults(resultMap map[string]utils.Result) {
59+
func outputResults(resultMap map[string]util.Result) {
6060
// Outputs diff/analysis results in alphabetical order by analyzer name
6161
sortedTypes := []string{}
6262
for analyzerType := range resultMap {
@@ -77,7 +77,7 @@ func outputResults(resultMap map[string]utils.Result) {
7777
}
7878
}
7979
if json {
80-
err := utils.JSONify(results)
80+
err := util.JSONify(results)
8181
if err != nil {
8282
glog.Error(err)
8383
}
@@ -159,5 +159,5 @@ func addSharedFlags(cmd *cobra.Command) {
159159
cmd.Flags().BoolVarP(&json, "json", "j", false, "JSON Output defines if the diff should be returned in a human readable format (false) or a JSON (true).")
160160
cmd.Flags().StringVarP(&types, "types", "t", "", "This flag sets the list of analyzer types to use. It expects a comma separated list of supported analyzers.")
161161
cmd.Flags().BoolVarP(&save, "save", "s", false, "Set this flag to save rather than remove the final image filesystems on exit.")
162-
cmd.Flags().BoolVarP(&utils.SortSize, "order", "o", false, "Set this flag to sort any file/package results by descending size. Otherwise, they will be sorted by name.")
162+
cmd.Flags().BoolVarP(&util.SortSize, "order", "o", false, "Set this flag to sort any file/package results by descending size. Otherwise, they will be sorted by name.")
163163
}

differs/apt_diff.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"strings"
2525

2626
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
27-
"github.com/GoogleCloudPlatform/container-diff/utils"
27+
"github.com/GoogleCloudPlatform/container-diff/util"
2828
"github.com/golang/glog"
2929
)
3030

@@ -36,19 +36,19 @@ func (a AptAnalyzer) Name() string {
3636
}
3737

3838
// AptDiff compares the packages installed by apt-get.
39-
func (a AptAnalyzer) Diff(image1, image2 pkgutil.Image) (utils.Result, error) {
39+
func (a AptAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
4040
diff, err := singleVersionDiff(image1, image2, a)
4141
return diff, err
4242
}
4343

44-
func (a AptAnalyzer) Analyze(image pkgutil.Image) (utils.Result, error) {
44+
func (a AptAnalyzer) Analyze(image pkgutil.Image) (util.Result, error) {
4545
analysis, err := singleVersionAnalysis(image, a)
4646
return analysis, err
4747
}
4848

49-
func (a AptAnalyzer) getPackages(image pkgutil.Image) (map[string]utils.PackageInfo, error) {
49+
func (a AptAnalyzer) getPackages(image pkgutil.Image) (map[string]util.PackageInfo, error) {
5050
path := image.FSPath
51-
packages := make(map[string]utils.PackageInfo)
51+
packages := make(map[string]util.PackageInfo)
5252
if _, err := os.Stat(path); err != nil {
5353
// invalid image directory path
5454
return packages, err
@@ -75,7 +75,7 @@ func (a AptAnalyzer) getPackages(image pkgutil.Image) (map[string]utils.PackageI
7575
return packages, nil
7676
}
7777

78-
func parseLine(text string, currPackage string, packages map[string]utils.PackageInfo) string {
78+
func parseLine(text string, currPackage string, packages map[string]util.PackageInfo) string {
7979
line := strings.Split(text, ": ")
8080
if len(line) == 2 {
8181
key := line[0]
@@ -92,7 +92,7 @@ func parseLine(text string, currPackage string, packages map[string]utils.Packag
9292
modifiedValue := strings.Replace(value, "+", " ", 1)
9393
currPackageInfo, ok := packages[currPackage]
9494
if !ok {
95-
currPackageInfo = utils.PackageInfo{}
95+
currPackageInfo = util.PackageInfo{}
9696
}
9797
currPackageInfo.Version = modifiedValue
9898
packages[currPackage] = currPackageInfo
@@ -101,7 +101,7 @@ func parseLine(text string, currPackage string, packages map[string]utils.Packag
101101
case "Installed-Size":
102102
currPackageInfo, ok := packages[currPackage]
103103
if !ok {
104-
currPackageInfo = utils.PackageInfo{}
104+
currPackageInfo = util.PackageInfo{}
105105
}
106106
var size int64
107107
var err error

differs/apt_diff_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,64 +21,64 @@ import (
2121
"testing"
2222

2323
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
24-
"github.com/GoogleCloudPlatform/container-diff/utils"
24+
"github.com/GoogleCloudPlatform/container-diff/util"
2525
)
2626

2727
func TestParseLine(t *testing.T) {
2828
testCases := []struct {
2929
descrip string
3030
line string
31-
packages map[string]utils.PackageInfo
31+
packages map[string]util.PackageInfo
3232
currPackage string
3333
expPackage string
34-
expected map[string]utils.PackageInfo
34+
expected map[string]util.PackageInfo
3535
}{
3636
{
3737
descrip: "Not applicable line",
3838
line: "Garbage: garbage info",
39-
packages: map[string]utils.PackageInfo{},
39+
packages: map[string]util.PackageInfo{},
4040
expPackage: "",
41-
expected: map[string]utils.PackageInfo{},
41+
expected: map[string]util.PackageInfo{},
4242
},
4343
{
4444
descrip: "Package line",
4545
line: "Package: La-Croix",
4646
currPackage: "Tea",
4747
expPackage: "La-Croix",
48-
packages: map[string]utils.PackageInfo{},
49-
expected: map[string]utils.PackageInfo{},
48+
packages: map[string]util.PackageInfo{},
49+
expected: map[string]util.PackageInfo{},
5050
},
5151
{
5252
descrip: "Version line",
5353
line: "Version: Lime",
54-
packages: map[string]utils.PackageInfo{},
54+
packages: map[string]util.PackageInfo{},
5555
currPackage: "La-Croix",
5656
expPackage: "La-Croix",
57-
expected: map[string]utils.PackageInfo{"La-Croix": {Version: "Lime"}},
57+
expected: map[string]util.PackageInfo{"La-Croix": {Version: "Lime"}},
5858
},
5959
{
6060
descrip: "Version line with deb release info",
6161
line: "Version: Lime+extra_lime",
62-
packages: map[string]utils.PackageInfo{},
62+
packages: map[string]util.PackageInfo{},
6363
currPackage: "La-Croix",
6464
expPackage: "La-Croix",
65-
expected: map[string]utils.PackageInfo{"La-Croix": {Version: "Lime extra_lime"}},
65+
expected: map[string]util.PackageInfo{"La-Croix": {Version: "Lime extra_lime"}},
6666
},
6767
{
6868
descrip: "Size line",
6969
line: "Installed-Size: 12",
70-
packages: map[string]utils.PackageInfo{},
70+
packages: map[string]util.PackageInfo{},
7171
currPackage: "La-Croix",
7272
expPackage: "La-Croix",
73-
expected: map[string]utils.PackageInfo{"La-Croix": {Size: 12288}},
73+
expected: map[string]util.PackageInfo{"La-Croix": {Size: 12288}},
7474
},
7575
{
7676
descrip: "Pre-existing PackageInfo struct",
7777
line: "Installed-Size: 12",
78-
packages: map[string]utils.PackageInfo{"La-Croix": {Version: "Lime"}},
78+
packages: map[string]util.PackageInfo{"La-Croix": {Version: "Lime"}},
7979
currPackage: "La-Croix",
8080
expPackage: "La-Croix",
81-
expected: map[string]utils.PackageInfo{"La-Croix": {Version: "Lime", Size: 12288}},
81+
expected: map[string]util.PackageInfo{"La-Croix": {Version: "Lime", Size: 12288}},
8282
},
8383
}
8484

@@ -97,24 +97,24 @@ func TestGetAptPackages(t *testing.T) {
9797
testCases := []struct {
9898
descrip string
9999
path string
100-
expected map[string]utils.PackageInfo
100+
expected map[string]util.PackageInfo
101101
err bool
102102
}{
103103
{
104104
descrip: "no directory",
105105
path: "testDirs/notThere",
106-
expected: map[string]utils.PackageInfo{},
106+
expected: map[string]util.PackageInfo{},
107107
err: true,
108108
},
109109
{
110110
descrip: "no packages",
111111
path: "testDirs/noPackages",
112-
expected: map[string]utils.PackageInfo{},
112+
expected: map[string]util.PackageInfo{},
113113
},
114114
{
115115
descrip: "packages in expected location",
116116
path: "testDirs/packageOne",
117-
expected: map[string]utils.PackageInfo{
117+
expected: map[string]util.PackageInfo{
118118
"pac1": {Version: "1.0"},
119119
"pac2": {Version: "2.0"},
120120
"pac3": {Version: "3.0"}},

differs/differs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222

2323
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
24-
"github.com/GoogleCloudPlatform/container-diff/utils"
24+
"github.com/GoogleCloudPlatform/container-diff/util"
2525
"github.com/golang/glog"
2626
)
2727

@@ -37,8 +37,8 @@ type SingleRequest struct {
3737
}
3838

3939
type Analyzer interface {
40-
Diff(image1, image2 pkgutil.Image) (utils.Result, error)
41-
Analyze(image pkgutil.Image) (utils.Result, error)
40+
Diff(image1, image2 pkgutil.Image) (util.Result, error)
41+
Analyze(image pkgutil.Image) (util.Result, error)
4242
Name() string
4343
}
4444

@@ -50,12 +50,12 @@ var Analyzers = map[string]Analyzer{
5050
"node": NodeAnalyzer{},
5151
}
5252

53-
func (req DiffRequest) GetDiff() (map[string]utils.Result, error) {
53+
func (req DiffRequest) GetDiff() (map[string]util.Result, error) {
5454
img1 := req.Image1
5555
img2 := req.Image2
5656
diffs := req.DiffTypes
5757

58-
results := map[string]utils.Result{}
58+
results := map[string]util.Result{}
5959
for _, differ := range diffs {
6060
if diff, err := differ.Diff(img1, img2); err == nil {
6161
results[differ.Name()] = diff
@@ -74,11 +74,11 @@ func (req DiffRequest) GetDiff() (map[string]utils.Result, error) {
7474
return results, err
7575
}
7676

77-
func (req SingleRequest) GetAnalysis() (map[string]utils.Result, error) {
77+
func (req SingleRequest) GetAnalysis() (map[string]util.Result, error) {
7878
img := req.Image
7979
analyses := req.AnalyzeTypes
8080

81-
results := map[string]utils.Result{}
81+
results := map[string]util.Result{}
8282
for _, analyzer := range analyses {
8383
analyzeName := analyzer.Name()
8484
if analysis, err := analyzer.Analyze(img); err == nil {

differs/file_diff.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package differs
1818

1919
import (
2020
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
21-
"github.com/GoogleCloudPlatform/container-diff/utils"
21+
"github.com/GoogleCloudPlatform/container-diff/util"
2222
)
2323

2424
type FileAnalyzer struct {
@@ -29,18 +29,18 @@ func (a FileAnalyzer) Name() string {
2929
}
3030

3131
// FileDiff diffs two packages and compares their contents
32-
func (a FileAnalyzer) Diff(image1, image2 pkgutil.Image) (utils.Result, error) {
32+
func (a FileAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
3333
diff, err := diffImageFiles(image1, image2)
34-
return &utils.DirDiffResult{
34+
return &util.DirDiffResult{
3535
Image1: image1.Source,
3636
Image2: image2.Source,
3737
DiffType: "File",
3838
Diff: diff,
3939
}, err
4040
}
4141

42-
func (a FileAnalyzer) Analyze(image pkgutil.Image) (utils.Result, error) {
43-
var result utils.FileAnalyzeResult
42+
func (a FileAnalyzer) Analyze(image pkgutil.Image) (util.Result, error) {
43+
var result util.FileAnalyzeResult
4444

4545
imgDir, err := pkgutil.GetDirectory(image.FSPath, true)
4646
if err != nil {
@@ -53,11 +53,11 @@ func (a FileAnalyzer) Analyze(image pkgutil.Image) (utils.Result, error) {
5353
return &result, err
5454
}
5555

56-
func diffImageFiles(image1, image2 pkgutil.Image) (utils.DirDiff, error) {
56+
func diffImageFiles(image1, image2 pkgutil.Image) (util.DirDiff, error) {
5757
img1 := image1.FSPath
5858
img2 := image2.FSPath
5959

60-
var diff utils.DirDiff
60+
var diff util.DirDiff
6161

6262
img1Dir, err := pkgutil.GetDirectory(img1, true)
6363
if err != nil {
@@ -68,6 +68,6 @@ func diffImageFiles(image1, image2 pkgutil.Image) (utils.DirDiff, error) {
6868
return diff, err
6969
}
7070

71-
diff, _ = utils.DiffDirectory(img1Dir, img2Dir)
71+
diff, _ = util.DiffDirectory(img1Dir, img2Dir)
7272
return diff, nil
7373
}

differs/history_diff.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"strings"
2121

2222
pkgutil "github.com/GoogleCloudPlatform/container-diff/pkg/util"
23-
"github.com/GoogleCloudPlatform/container-diff/utils"
23+
"github.com/GoogleCloudPlatform/container-diff/util"
2424
)
2525

2626
type HistoryAnalyzer struct {
@@ -35,19 +35,19 @@ func (a HistoryAnalyzer) Name() string {
3535
return "HistoryAnalyzer"
3636
}
3737

38-
func (a HistoryAnalyzer) Diff(image1, image2 pkgutil.Image) (utils.Result, error) {
38+
func (a HistoryAnalyzer) Diff(image1, image2 pkgutil.Image) (util.Result, error) {
3939
diff, err := getHistoryDiff(image1, image2)
40-
return &utils.HistDiffResult{
40+
return &util.HistDiffResult{
4141
Image1: image1.Source,
4242
Image2: image2.Source,
4343
DiffType: "History",
4444
Diff: diff,
4545
}, err
4646
}
4747

48-
func (a HistoryAnalyzer) Analyze(image pkgutil.Image) (utils.Result, error) {
48+
func (a HistoryAnalyzer) Analyze(image pkgutil.Image) (util.Result, error) {
4949
history := getHistoryList(image.Config.History)
50-
result := utils.ListAnalyzeResult{
50+
result := util.ListAnalyzeResult{
5151
Image: image.Source,
5252
AnalyzeType: "History",
5353
Analysis: history,
@@ -59,8 +59,8 @@ func getHistoryDiff(image1, image2 pkgutil.Image) (HistDiff, error) {
5959
history1 := getHistoryList(image1.Config.History)
6060
history2 := getHistoryList(image2.Config.History)
6161

62-
adds := utils.GetAdditions(history1, history2)
63-
dels := utils.GetDeletions(history1, history2)
62+
adds := util.GetAdditions(history1, history2)
63+
dels := util.GetDeletions(history1, history2)
6464
diff := HistDiff{adds, dels}
6565
return diff, nil
6666
}

0 commit comments

Comments
 (0)