4
4
"bytes"
5
5
"flag"
6
6
"fmt"
7
- "io/ioutil"
8
7
"os"
9
8
"os/exec"
10
9
"path/filepath"
@@ -17,11 +16,15 @@ import (
17
16
"k8s.io/client-go/tools/clientcmd"
18
17
)
19
18
20
- var WaitDuration = 60 * time .Second
21
- var TickDuration = 2 * time .Second
19
+ var (
20
+ WaitDuration = 60 * time .Second
21
+ TickDuration = 2 * time .Second
22
+ )
22
23
23
- var devModeFlag = flag .Bool ("dev" , false , "keep test environment after finishing" )
24
- var devMode bool
24
+ var (
25
+ devModeFlag = flag .Bool ("dev" , false , "keep test environment after finishing" )
26
+ devMode bool
27
+ )
25
28
26
29
type Test struct {
27
30
namespace string
@@ -50,7 +53,7 @@ func NewTest() (test Test, err error) {
50
53
return nil
51
54
}}
52
55
// TemplateDir
53
- test .templateDir , err = ioutil . TempDir ("/tmp/" , "haproxy-ic-test-tmpl" )
56
+ test .templateDir , err = os . MkdirTemp ("/tmp/" , "haproxy-ic-test-tmpl" )
54
57
if err != nil {
55
58
return test , fmt .Errorf ("error creating template dir: %w " , err )
56
59
}
@@ -69,7 +72,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
69
72
return err
70
73
}
71
74
}
72
- if file , err = ioutil .ReadFile (path ); err != nil {
75
+ if file , err = os .ReadFile (path ); err != nil {
73
76
return fmt .Errorf ("error reading yaml file: %w" , err )
74
77
}
75
78
// kubectl -n $NS apply -f -
@@ -80,7 +83,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
80
83
}
81
84
82
85
func (t * Test ) processTemplate (path string , tmplData interface {}) (string , error ) {
83
- file , err := ioutil .ReadFile (path )
86
+ file , err := os .ReadFile (path )
84
87
if err != nil {
85
88
return "" , fmt .Errorf ("error reading yaml template: %w" , err )
86
89
}
@@ -91,13 +94,13 @@ func (t *Test) processTemplate(path string, tmplData interface{}) (string, error
91
94
return "" , fmt .Errorf ("error parsing yaml template: %w" , err )
92
95
}
93
96
yaml := filepath .Join (t .templateDir , t .namespace + time .Now ().Format ("2006-01-02-1504051111" )+ ".yaml" )
94
- return yaml , ioutil .WriteFile (yaml , result .Bytes (), 0600 )
97
+ return yaml , os .WriteFile (yaml , result .Bytes (), 0o600 )
95
98
}
96
99
97
100
func (t * Test ) Delete (path string ) error {
98
101
var err error
99
102
var file []byte
100
- if file , err = ioutil .ReadFile (path ); err != nil {
103
+ if file , err = os .ReadFile (path ); err != nil {
101
104
return fmt .Errorf ("error reading yaml file: %w" , err )
102
105
}
103
106
if out , errApply := t .execute (string (file ), "kubectl" , "delete" , "-f" , "-" ); errApply != nil {
0 commit comments