1
0
Fork 0
mirror of https://github.com/arangodb/kube-arangodb.git synced 2024-12-15 17:51:03 +00:00
kube-arangodb/internal/metrics.item.go_test.tmpl
2024-05-21 14:09:50 +02:00

179 lines
3.9 KiB
Cheetah

{{- $root := . -}}
//
// DISCLAIMER
//
// Copyright 2016-2024 ArangoDB GmbH, Cologne, Germany
//
// 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.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
package metric_descriptions
import (
"testing"
{{- if .global }}
"github.com/stretchr/testify/require"
{{- end }}
)
func Test_{{ .ename }}_Descriptor(t *testing.T) {
{{ .ename }}()
}
{{- if .global }}
func Test_{{ .ename }}_Global(t *testing.T) {
global := Get{{ .ename }}Factory()
object1 := {{ .ename }}Item{
{{- range $i, $field := .mapKeys }}
{{ $field }}: "1",
{{- end }}
}
object2 := {{ .ename }}Item{
{{- range $i, $field := .mapKeys }}
{{ $field }}: "2",
{{- end }}
}
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 0)
})
t.Run("Precheck", func(t *testing.T) {
require.EqualValues(t, 0, global.Get(object1))
require.EqualValues(t, 0, global.Get(object2))
})
t.Run("Add", func(t *testing.T) {
global.Add(10, object1)
require.EqualValues(t, 10, global.Get(object1))
require.EqualValues(t, 0, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 1)
})
t.Run("Add", func(t *testing.T) {
global.Add(3, object2)
require.EqualValues(t, 10, global.Get(object1))
require.EqualValues(t, 3, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 2)
})
t.Run("Dec", func(t *testing.T) {
global.Add(-1, object1)
require.EqualValues(t, 9, global.Get(object1))
require.EqualValues(t, 3, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 2)
})
t.Run("Remove", func(t *testing.T) {
global.Remove(object1)
require.EqualValues(t, 0, global.Get(object1))
require.EqualValues(t, 3, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 1)
})
t.Run("Remove", func(t *testing.T) {
global.Remove(object1)
require.EqualValues(t, 0, global.Get(object1))
require.EqualValues(t, 3, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 1)
})
t.Run("Remove", func(t *testing.T) {
global.Remove(object2)
require.EqualValues(t, 0, global.Get(object1))
require.EqualValues(t, 0, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 0)
})
}
{{- if eq .type "Counter" }}
func Test_{{ .ename }}_Global_Counter(t *testing.T) {
global := Get{{ .ename }}Factory()
object1 := {{ .ename }}Item{
{{- range $i, $field := .mapKeys }}
{{ $field }}: "1",
{{- end }}
}
object2 := {{ .ename }}Item{
{{- range $i, $field := .mapKeys }}
{{ $field }}: "2",
{{- end }}
}
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 0)
})
t.Run("Precheck", func(t *testing.T) {
require.EqualValues(t, 0, global.Get(object1))
require.EqualValues(t, 0, global.Get(object2))
})
t.Run("Add", func(t *testing.T) {
global.Add(10, object1)
require.EqualValues(t, 10, global.Get(object1))
require.EqualValues(t, 0, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 1)
})
t.Run("Inc", func(t *testing.T) {
global.Inc(object1)
global.Inc(object2)
require.EqualValues(t, 11, global.Get(object1))
require.EqualValues(t, 1, global.Get(object2))
})
t.Run("List", func(t *testing.T) {
require.Len(t, global.Items(), 2)
})
}
{{- end }}
{{- end }}