@@ -35,6 +35,7 @@ import (
35
35
"context"
36
36
"crypto/rand"
37
37
"fmt"
38
+ "net"
38
39
"os"
39
40
"path"
40
41
"runtime"
@@ -46,6 +47,7 @@ import (
46
47
"github.com/containerd/continuity/testutil"
47
48
"github.com/containerd/go-cni"
48
49
"github.com/stretchr/testify/assert"
50
+ "github.com/vishvananda/netlink"
49
51
)
50
52
51
53
var (
@@ -306,6 +308,25 @@ func TestBasicSetupAndRemovePluginWithoutVersion(t *testing.T) {
306
308
}
307
309
}
308
310
311
+ // TestLoopbackStatus validates whether the loopback interface state is UP.
312
+ func TestLoopbackStatus (t * testing.T ) {
313
+ t .Log ("Checking loopback interface status" )
314
+ up , err := isLoInterfaceUp ()
315
+ assert .NoError (t , err , "could not check lo interface status" )
316
+
317
+ t .Logf ("loopback interface status is %v" , map [bool ]string {true : "UP" , false : "DOWN" }[up ])
318
+ assert .True (t , up )
319
+ }
320
+
321
+ // isLoInterfaceUp returns true if the loopback interface status is UP, otherwise false.
322
+ func isLoInterfaceUp () (bool , error ) {
323
+ link , err := netlink .LinkByName ("lo" )
324
+ if err != nil {
325
+ return false , fmt .Errorf ("could not find interface lo: %w" , err )
326
+ }
327
+ return link .Attrs ().Flags & net .FlagUp != 0 , nil
328
+ }
329
+
309
330
// createNetNS returns temp netns path.
310
331
//
311
332
// NOTE: It is based on https://github.com/containernetworking/plugins/blob/v1.0.1/pkg/testutils/netns_linux.go.
0 commit comments