Skip to content

Commit

Permalink
Add initial backend tests
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Mar 1, 2024
1 parent 45ae25e commit 37414c3
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions go/stats/opentsdb/backend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package opentsdb

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
)

type mockWriter struct {
data []*DataPoint
}

func (mw *mockWriter) Write(data []*DataPoint) error {
mw.data = data
return nil
}

type mockVariable struct{}

func (mv *mockVariable) Help() string {
return ""
}

func (mv *mockVariable) String() string {
return ""
}

func TestPushAll(t *testing.T) {
mw := &mockWriter{}
p := "testPrefix"
ct := map[string]string{
"tag1": "value1",
"tag2": "value2",
}

b := &backend{
prefix: p,
commonTags: ct,
writer: mw,
}

// TODO: Add asserts
err := b.PushAll()
assert.NoError(t, err)
}

func TestPushOne(t *testing.T) {
mw := &mockWriter{}
mv := &mockVariable{}
b := &backend{
prefix: "test",
commonTags: map[string]string{"tag1": "value1"},
writer: mw,
}

// TODO: Add asserts
err := b.PushOne("var1", mv)
assert.NoError(t, err)

fmt.Println(b.collector().data)
}

0 comments on commit 37414c3

Please sign in to comment.