-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver-config.go
52 lines (43 loc) · 1.08 KB
/
driver-config.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
package main
import (
"bufio"
"os"
"path/filepath"
"text/template"
)
type driverConfig struct {
StorageClassFile string
}
const (
testConfigDir = "test/k8s-integration/config"
configTemplateFile = "test-config-template.in"
configFile = "test-config.yaml"
)
// generateDriverConfigFile loads a testdriver config template and creates a file
// with the test-specific configuration
func generateDriverConfigFile(pkgDir, storageClassFile string) (string, error) {
// Load template
t, err := template.ParseFiles(filepath.Join(pkgDir, testConfigDir, configTemplateFile))
if err != nil {
return "", err
}
// Create destination
configFilePath := filepath.Join(pkgDir, testConfigDir, configFile)
f, err := os.Create(configFilePath)
if err != nil {
return "", err
}
defer f.Close()
w := bufio.NewWriter(f)
defer w.Flush()
// Fill in template parameters
params := driverConfig{
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
}
// Write config file
err = t.Execute(w, params)
if err != nil {
return "", err
}
return configFilePath, nil
}