From 7f72b6ac690540941ee073f6a8ee4b14127d2a79 Mon Sep 17 00:00:00 2001 From: Kota Kanbe Date: Tue, 26 Nov 2019 09:40:38 +0900 Subject: [PATCH] Warn no ip (#922) * fix(scan): ignore wp-cli stderr messages (#825) (#915) * fix(scan): warn if unable to get ip address on the scan tareget server * fix test case --- scan/alpine.go | 3 ++- scan/debian.go | 3 ++- scan/debian_test.go | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scan/alpine.go b/scan/alpine.go index 5573e4c2..8eb67cce 100644 --- a/scan/alpine.go +++ b/scan/alpine.go @@ -75,7 +75,8 @@ func (o *alpine) apkUpdate() error { func (o *alpine) preCure() error { o.log.Infof("Scanning in %s", o.getServerInfo().Mode) if err := o.detectIPAddr(); err != nil { - o.log.Debugf("Failed to detect IP addresses: %s", err) + o.log.Warnf("Failed to detect IP addresses: %s", err) + o.warns = append(o.warns, err) } // Ignore this error as it just failed to detect the IP addresses return nil diff --git a/scan/debian.go b/scan/debian.go index 0546f511..e5aedde7 100644 --- a/scan/debian.go +++ b/scan/debian.go @@ -241,7 +241,8 @@ func (o *debian) checkDeps() error { func (o *debian) preCure() error { o.log.Infof("Scanning in %s", o.getServerInfo().Mode) if err := o.detectIPAddr(); err != nil { - o.log.Debugf("Failed to detect IP addresses: %s", err) + o.log.Warnf("Failed to detect IP addresses: %s", err) + o.warns = append(o.warns, err) } // Ignore this error as it just failed to detect the IP addresses return nil diff --git a/scan/debian_test.go b/scan/debian_test.go index 7d13b054..5a7d1c03 100644 --- a/scan/debian_test.go +++ b/scan/debian_test.go @@ -1,6 +1,7 @@ package scan import ( + "sort" "os" "reflect" "testing" @@ -729,8 +730,8 @@ dpkg-query: no path found matching pattern /lib/udev/hwdb.bin libuuid1:amd64: /lib/x86_64-linux-gnu/libuuid.so.1.3.0`, }, wantPkgNames: []string{ - "udev", "libuuid1", + "udev", }, }, } @@ -738,6 +739,7 @@ libuuid1:amd64: /lib/x86_64-linux-gnu/libuuid.so.1.3.0`, t.Run(tt.name, func(t *testing.T) { o := &debian{} gotPkgNames := o.parseGetPkgName(tt.args.stdout) + sort.Strings(gotPkgNames) if !reflect.DeepEqual(gotPkgNames, tt.wantPkgNames) { t.Errorf("debian.parseGetPkgName() = %v, want %v", gotPkgNames, tt.wantPkgNames) }