forked from sonic-net/sonic-gnmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.go
57 lines (51 loc) · 1.14 KB
/
test_utils.go
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
package test_utils
import (
"io"
"os"
)
func SetupMultiNamespace() error {
err := os.MkdirAll("/var/run/redis0/sonic-db/", 0755)
if err != nil {
return err
}
srcFileName := [2]string{"../testdata/database_global.json", "../testdata/database_config_asic0.json"}
dstFileName := [2]string{"/var/run/redis/sonic-db/database_global.json", "/var/run/redis0/sonic-db/database_config_asic0.json"}
for i := 0; i < len(srcFileName); i++ {
sourceFileStat, err := os.Stat(srcFileName[i])
if err != nil {
return err
}
if !sourceFileStat.Mode().IsRegular() {
return err
}
source, err := os.Open(srcFileName[i])
if err != nil {
return err
}
defer source.Close()
destination, err := os.Create(dstFileName[i])
if err != nil {
return err
}
defer destination.Close()
_, err = io.Copy(destination, source)
if err != nil {
return err
}
}
return nil
}
func CleanUpMultiNamespace() error {
err := os.Remove("/var/run/redis/sonic-db/database_global.json")
if err != nil {
return err
}
err = os.RemoveAll("/var/run/redis0")
if err != nil {
return err
}
return nil
}
func GetMultiNsNamespace() string {
return "asic0"
}