inlet: don't hard code schema version in some tests

Otherwise, this is painful to update
This commit is contained in:
Vincent Bernat
2022-09-17 23:21:18 +02:00
parent 7c2f2a6799
commit cd8cf04d03
3 changed files with 15 additions and 10 deletions

View File

@@ -75,6 +75,7 @@ $(BIN)/wwhrd: PACKAGE=github.com/frapposelli/wwhrd@latest
inlet/flow/decoder/flow-%.pb.go: inlet/flow/data/schemas/flow-%.proto | $(PROTOC_GEN_GO) ; $(info $(M) compiling protocol buffers definition) inlet/flow/decoder/flow-%.pb.go: inlet/flow/data/schemas/flow-%.proto | $(PROTOC_GEN_GO) ; $(info $(M) compiling protocol buffers definition)
$Q $(PROTOC) -I=. --plugin=$(PROTOC_GEN_GO) --go_out=. --go_opt=module=$(MODULE) $< $Q $(PROTOC) -I=. --plugin=$(PROTOC_GEN_GO) --go_out=. --go_opt=module=$(MODULE) $<
$Q sed -i.bkp s/FlowMessagev./FlowMessage/g $@ && rm $@.bkp $Q sed -i.bkp s/FlowMessagev./FlowMessage/g $@ && rm $@.bkp
$Q : $$((i=$*)); while [ $$i -ne 0 ]; do : $$((i = i - 1)); rm -f inlet/flow/decoder/flow-$$i.pb.go; done
common/clickhousedb/mocks/mock_driver.go: $(MOCKGEN) ; $(info $(M) generate mocks for ClickHouse driver) common/clickhousedb/mocks/mock_driver.go: $(MOCKGEN) ; $(info $(M) generate mocks for ClickHouse driver)
$Q echo '//go:build !release' > $@ $Q echo '//go:build !release' > $@

View File

@@ -4,6 +4,8 @@
package flow package flow
import ( import (
"fmt"
"strconv"
"testing" "testing"
"akvorado/common/helpers" "akvorado/common/helpers"
@@ -15,6 +17,10 @@ import (
func TestHTTPEndpoints(t *testing.T) { func TestHTTPEndpoints(t *testing.T) {
r := reporter.NewMock(t) r := reporter.NewMock(t)
c := NewMock(t, r, DefaultConfiguration()) c := NewMock(t, r, DefaultConfiguration())
versions := gin.H{}
for i := 0; i < CurrentSchemaVersion+1; i++ {
versions[strconv.Itoa(i)] = fmt.Sprintf("/api/v0/inlet/flow/schema-%d.proto", i)
}
cases := helpers.HTTPEndpointCases{ cases := helpers.HTTPEndpointCases{
{ {
@@ -27,12 +33,8 @@ func TestHTTPEndpoints(t *testing.T) {
}, { }, {
URL: "/api/v0/inlet/flow/schemas.json", URL: "/api/v0/inlet/flow/schemas.json",
JSONOutput: gin.H{ JSONOutput: gin.H{
"current-version": 2, "current-version": CurrentSchemaVersion,
"versions": gin.H{ "versions": versions,
"0": "/api/v0/inlet/flow/schema-0.proto",
"1": "/api/v0/inlet/flow/schema-1.proto",
"2": "/api/v0/inlet/flow/schema-2.proto",
},
}, },
}, },
} }

View File

@@ -5,6 +5,7 @@ package kafka
import ( import (
"errors" "errors"
"fmt"
"testing" "testing"
"time" "time"
@@ -14,6 +15,7 @@ import (
"akvorado/common/daemon" "akvorado/common/daemon"
"akvorado/common/helpers" "akvorado/common/helpers"
"akvorado/common/reporter" "akvorado/common/reporter"
"akvorado/inlet/flow"
) )
func TestKafka(t *testing.T) { func TestKafka(t *testing.T) {
@@ -25,7 +27,7 @@ func TestKafka(t *testing.T) {
mockProducer.ExpectInputWithMessageCheckerFunctionAndSucceed(func(got *sarama.ProducerMessage) error { mockProducer.ExpectInputWithMessageCheckerFunctionAndSucceed(func(got *sarama.ProducerMessage) error {
defer close(received) defer close(received)
expected := sarama.ProducerMessage{ expected := sarama.ProducerMessage{
Topic: "flows-v2", Topic: fmt.Sprintf("flows-v%d", flow.CurrentSchemaVersion),
Key: got.Key, Key: got.Key,
Value: sarama.ByteEncoder("hello world!"), Value: sarama.ByteEncoder("hello world!"),
Partition: got.Partition, Partition: got.Partition,
@@ -49,9 +51,9 @@ func TestKafka(t *testing.T) {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
gotMetrics := r.GetMetrics("akvorado_inlet_kafka_") gotMetrics := r.GetMetrics("akvorado_inlet_kafka_")
expectedMetrics := map[string]string{ expectedMetrics := map[string]string{
`sent_bytes_total{exporter="127.0.0.1"}`: "26", `sent_bytes_total{exporter="127.0.0.1"}`: "26",
`errors_total{error="kafka: Failed to produce message to topic flows-v2: noooo"}`: "1", fmt.Sprintf(`errors_total{error="kafka: Failed to produce message to topic flows-v%d: noooo"}`, flow.CurrentSchemaVersion): "1",
`sent_messages_total{exporter="127.0.0.1"}`: "2", `sent_messages_total{exporter="127.0.0.1"}`: "2",
} }
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" { if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
t.Fatalf("Metrics (-got, +want):\n%s", diff) t.Fatalf("Metrics (-got, +want):\n%s", diff)