mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
inlet: don't hard code schema version in some tests
Otherwise, this is painful to update
This commit is contained in:
1
Makefile
1
Makefile
@@ -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…)
|
||||
$Q $(PROTOC) -I=. --plugin=$(PROTOC_GEN_GO) --go_out=. --go_opt=module=$(MODULE) $<
|
||||
$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…)
|
||||
$Q echo '//go:build !release' > $@
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
package flow
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"akvorado/common/helpers"
|
||||
@@ -15,6 +17,10 @@ import (
|
||||
func TestHTTPEndpoints(t *testing.T) {
|
||||
r := reporter.NewMock(t)
|
||||
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{
|
||||
{
|
||||
@@ -27,12 +33,8 @@ func TestHTTPEndpoints(t *testing.T) {
|
||||
}, {
|
||||
URL: "/api/v0/inlet/flow/schemas.json",
|
||||
JSONOutput: gin.H{
|
||||
"current-version": 2,
|
||||
"versions": gin.H{
|
||||
"0": "/api/v0/inlet/flow/schema-0.proto",
|
||||
"1": "/api/v0/inlet/flow/schema-1.proto",
|
||||
"2": "/api/v0/inlet/flow/schema-2.proto",
|
||||
},
|
||||
"current-version": CurrentSchemaVersion,
|
||||
"versions": versions,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ package kafka
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"akvorado/common/daemon"
|
||||
"akvorado/common/helpers"
|
||||
"akvorado/common/reporter"
|
||||
"akvorado/inlet/flow"
|
||||
)
|
||||
|
||||
func TestKafka(t *testing.T) {
|
||||
@@ -25,7 +27,7 @@ func TestKafka(t *testing.T) {
|
||||
mockProducer.ExpectInputWithMessageCheckerFunctionAndSucceed(func(got *sarama.ProducerMessage) error {
|
||||
defer close(received)
|
||||
expected := sarama.ProducerMessage{
|
||||
Topic: "flows-v2",
|
||||
Topic: fmt.Sprintf("flows-v%d", flow.CurrentSchemaVersion),
|
||||
Key: got.Key,
|
||||
Value: sarama.ByteEncoder("hello world!"),
|
||||
Partition: got.Partition,
|
||||
@@ -50,7 +52,7 @@ func TestKafka(t *testing.T) {
|
||||
gotMetrics := r.GetMetrics("akvorado_inlet_kafka_")
|
||||
expectedMetrics := map[string]string{
|
||||
`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",
|
||||
}
|
||||
if diff := helpers.Diff(gotMetrics, expectedMetrics); diff != "" {
|
||||
|
||||
Reference in New Issue
Block a user