4
4
"bytes"
5
5
"flag"
6
6
"fmt"
7
- "io/ioutil"
8
7
"os"
9
8
"os/exec"
10
9
"path/filepath"
@@ -54,7 +53,7 @@ func NewTest() (test Test, err error) {
54
53
return nil
55
54
}}
56
55
// TemplateDir
57
- test .templateDir , err = ioutil . TempDir ("/tmp/" , "haproxy-ic-test-tmpl" )
56
+ test .templateDir , err = os . MkdirTemp ("/tmp/" , "haproxy-ic-test-tmpl" )
58
57
if err != nil {
59
58
return test , fmt .Errorf ("error creating template dir: %w " , err )
60
59
}
@@ -73,7 +72,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
73
72
return err
74
73
}
75
74
}
76
- if file , err = ioutil .ReadFile (path ); err != nil {
75
+ if file , err = os .ReadFile (path ); err != nil {
77
76
return fmt .Errorf ("error reading yaml file: %w" , err )
78
77
}
79
78
// kubectl -n $NS apply -f -
@@ -84,7 +83,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
84
83
}
85
84
86
85
func (t * Test ) processTemplate (path string , tmplData interface {}) (string , error ) {
87
- file , err := ioutil .ReadFile (path )
86
+ file , err := os .ReadFile (path )
88
87
if err != nil {
89
88
return "" , fmt .Errorf ("error reading yaml template: %w" , err )
90
89
}
@@ -95,13 +94,13 @@ func (t *Test) processTemplate(path string, tmplData interface{}) (string, error
95
94
return "" , fmt .Errorf ("error parsing yaml template: %w" , err )
96
95
}
97
96
yaml := filepath .Join (t .templateDir , t .namespace + time .Now ().Format ("2006-01-02-1504051111" )+ ".yaml" )
98
- return yaml , ioutil .WriteFile (yaml , result .Bytes (), 0o600 )
97
+ return yaml , os .WriteFile (yaml , result .Bytes (), 0o600 )
99
98
}
100
99
101
100
func (t * Test ) Delete (path string ) error {
102
101
var err error
103
102
var file []byte
104
- if file , err = ioutil .ReadFile (path ); err != nil {
103
+ if file , err = os .ReadFile (path ); err != nil {
105
104
return fmt .Errorf ("error reading yaml file: %w" , err )
106
105
}
107
106
if out , errApply := t .execute (string (file ), "kubectl" , "delete" , "-f" , "-" ); errApply != nil {
0 commit comments