@@ -7,11 +7,13 @@ import (
77 "os"
88 "strings"
99 "testing"
10+
11+ "github.com/stretchr/testify/assert"
1012)
1113
12- func TestAPI (t * testing.T ) {
13- client := & http.Client {}
14+ var client * http.Client = & http.Client {}
1415
16+ func TestAPI (t * testing.T ) {
1517 baseUrl := os .Getenv ("TEST_BASE_URL" )
1618 if baseUrl == "" {
1719 baseUrl = "http://localhost:9115/probe"
@@ -64,6 +66,36 @@ func TestAPI(t *testing.T) {
6466 }
6567}
6668
69+ func TestResponseContent (t * testing.T ) {
70+ baseUrl := os .Getenv ("TEST_BASE_URL" )
71+ if baseUrl == "" {
72+ baseUrl = "http://localhost:9115/probe"
73+ }
74+
75+ url := fmt .Sprintf ("%s?group=%s&project=%s" , baseUrl , "alwojnarowicz" , "some-project1" )
76+ req , err := http .NewRequest ("GET" , url , nil )
77+ if err != nil {
78+ t .Fatalf ("creating request: %v" , err )
79+ }
80+
81+ resp , err := client .Do (req )
82+ if err != nil {
83+ t .Fatalf ("making request: %v" , err )
84+ }
85+ defer saveCloseRespBody (resp )
86+
87+ bodyText , err := io .ReadAll (resp .Body )
88+ if err != nil {
89+ t .Fatalf ("reading response body: %v" , err )
90+ }
91+
92+ assert .Contains (t , string (bodyText ), "gitlab_probe_success" )
93+ assert .Contains (t , string (bodyText ), "gitlab_host" )
94+ assert .Contains (t , string (bodyText ), "gitlab_pipeline_total" )
95+ assert .Contains (t , string (bodyText ), "gitlab_pipeline_total" )
96+ assert .Contains (t , string (bodyText ), "exporter_probe_duration_seconds" )
97+ }
98+
6799func saveCloseRespBody (resp * http.Response ) {
68100 err := resp .Body .Close ()
69101 if err != nil {
0 commit comments