44 "bytes"
55 "flag"
66 "fmt"
7- "io/ioutil"
87 "os"
98 "os/exec"
109 "path/filepath"
@@ -17,11 +16,15 @@ import (
1716 "k8s.io/client-go/tools/clientcmd"
1817)
1918
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+ )
2223
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+ )
2528
2629type Test struct {
2730 namespace string
@@ -50,7 +53,7 @@ func NewTest() (test Test, err error) {
5053 return nil
5154 }}
5255 // TemplateDir
53- test .templateDir , err = ioutil . TempDir ("/tmp/" , "haproxy-ic-test-tmpl" )
56+ test .templateDir , err = os . MkdirTemp ("/tmp/" , "haproxy-ic-test-tmpl" )
5457 if err != nil {
5558 return test , fmt .Errorf ("error creating template dir: %w " , err )
5659 }
@@ -69,7 +72,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
6972 return err
7073 }
7174 }
72- if file , err = ioutil .ReadFile (path ); err != nil {
75+ if file , err = os .ReadFile (path ); err != nil {
7376 return fmt .Errorf ("error reading yaml file: %w" , err )
7477 }
7578 // kubectl -n $NS apply -f -
@@ -80,7 +83,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
8083}
8184
8285func (t * Test ) processTemplate (path string , tmplData interface {}) (string , error ) {
83- file , err := ioutil .ReadFile (path )
86+ file , err := os .ReadFile (path )
8487 if err != nil {
8588 return "" , fmt .Errorf ("error reading yaml template: %w" , err )
8689 }
@@ -91,13 +94,13 @@ func (t *Test) processTemplate(path string, tmplData interface{}) (string, error
9194 return "" , fmt .Errorf ("error parsing yaml template: %w" , err )
9295 }
9396 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 )
9598}
9699
97100func (t * Test ) Delete (path string ) error {
98101 var err error
99102 var file []byte
100- if file , err = ioutil .ReadFile (path ); err != nil {
103+ if file , err = os .ReadFile (path ); err != nil {
101104 return fmt .Errorf ("error reading yaml file: %w" , err )
102105 }
103106 if out , errApply := t .execute (string (file ), "kubectl" , "delete" , "-f" , "-" ); errApply != nil {
0 commit comments