...
1
2
3
4 package vmbus
5
6 import (
7 "context"
8 "path/filepath"
9 "testing"
10 "time"
11 )
12
13 func Test_WaitForVMBusDevicePath_Success(t *testing.T) {
14 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
15 defer cancel()
16
17 vmBusGUID := "1111-2222-3333-4444"
18 pciDir := "pci1234:00"
19
20 storageWaitForFileMatchingPattern = func(ctx context.Context, pattern string) (string, error) {
21 vmBusDirPath, targetPattern := filepath.Split(pattern)
22 if targetPattern == "pci*" {
23 return filepath.Join(vmBusDirPath, pciDir), nil
24 }
25 return "", nil
26 }
27
28 vmBusGUIDPattern := filepath.Join(vmBusGUID, "pci*")
29 expectedResult := filepath.Join("/sys/bus/vmbus/devices", vmBusGUID, pciDir)
30 result, err := WaitForDevicePath(ctx, vmBusGUIDPattern)
31 if err != nil {
32 t.Fatalf("expected to succeed, instead got: %v", err)
33 }
34 if result != expectedResult {
35 t.Fatalf("result %s does not match expected result %s", result, expectedResult)
36 }
37 }
38
View as plain text