File: metric_test.go

package info (click to toggle)
golang-github-openfga-go-sdk 0.6.5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,960 kB
  • sloc: makefile: 13
file content (76 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package telemetry

import (
	"testing"
)

type MockMetric struct {
	Name        string
	Description string
}

func (m *MockMetric) GetName() string {
	return m.Name
}

func (m *MockMetric) GetDescription() string {
	return m.Description
}

func TestMetric_GetName(t *testing.T) {
	metricName := "test-metric"
	metricDescription := "This is a test metric."

	metric := &Metric{
		Name:        metricName,
		Description: metricDescription,
		MetricInterface: &MockMetric{
			Name:        metricName,
			Description: metricDescription,
		},
	}

	if metric.GetName() != metricName {
		t.Errorf("Expected Metric Name to be '%s', but got '%s'", metricName, metric.GetName())
	}

	if metric.GetDescription() != metricDescription {
		t.Errorf("Expected Metric Description to be '%s', but got '%s'", metricDescription, metric.GetDescription())
	}
}

func TestMetricInterfaceImplementation(t *testing.T) {
	metricName := "interface-metric"
	metricDescription := "Metric implemented using MetricInterface."

	mockMetric := &MockMetric{
		Name:        metricName,
		Description: metricDescription,
	}

	metric := &Metric{
		Name:            metricName,
		Description:     metricDescription,
		MetricInterface: mockMetric,
	}

	if metric.MetricInterface.GetName() != metricName {
		t.Errorf("Expected MetricInterface Name to be '%s', but got '%s'", metricName, metric.MetricInterface.GetName())
	}

	if metric.MetricInterface.GetDescription() != metricDescription {
		t.Errorf("Expected MetricInterface Description to be '%s', but got '%s'", metricDescription, metric.MetricInterface.GetDescription())
	}
}

func TestEmptyMetric(t *testing.T) {
	metric := &Metric{}

	if metric.GetName() != "" {
		t.Errorf("Expected Metric Name to be empty, but got '%s'", metric.GetName())
	}

	if metric.GetDescription() != "" {
		t.Errorf("Expected Metric Description to be empty, but got '%s'", metric.GetDescription())
	}
}