Skip to content

Commit 4e3fa30

Browse files
authored
moved runCommand to common utilities (#165)
1 parent 63254aa commit 4e3fa30

File tree

3 files changed

+47
-54
lines changed

3 files changed

+47
-54
lines changed

pkg/test/e2e/kafka/kafka.strimzi.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
spec:
66
kafka:
77
version: 3.1.0
8-
replicas: 3
8+
replicas: 1
99
listeners:
1010
- name: plain
1111
port: 9092
@@ -20,16 +20,16 @@ spec:
2020
type: nodeport
2121
tls: false
2222
config:
23-
offsets.topic.replication.factor: 3
24-
transaction.state.log.replication.factor: 3
25-
transaction.state.log.min.isr: 2
26-
default.replication.factor: 3
27-
min.insync.replicas: 2
23+
offsets.topic.replication.factor: 1
24+
transaction.state.log.replication.factor: 1
25+
transaction.state.log.min.isr: 1
26+
default.replication.factor: 1
27+
min.insync.replicas: 1
2828
inter.broker.protocol.version: "3.1"
2929
storage:
3030
type: ephemeral
3131
zookeeper:
32-
replicas: 3
32+
replicas: 1
3333
storage:
3434
type: ephemeral
3535
entityOperator:

pkg/test/e2e/kafka/kafka_end_to_end_test.go

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
*
1616
*/
1717

18-
package test
18+
package e2e
1919

2020
import (
2121
"bufio"
2222
"bytes"
2323
"fmt"
2424
"os"
25-
"os/exec"
26-
"strings"
2725
"testing"
2826
"time"
2927

3028
jsoniter "github.com/json-iterator/go"
3129
"github.com/netobserv/flowlogs-pipeline/pkg/config"
3230
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline"
31+
"github.com/netobserv/flowlogs-pipeline/pkg/test"
3332
kafkago "github.com/segmentio/kafka-go"
3433
log "github.com/sirupsen/logrus"
3534
"github.com/spf13/viper"
@@ -309,60 +308,28 @@ parameters:
309308
}()
310309
}
311310

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
327313
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)
349317
}
350-
318+
*/
351319
func TestEnd2EndKafka(t *testing.T) {
352320
var command string
353321

354-
pwd := runCommandGetOutput(t, "pwd")
355-
322+
pwd := test.RunCommand("pwd")
356323
fmt.Printf("\nset up kind and kafka \n\n")
357324
command = pwd + "/kafka_kind_start.sh"
358-
runCommand(t, command)
325+
test.RunCommand(command)
359326

360327
fmt.Printf("\nwait for kafka to be active \n\n")
361328
command = "kubectl wait kafka/my-cluster --for=condition=Ready --timeout=1200s -n default"
362-
runCommand(t, command)
329+
test.RunCommand(command)
363330

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)
366333
// strip the quotation marks
367334
kafkaAddr = kafkaAddr[1 : len(kafkaAddr)-1]
368335
fmt.Printf("kafkaAddr = %s \n", kafkaAddr)
@@ -391,5 +358,5 @@ func TestEnd2EndKafka(t *testing.T) {
391358

392359
fmt.Printf("delete kind and kafka \n")
393360
command = pwd + "/kafka_kind_stop.sh"
394-
runCommand(t, command)
361+
test.RunCommand(command)
395362
}

pkg/test/utils.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ package test
2020
import (
2121
"bytes"
2222
"fmt"
23+
"os"
24+
"os/exec"
2325
"reflect"
26+
"strings"
2427
"testing"
2528

2629
jsoniter "github.com/json-iterator/go"
@@ -131,3 +134,26 @@ func CreateMockAgg(name, recordKey, by, agg, op string, value float64, count int
131134
"recent_count": recentCount,
132135
}
133136
}
137+
138+
func RunCommand(command string) string {
139+
var cmd *exec.Cmd
140+
var outBuf bytes.Buffer
141+
var err error
142+
cmdStrings := strings.Split(command, " ")
143+
cmdBase := cmdStrings[0]
144+
cmdStrings = cmdStrings[1:]
145+
cmd = exec.Command(cmdBase, cmdStrings...)
146+
cmd.Stdout = &outBuf
147+
cmd.Stderr = os.Stderr
148+
err = cmd.Run()
149+
if err != nil {
150+
fmt.Printf("error in running command: %v \n", err)
151+
}
152+
output := outBuf.Bytes()
153+
//strip newline from end of output
154+
if len(output) > 0 && output[len(output)-1] == '\n' {
155+
output = output[0 : len(output)-1]
156+
}
157+
fmt.Printf("output = %s\n", string(output))
158+
return string(output)
159+
}

0 commit comments

Comments
 (0)