From 42275a0ac81ea71c086bc88363cea2b4f3666c16 Mon Sep 17 00:00:00 2001 From: yangjiaqi Date: Mon, 17 Oct 2022 17:11:39 +0800 Subject: [PATCH] add dt-test --- 0004-add-dt-test.patch | 136 ++++++++++++++++++++++++++++++++++++++++ syscontainer-tools.spec | 9 ++- 2 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 0004-add-dt-test.patch diff --git a/0004-add-dt-test.patch b/0004-add-dt-test.patch new file mode 100644 index 0000000..3f5b2f1 --- /dev/null +++ b/0004-add-dt-test.patch @@ -0,0 +1,136 @@ +From 7a8327e4391a02aadfbd29cfaa61720feadec8af Mon Sep 17 00:00:00 2001 +From: yangjiaqi +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 + diff --git a/syscontainer-tools.spec b/syscontainer-tools.spec index 6528f20..5edce47 100644 --- a/syscontainer-tools.spec +++ b/syscontainer-tools.spec @@ -1,7 +1,7 @@ #Basic Information Name: syscontainer-tools Version: 0.9 -Release: 49 +Release: 50 Summary: syscontainer tools for IT, work with iSulad License: Mulan PSL v2 URL: https://gitee.com/openeuler/syscontainer-tools @@ -11,6 +11,7 @@ BuildRoot: %{_tmppath}/%{name}-root Patch1: 0001-fix-failed-build-with-golang-1.15.5.patch Patch2: 0002-syscontainer-tools-build-security-option.patch Patch3: 0003-enable-external-linkmode-for-cgo-build.patch +Patch4: 0004-add-dt-test.patch #Dependency BuildRequires: glibc-static @@ -41,6 +42,9 @@ install -m 0750 build/syscontainer-hooks ${HOOK_DIR} install -m 0750 build/syscontainer-tools ${ISULAD_TOOLS_DIR} install -m 0750 hack/syscontainer-tools_wrapper ${ISULAD_TOOLS_WRAPPER}/syscontainer-tools_wrapper +%check +make localtest + #Install and uninstall scripts %pre @@ -109,6 +113,9 @@ chmod 0640 ${HOOK_SPEC}/hookspec.json rm -rfv %{buildroot} %changelog +* Mon Oct 17 2022 vegbir - 0.9-50 +- add dt-test + * Thu Sep 02 2021 zhangsong234 - 0.9-49 - DESC: enable external linkmode for cgo build