1
- package agent
1
+ package cmd
2
2
3
3
import (
4
4
"bytes"
@@ -8,53 +8,40 @@ import (
8
8
"testing"
9
9
"time"
10
10
11
- "github.com/spf13/cobra"
12
11
"github.com/stretchr/testify/require"
13
- "k8s.io/klog/v2"
14
-
15
- "github.com/jetstack/preflight/pkg/logs"
16
12
)
17
13
18
- // TestRunOneShot runs the agent in `--one-shot` mode and verifies that it exits
14
+ // TestAgentRunOneShot runs the agent in `--one-shot` mode and verifies that it exits
19
15
// after the first data gathering iteration.
20
- func TestRunOneShot (t * testing.T ) {
16
+ func TestAgentRunOneShot (t * testing.T ) {
21
17
if _ , found := os .LookupEnv ("GO_CHILD" ); found {
22
18
// Silence the warning about missing pod name for event generation
23
19
// TODO(wallrj): This should not be required when an `--input-file` has been supplied.
24
20
t .Setenv ("POD_NAME" , "venafi-kubernetes-e2e" )
25
21
// Silence the error about missing kubeconfig.
26
22
// TODO(wallrj): This should not be required when an `--input-file` has been supplied.
27
- t .Setenv ("KUBECONFIG" , "testdata/one-shot/success/kubeconfig.yaml" )
28
-
29
- c := & cobra.Command {}
30
- InitAgentCmdFlags (c , & Flags )
31
- logs .AddFlags (c .Flags ())
23
+ t .Setenv ("KUBECONFIG" , "testdata/agent/one-shot/success/kubeconfig.yaml" )
32
24
33
- err := c .ParseFlags ([]string {
25
+ os .Args = []string {
26
+ "preflight" ,
27
+ "agent" ,
34
28
"--one-shot" ,
35
29
// TODO(wallrj): This should not be required when an `--input-file` has been supplied.
36
30
"--api-token=should-not-be-required" ,
37
31
// TODO(wallrj): This should not be required when an `--input-file` has been supplied.
38
32
"--install-namespace=default" ,
39
- "--agent-config-file=testdata/one-shot/success/config.yaml" ,
40
- "--input-path=testdata/one-shot/success/input.json" ,
33
+ "--agent-config-file=testdata/agent/ one-shot/success/config.yaml" ,
34
+ "--input-path=testdata/agent/ one-shot/success/input.json" ,
41
35
"--output-path=/dev/null" ,
42
36
"-v=1" ,
43
- })
44
- require .NoError (t , err )
45
-
46
- logs .Initialize ()
47
- defer klog .Flush ()
48
-
49
- runErr := Run (c , nil )
50
- require .NoError (t , runErr , "Run returned an unexpected error" )
51
-
37
+ }
38
+ Execute ()
52
39
return
53
40
}
54
41
t .Log ("Running child process" )
55
42
ctx , cancel := context .WithTimeout (context .Background (), time .Second * 3 )
56
43
defer cancel ()
57
- cmd := exec .CommandContext (ctx , os .Args [0 ], "-test.run=^TestRunOneShot $" )
44
+ cmd := exec .CommandContext (ctx , os .Args [0 ], "-test.run=^TestAgentRunOneShot $" )
58
45
var (
59
46
stdout bytes.Buffer
60
47
stderr bytes.Buffer
0 commit comments