|
15 | 15 | * |
16 | 16 | */ |
17 | 17 |
|
18 | | -package test |
| 18 | +package e2e |
19 | 19 |
|
20 | 20 | import ( |
21 | 21 | "bufio" |
22 | 22 | "bytes" |
23 | 23 | "fmt" |
24 | 24 | "os" |
25 | | - "os/exec" |
26 | | - "strings" |
27 | 25 | "testing" |
28 | 26 | "time" |
29 | 27 |
|
30 | 28 | jsoniter "github.com/json-iterator/go" |
31 | 29 | "github.com/netobserv/flowlogs-pipeline/pkg/config" |
32 | 30 | "github.com/netobserv/flowlogs-pipeline/pkg/pipeline" |
| 31 | + "github.com/netobserv/flowlogs-pipeline/pkg/test" |
33 | 32 | kafkago "github.com/segmentio/kafka-go" |
34 | 33 | log "github.com/sirupsen/logrus" |
35 | 34 | "github.com/spf13/viper" |
@@ -309,60 +308,28 @@ parameters: |
309 | 308 | }() |
310 | 309 | } |
311 | 310 |
|
312 | | -func runCommand(t *testing.T, command string) { |
313 | | - var cmd *exec.Cmd |
314 | | - cmdStrings := strings.Split(command, " ") |
315 | | - cmdBase := cmdStrings[0] |
316 | | - cmdStrings = cmdStrings[1:] |
317 | | - cmd = exec.Command(cmdBase, cmdStrings...) |
318 | | - cmd.Stdout = os.Stdout |
319 | | - cmd.Stderr = os.Stderr |
320 | | - err := cmd.Run() |
321 | | - assert.NoError(t, err) |
322 | | - if err != nil { |
323 | | - msg := fmt.Sprintf("error in running command: %v \n", err) |
324 | | - assert.Fail(t, msg) |
325 | | - } |
326 | | -} |
| 311 | +/* |
| 312 | +var TestEnv env.Environment |
327 | 313 |
|
328 | | -func runCommandGetOutput(t *testing.T, command string) string { |
329 | | - var cmd *exec.Cmd |
330 | | - var outBuf bytes.Buffer |
331 | | - var err error |
332 | | - cmdStrings := strings.Split(command, " ") |
333 | | - cmdBase := cmdStrings[0] |
334 | | - cmdStrings = cmdStrings[1:] |
335 | | - cmd = exec.Command(cmdBase, cmdStrings...) |
336 | | - cmd.Stdout = &outBuf |
337 | | - cmd.Stderr = os.Stderr |
338 | | - err = cmd.Run() |
339 | | - assert.NoError(t, err) |
340 | | - if err != nil { |
341 | | - msg := fmt.Sprintf("error in running command: %v \n", err) |
342 | | - assert.Fail(t, msg) |
343 | | - } |
344 | | - output := outBuf.Bytes() |
345 | | - // strip the line feed from the end of the output string |
346 | | - output = output[0 : len(output)-1] |
347 | | - fmt.Printf("output = %s\n", string(output)) |
348 | | - return string(output) |
| 314 | +func TestMain(m *testing.M) { |
| 315 | + yamlFiles := []string{"strimzi.yaml", "kafka.strimzi.yaml"} |
| 316 | + e2e.Main(m, yamlFiles, &TestEnv) |
349 | 317 | } |
350 | | - |
| 318 | +*/ |
351 | 319 | func TestEnd2EndKafka(t *testing.T) { |
352 | 320 | var command string |
353 | 321 |
|
354 | | - pwd := runCommandGetOutput(t, "pwd") |
355 | | - |
| 322 | + pwd := test.RunCommand("pwd") |
356 | 323 | fmt.Printf("\nset up kind and kafka \n\n") |
357 | 324 | command = pwd + "/kafka_kind_start.sh" |
358 | | - runCommand(t, command) |
| 325 | + test.RunCommand(command) |
359 | 326 |
|
360 | 327 | fmt.Printf("\nwait for kafka to be active \n\n") |
361 | 328 | command = "kubectl wait kafka/my-cluster --for=condition=Ready --timeout=1200s -n default" |
362 | | - runCommand(t, command) |
| 329 | + test.RunCommand(command) |
363 | 330 |
|
364 | | - command = "kubectl get kafka my-cluster -o=jsonpath='{.status.listeners[?(@.type==\"external\")].bootstrapServers}{\"\\n\"}'" |
365 | | - kafkaAddr := runCommandGetOutput(t, command) |
| 331 | + command = "kubectl get kafka my-cluster -o=jsonpath='{.status.listeners[?(@.type==\"external\")].bootstrapServers}'" |
| 332 | + kafkaAddr := test.RunCommand(command) |
366 | 333 | // strip the quotation marks |
367 | 334 | kafkaAddr = kafkaAddr[1 : len(kafkaAddr)-1] |
368 | 335 | fmt.Printf("kafkaAddr = %s \n", kafkaAddr) |
@@ -391,5 +358,5 @@ func TestEnd2EndKafka(t *testing.T) { |
391 | 358 |
|
392 | 359 | fmt.Printf("delete kind and kafka \n") |
393 | 360 | command = pwd + "/kafka_kind_stop.sh" |
394 | | - runCommand(t, command) |
| 361 | + test.RunCommand(command) |
395 | 362 | } |
0 commit comments