-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathsanity_test.go
More file actions
92 lines (74 loc) · 2.19 KB
/
Copy pathsanity_test.go
File metadata and controls
92 lines (74 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package sanitytest
import (
"fmt"
"io/ioutil"
"os"
"testing"
sanity "github.com/kubernetes-csi/csi-test/v4/pkg/sanity"
"github.com/SynologyOpenSource/synology-csi/pkg/driver"
"github.com/SynologyOpenSource/synology-csi/pkg/dsm/common"
"github.com/SynologyOpenSource/synology-csi/pkg/dsm/service"
"github.com/SynologyOpenSource/synology-csi/pkg/utils/hostexec"
)
const (
ConfigPath = "./../../config/client-info.yml"
SecretsFilePath = "./sanity-test-secret-file.yaml"
)
func TestSanity(t *testing.T) {
nodeID := "CSINode"
endpointFile, err := ioutil.TempFile("", "csi-gcs.*.sock")
if err != nil {
t.Fatal(err)
}
defer os.Remove(endpointFile.Name())
stagingPath, err := ioutil.TempDir("", "csi-gcs-staging")
if err != nil {
t.Fatal(err)
}
os.Remove(stagingPath)
targetPath, err := ioutil.TempDir("", "csi-gcs-target")
if err != nil {
t.Fatal(err)
}
os.Remove(targetPath)
info, err := common.LoadConfig(ConfigPath)
if err != nil {
t.Fatal(fmt.Sprintf("Failed to read config: %v", err))
}
dsmService := service.NewDsmService()
for _, client := range info.Clients {
err := dsmService.AddDsm(client)
if err != nil {
fmt.Printf("Failed to add DSM: %s, error: %v\n", client.Host, err)
}
}
if dsmService.GetDsmsCount() == 0 {
t.Fatal("No available DSM.")
}
defer dsmService.RemoveAllDsms()
cmdExecutor, err := hostexec.New(nil, "")
if err != nil {
t.Fatal(fmt.Sprintf("Failed to create command executor: %v\n", err))
}
tools := driver.NewTools(cmdExecutor)
endpoint := "unix://" + endpointFile.Name()
drv, err := driver.NewControllerAndNodeDriver(nodeID, endpoint, dsmService, tools)
if err != nil {
t.Fatal(fmt.Sprintf("Failed to create driver: %v\n", err))
}
drv.Activate()
// Set configuration options as needed
testConfig := sanity.NewTestConfig()
testConfig.TargetPath = targetPath
testConfig.StagingPath = stagingPath
testConfig.Address = endpoint
testConfig.SecretsFile = SecretsFilePath
// Set Input parameters for test
testConfig.TestVolumeParameters = map[string]string{
"protocol": "iscsi",
"allowMultipleSessions": "true",
}
// testConfig.TestVolumeAccessType = "block" // raw block
// Run test
sanity.Test(t, testConfig)
}