-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds tests for Ports in exporter.go
- Loading branch information
1 parent
3bb5fdf
commit ab899d4
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
internal/manifests/collector/parser/exporter/exporter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package exporter | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
func TestPorts(t *testing.T) { | ||
tests := []struct { | ||
testName string | ||
parser *PrometheusExporterParser | ||
want []v1.ServicePort | ||
}{ | ||
{ | ||
testName: "Valid Configuration", | ||
parser: &PrometheusExporterParser{ | ||
name: "test-exporter", | ||
config: map[interface{}]interface{}{ | ||
"endpoint": "http://myprometheus.io:9090", | ||
}, | ||
}, | ||
want: []v1.ServicePort{ | ||
{ | ||
Name: "test-exporter", | ||
Port: 9091, | ||
}, | ||
}, | ||
}, | ||
{ | ||
testName: "Empty Configuration", | ||
parser: &PrometheusExporterParser{ | ||
name: "test-exporter", | ||
config: nil, // Simulate no configuration provided | ||
}, | ||
want: []v1.ServicePort{ | ||
{ | ||
Name: "test-exporter", | ||
Port: defaultPrometheusPort, | ||
TargetPort: intstr.FromInt(int(defaultPrometheusPort)), | ||
Protocol: v1.ProtocolTCP, | ||
}, | ||
}, | ||
}, | ||
{ | ||
testName: "Invalid Endpoint No Port", | ||
parser: &PrometheusExporterParser{ | ||
name: "test-exporter", | ||
config: map[interface{}]interface{}{ | ||
"endpoint": "invalidendpoint", | ||
}, | ||
}, | ||
want: []v1.ServicePort{}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.testName, func(t *testing.T) { | ||
if got, _ := tt.parser.Ports(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("Ports(%v, = %v, want %v", tt.parser, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |