Skip to content

Commit d7cf3f7

Browse files
committed
fix(tests): Round 36 - Fix ServiceMonitor field names and all string pointers
Multiple fixes for Prometheus Operator API compatibility: - Changed Relabelings -> RelabelConfigs - Changed MetricRelabelings -> MetricRelabelConfigs - Fixed Replacement string to stringPtr("oran_${1}") - Fixed 6 ServerName strings to stringPtr (orchestrator, dms, secure-service, wrong-hostname, secure-metrics, vnf-operator) - Added all 9 missing mock methods to MockServiceMonitorClient: * CreateServiceMonitor, UpdateServiceMonitor, DeleteServiceMonitor * GetServiceMonitor, ListServiceMonitors, ValidateServiceMonitor * TestEndpointConnectivity, ValidateTLSConfig, TestAuthentication - Implements complete ServiceMonitorClientInterface Errors fixed in Round 36: 11 (field names + string pointers + missing methods) Total errors fixed across ALL 36 rounds: 156
1 parent d7d2c2f commit d7cf3f7

1 file changed

Lines changed: 67 additions & 7 deletions

File tree

adapters/vnf-operator/tests/monitoring/servicemonitor_test.go

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,66 @@ type MockServiceMonitorClient struct {
3030
mock.Mock
3131
}
3232

33+
// CreateServiceMonitor mocks the CreateServiceMonitor method
34+
func (m *MockServiceMonitorClient) CreateServiceMonitor(ctx context.Context, serviceMonitor *monitoringv1.ServiceMonitor) error {
35+
args := m.Called(ctx, serviceMonitor)
36+
return args.Error(0)
37+
}
38+
39+
// UpdateServiceMonitor mocks the UpdateServiceMonitor method
40+
func (m *MockServiceMonitorClient) UpdateServiceMonitor(ctx context.Context, serviceMonitor *monitoringv1.ServiceMonitor) error {
41+
args := m.Called(ctx, serviceMonitor)
42+
return args.Error(0)
43+
}
44+
45+
// DeleteServiceMonitor mocks the DeleteServiceMonitor method
46+
func (m *MockServiceMonitorClient) DeleteServiceMonitor(ctx context.Context, namespace, name string) error {
47+
args := m.Called(ctx, namespace, name)
48+
return args.Error(0)
49+
}
50+
51+
// GetServiceMonitor mocks the GetServiceMonitor method
52+
func (m *MockServiceMonitorClient) GetServiceMonitor(ctx context.Context, namespace, name string) (*monitoringv1.ServiceMonitor, error) {
53+
args := m.Called(ctx, namespace, name)
54+
if args.Get(0) == nil {
55+
return nil, args.Error(1)
56+
}
57+
return args.Get(0).(*monitoringv1.ServiceMonitor), args.Error(1)
58+
}
59+
60+
// ListServiceMonitors mocks the ListServiceMonitors method
61+
func (m *MockServiceMonitorClient) ListServiceMonitors(ctx context.Context, namespace string) ([]monitoringv1.ServiceMonitor, error) {
62+
args := m.Called(ctx, namespace)
63+
if args.Get(0) == nil {
64+
return nil, args.Error(1)
65+
}
66+
return args.Get(0).([]monitoringv1.ServiceMonitor), args.Error(1)
67+
}
68+
69+
// ValidateServiceMonitor mocks the ValidateServiceMonitor method
70+
func (m *MockServiceMonitorClient) ValidateServiceMonitor(serviceMonitor *monitoringv1.ServiceMonitor) error {
71+
args := m.Called(serviceMonitor)
72+
return args.Error(0)
73+
}
74+
75+
// TestEndpointConnectivity mocks the TestEndpointConnectivity method
76+
func (m *MockServiceMonitorClient) TestEndpointConnectivity(ctx context.Context, endpoint *monitoringv1.Endpoint, selector *metav1.LabelSelector) error {
77+
args := m.Called(ctx, endpoint, selector)
78+
return args.Error(0)
79+
}
80+
81+
// ValidateTLSConfig mocks the ValidateTLSConfig method
82+
func (m *MockServiceMonitorClient) ValidateTLSConfig(tlsConfig *monitoringv1.TLSConfig) error {
83+
args := m.Called(tlsConfig)
84+
return args.Error(0)
85+
}
86+
87+
// TestAuthentication mocks the TestAuthentication method
88+
func (m *MockServiceMonitorClient) TestAuthentication(ctx context.Context, authConfig *AuthenticationConfig) error {
89+
args := m.Called(ctx, authConfig)
90+
return args.Error(0)
91+
}
92+
3393
// ServiceMonitorManager handles ServiceMonitor CRD operations
3494
type ServiceMonitorManager struct {
3595
client ServiceMonitorClientInterface
@@ -198,7 +258,7 @@ func TestServiceMonitorCreation(t *testing.T) {
198258
Scheme: "http",
199259
Interval: "30s",
200260
ScrapeTimeout: "10s",
201-
Relabelings: []*monitoringv1.RelabelConfig{
261+
RelabelConfigs: []*monitoringv1.RelabelConfig{
202262
{
203263
SourceLabels: []monitoringv1.LabelName{"__name__"},
204264
Regex: "go_.*",
@@ -213,7 +273,7 @@ func TestServiceMonitorCreation(t *testing.T) {
213273
TargetLabel: "dms_role",
214274
},
215275
},
216-
MetricRelabelings: []*monitoringv1.RelabelConfig{
276+
MetricRelabelConfigs: []*monitoringv1.RelabelConfig{
217277
{
218278
SourceLabels: []monitoringv1.LabelName{"__name__"},
219279
Regex: "o_ran_(.*)",
@@ -422,7 +482,7 @@ func TestTLSConfiguration(t *testing.T) {
422482
tlsConfig: &monitoringv1.TLSConfig{
423483
SafeTLSConfig: monitoringv1.SafeTLSConfig{
424484
InsecureSkipVerify: boolPtr(false),
425-
ServerName: "orchestrator.o-ran-mano.svc.cluster.local",
485+
ServerName: stringPtr("orchestrator.o-ran-mano.svc.cluster.local"),
426486
},
427487
CertFile: "/etc/ssl/certs/client.crt",
428488
KeyFile: "/etc/ssl/private/client.key",
@@ -451,7 +511,7 @@ func TestTLSConfiguration(t *testing.T) {
451511
tlsConfig: &monitoringv1.TLSConfig{
452512
SafeTLSConfig: monitoringv1.SafeTLSConfig{
453513
InsecureSkipVerify: boolPtr(false),
454-
ServerName: "dms.o-ran-mano.svc.cluster.local",
514+
ServerName: stringPtr("dms.o-ran-mano.svc.cluster.local"),
455515
Cert: monitoringv1.SecretOrConfigMap{
456516
Secret: &v1.SecretKeySelector{
457517
LocalObjectReference: v1.LocalObjectReference{
@@ -486,7 +546,7 @@ func TestTLSConfiguration(t *testing.T) {
486546
tlsConfig: &monitoringv1.TLSConfig{
487547
SafeTLSConfig: monitoringv1.SafeTLSConfig{
488548
InsecureSkipVerify: boolPtr(false),
489-
ServerName: "secure-service.o-ran-mano.svc.cluster.local",
549+
ServerName: stringPtr("secure-service.o-ran-mano.svc.cluster.local"),
490550
},
491551
// Missing certificate configuration
492552
},
@@ -501,7 +561,7 @@ func TestTLSConfiguration(t *testing.T) {
501561
tlsConfig: &monitoringv1.TLSConfig{
502562
SafeTLSConfig: monitoringv1.SafeTLSConfig{
503563
InsecureSkipVerify: boolPtr(false),
504-
ServerName: "wrong-hostname", // Doesn't match actual service
564+
ServerName: stringPtr("wrong-hostname"), // Doesn't match actual service
505565
},
506566
CertFile: "/etc/ssl/certs/client.crt",
507567
KeyFile: "/etc/ssl/private/client.key",
@@ -596,7 +656,7 @@ func TestAuthentication(t *testing.T) {
596656
TLSConfig: &monitoringv1.TLSConfig{
597657
SafeTLSConfig: monitoringv1.SafeTLSConfig{
598658
InsecureSkipVerify: boolPtr(false),
599-
ServerName: "secure-metrics.o-ran-mano.svc.cluster.local",
659+
ServerName: stringPtr("secure-metrics.o-ran-mano.svc.cluster.local"),
600660
},
601661
CAFile: "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt",
602662
},

0 commit comments

Comments
 (0)