代码拉取完成,页面将自动刷新
同步操作将从 openEuler-RISC-V/syscontainer-tools 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 7a8327e4391a02aadfbd29cfaa61720feadec8af Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Mon, 17 Oct 2022 17:07:00 +0800
Subject: [PATCH] add dt-test
---
Makefile | 2 +-
libnetwork/interfaces.go | 3 +-
utils/utils.go | 2 +-
utils/utils_test.go | 74 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+), 3 deletions(-)
create mode 100644 utils/utils_test.go
diff --git a/Makefile b/Makefile
index 5881aec..a76cab2 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ syscontainer-hooks: $(SOURCES) | $(DEPS_LINK)
@echo "Done!"
localtest:
- go test -tags ${TAGS} -ldflags ${GO_LDFLAGS} -v ./...
+ ${ENV} go test -mod=vendor -tags ${TAGS} -ldflags ${GO_LDFLAGS} -v ./...
clean:
rm -rf build
diff --git a/libnetwork/interfaces.go b/libnetwork/interfaces.go
index c3c71c1..6e1349a 100644
--- a/libnetwork/interfaces.go
+++ b/libnetwork/interfaces.go
@@ -229,7 +229,8 @@ func UpdateNic(ctr *container.Container, config *types.InterfaceConf, updateConf
tmpConfig.HostNicName = newConfig.HostNicName
if hConfig.IsSameInterface(tmpConfig) {
- logrus.Infof("Network interface in container %s: Identical setting, nothing to change", config.CtrNicName, ctr.Name())
+ logrus.Infof("Network interface in container (%s, %s): Identical setting, nothing to change",
+ config.CtrNicName, ctr.Name())
return nil
}
if err := hConfig.UpdateNetworkInterface(newConfig, false); err != nil {
diff --git a/utils/utils.go b/utils/utils.go
index c774da0..4f5581b 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -98,7 +98,7 @@ func ParseSyslogService(service string) (*SyslogService, error) {
serviceAddr = ""
} else if strings.HasPrefix(service, syslogUDPPrefix) {
serviceType = "udp"
- serviceAddr := service[len(syslogUDPPrefix):]
+ serviceAddr = service[len(syslogUDPPrefix):]
if serviceAddr == "" {
serviceAddr = syslogDefaultUDPService
}
diff --git a/utils/utils_test.go b/utils/utils_test.go
new file mode 100644
index 0000000..4cd168b
--- /dev/null
+++ b/utils/utils_test.go
@@ -0,0 +1,74 @@
+// Copyright (c) Huawei Technologies Co., Ltd. 2021-2022. All rights reserved.
+// rubik licensed under the Mulan PSL v2.
+// You can use this software according to the terms and conditions of the Mulan PSL v2.
+// You may obtain a copy of Mulan PSL v2 at:
+// http://license.coscl.org.cn/MulanPSL2
+// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+// PURPOSE.
+// See the Mulan PSL v2 for more details.
+// Author: Jiaqi Yang
+// Date: 2022-10-15
+// Description: This file is used for utils.go
+
+package utils
+
+import (
+ "testing"
+)
+
+// TestParseSyslogService tests ParseSyslogService
+func TestParseSyslogService(t *testing.T) {
+ const ip, invalidPrefix = "10.20.30.40", "invalid"
+ tests := []struct {
+ name, service, serviceType, addr string
+ wantErr bool
+ }{
+ {name: "TC1-udp", service: syslogUDPPrefix + ip, wantErr: false, serviceType: "udp", addr: ip},
+ {name: "TC1.1-udp(default)", service: syslogUDPPrefix, wantErr: false, serviceType: "udp",
+ addr: syslogDefaultUDPService},
+ {name: "TC2-tcp", service: syslogTCPPrefix + ip, wantErr: false, serviceType: "tcp", addr: ip},
+ {name: "TC2.1-tcp(default)", service: syslogTCPPrefix, wantErr: false, serviceType: "tcp",
+ addr: syslogDefaultTCPService},
+ {name: "TC3-default", serviceType: "default", addr: "", wantErr: false},
+ {name: "TC4-unix", service: syslogUnixSock + ip, wantErr: false, addr: ip},
+ {name: "TC5-invalid", service: invalidPrefix + ip, wantErr: true},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ out, err := ParseSyslogService(tt.service)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("ParseSyslogService() = %v, want %v", err, tt.wantErr)
+ }
+ if err == nil && (out.Addr != tt.addr || out.Type != tt.serviceType) {
+ t.Errorf("get false results: expect(addr: %v, type: %v), get(addr: %v, type: %v)",
+ tt.addr, tt.serviceType, out.Addr, out.Type)
+ }
+ })
+ }
+}
+
+// TestHookSyslog tests HookSyslog
+func TestHookSyslog(t *testing.T) {
+ const ip, invalidPrefix, syslogTag = "10.20.30.40", "invalid", "tools "
+ tests := []struct {
+ name, service string
+ wantErr bool
+ }{
+ {
+ name: "TC1-fail to parse",
+ service: invalidPrefix,
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ err := HookSyslog(tt.service, syslogTag)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("HookSyslog() = %v, want %v", err, tt.wantErr)
+ }
+ })
+ }
+}
--
2.30.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。