Skip to content

Commit

Permalink
fix:remove unnecassry logs and panics fix: linting problems fix: devi…
Browse files Browse the repository at this point in the history
…ce_test

Signed-off-by: nabil salah <[email protected]>
  • Loading branch information
Nabil-Salah committed Dec 5, 2024
1 parent 1d3fc5f commit abfe48e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test: lint build
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )

testrace: lint build
sudo -E ${GOBINARY} test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )
go test -vet=off -v $(shell go list ./... | grep -Ev "stubs|network" )

generate:
@echo "Generating modules client stubs"
Expand Down
10 changes: 3 additions & 7 deletions pkg/flist/flist.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ import (
)

const (
defaultRoot = "/var/cache/modules/flist"
mib = 1024 * 1024
md5HexLength = 32

defaultNamespace = "ndmz"
publicNamespace = "public"

defaultRoot = "/var/cache/modules/flist"
mib = 1024 * 1024
md5HexLength = 32
defaultHubCallTimeout = 20 * time.Second
)

Expand Down
6 changes: 0 additions & 6 deletions pkg/netlight/bridge/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bridge

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -89,19 +88,14 @@ func TestAttachBridgeWithMac(t *testing.T) {
}()

addrBefore := br.Attrs().HardwareAddr
t.Logf("initial bridge mac: %s", addrBefore)
err = AttachNicWithMac(dummy, br)
require.NoError(t, err)
time.Sleep(100 * time.Millisecond)

l, err := netlink.LinkByName("bro0")
require.NoError(t, err)
br = l.(*netlink.Bridge)
addrAfter := br.Attrs().HardwareAddr

t.Logf("bridge mac After: %s", addrAfter)
t.Logf("dummy mac: %s", dummy.Attrs().HardwareAddr)

assert.NotEqual(t, addrBefore, addrAfter)
assert.Equal(t, dummy.Attrs().HardwareAddr, addrAfter)
}
4 changes: 2 additions & 2 deletions pkg/netlight/public/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ func TestCreatePublicNS(t *testing.T) {
require.NoError(t, err)
}()

_, err := bridge.New("br-pub")
_, err := bridge.New(PublicBridge)
require.NoError(t, err)
defer func() {
err = bridge.Delete("br-pub")
err = bridge.Delete(PublicBridge)
require.NoError(t, err)
}()
err = setupPublicNS(pkg.StrIdentifier(""), iface)
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/filesystem/btrfs_ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ var (

type TestDevices map[string]string

func (d TestDevices) Loops() Devices {
func (d TestDevices) Loops(t *testing.T) Devices {
mgr := lsblkDeviceManager{
executer: executerFunc(run),
}
for loopTempPath, loop := range d {
size, err := FilesUsage(loopTempPath)
if err != nil {
panic(err)
require.NoError(t, err)
}
mgr.cache = append(mgr.cache, DeviceInfo{
Path: loop,
Expand All @@ -53,7 +53,7 @@ func (d TestDevices) Loops() Devices {

devices, err := mgr.Devices(context.Background())
if err != nil {
panic(err)
require.NoError(t, err)
}
return devices
}
Expand Down Expand Up @@ -208,7 +208,7 @@ func TestBtrfsSingleCI(t *testing.T) {
require.NoError(t, err, "failed to initialize devices")

defer devices.Destroy()
loops := devices.Loops()
loops := devices.Loops(t)

for _, dev := range loops {
dev.mgr = &lsblkDeviceManager{
Expand All @@ -229,7 +229,7 @@ func TestCLeanUpQgroupsCI(t *testing.T) {
require.NoError(t, err, "failed to initialize devices")
defer devices.Destroy()

loops := devices.Loops()
loops := devices.Loops(t)
loops[0].mgr = &lsblkDeviceManager{
executer: executerFunc(run),
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/filesystem/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ func TestDeviceManagerScan(t *testing.T) {
},
}.Bytes(), nil)

// same call to lsblk but with UUID for better identification for partitions
exec.On("run", ctx, "lsblk", "--json", "-o", "PATH,NAME,SIZE,SUBSYSTEMS,FSTYPE,LABEL,ROTA,UUID", "--bytes", "--exclude", "1,2,11", "--path").
Return(TestMap{
"blockdevices": []TestMap{
{"subsystems": "block:scsi:pci", "path": "/tmp/dev1", "name": "dev1", "label": "test"},
{"subsystems": "block:scsi:pci", "path": "/tmp/dev2", "name": "dev2", "label": "test2"},
},
}.Bytes(), nil)

// then other calls per device for extended details
exec.On("run", ctx, "lsblk", "--json", "-o", "PATH,NAME,SIZE,SUBSYSTEMS,FSTYPE,LABEL,ROTA", "--bytes", "--exclude", "1,2,11", "--path", "/tmp/dev1").
Return(TestMap{
Expand Down

0 comments on commit abfe48e

Please sign in to comment.