1- package agent
1+ package cmd
22
33import (
44 "bytes"
@@ -8,53 +8,40 @@ import (
88 "testing"
99 "time"
1010
11- "github.com/spf13/cobra"
1211 "github.com/stretchr/testify/require"
13- "k8s.io/klog/v2"
14-
15- "github.com/jetstack/preflight/pkg/logs"
1612)
1713
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
1915// after the first data gathering iteration.
20- func TestRunOneShot (t * testing.T ) {
16+ func TestAgentRunOneShot (t * testing.T ) {
2117 if _ , found := os .LookupEnv ("GO_CHILD" ); found {
2218 // Silence the warning about missing pod name for event generation
2319 // TODO(wallrj): This should not be required when an `--input-file` has been supplied.
2420 t .Setenv ("POD_NAME" , "venafi-kubernetes-e2e" )
2521 // Silence the error about missing kubeconfig.
2622 // 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" )
3224
33- err := c .ParseFlags ([]string {
25+ os .Args = []string {
26+ "preflight" ,
27+ "agent" ,
3428 "--one-shot" ,
3529 // TODO(wallrj): This should not be required when an `--input-file` has been supplied.
3630 "--api-token=should-not-be-required" ,
3731 // TODO(wallrj): This should not be required when an `--input-file` has been supplied.
3832 "--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" ,
4135 "--output-path=/dev/null" ,
4236 "-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 ()
5239 return
5340 }
5441 t .Log ("Running child process" )
5542 ctx , cancel := context .WithTimeout (context .Background (), time .Second * 3 )
5643 defer cancel ()
57- cmd := exec .CommandContext (ctx , os .Args [0 ], "-test.run=^TestRunOneShot $" )
44+ cmd := exec .CommandContext (ctx , os .Args [0 ], "-test.run=^TestAgentRunOneShot $" )
5845 var (
5946 stdout bytes.Buffer
6047 stderr bytes.Buffer
0 commit comments