-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
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
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,72 @@ | ||
package collector | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/onedr0p/exportarr/internal/arr/config" | ||
"github.com/onedr0p/exportarr/internal/test_util" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const radarr_test_fixtures_path = "../test_fixtures/radarr/" | ||
|
||
func newTestRadarrServer(t *testing.T, fn func(http.ResponseWriter, *http.Request)) (*httptest.Server, error) { | ||
return test_util.NewTestServer(t, radarr_test_fixtures_path, fn) | ||
} | ||
|
||
func TestRadarrCollect(t *testing.T) { | ||
require := require.New(t) | ||
ts, err := newTestRadarrServer(t, func(w http.ResponseWriter, r *http.Request) { | ||
require.Contains(r.URL.Path, "/api/") | ||
}) | ||
require.NoError(err) | ||
|
||
defer ts.Close() | ||
|
||
config := &config.ArrConfig{ | ||
URL: ts.URL, | ||
App: "radarr", | ||
ApiKey: test_util.API_KEY, | ||
ApiVersion: "v3", | ||
} | ||
collector := NewRadarrCollector(config) | ||
require.NoError(err) | ||
|
||
b, err := os.ReadFile(radarr_test_fixtures_path + "expected_metrics.txt") | ||
require.NoError(err) | ||
|
||
expected := strings.Replace(string(b), "SOMEURL", ts.URL, -1) | ||
f := strings.NewReader(expected) | ||
|
||
require.NotPanics(func() { | ||
err = testutil.CollectAndCompare(collector, f) | ||
}) | ||
require.NoError(err) | ||
} | ||
|
||
func TestRadarrCollect_FailureDoesntPanic(t *testing.T) { | ||
require := require.New(t) | ||
|
||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusInternalServerError) | ||
})) | ||
defer ts.Close() | ||
|
||
config := &config.ArrConfig{ | ||
URL: ts.URL, | ||
ApiKey: test_util.API_KEY, | ||
} | ||
collector := NewRadarrCollector(config) | ||
|
||
f := strings.NewReader("") | ||
|
||
require.NotPanics(func() { | ||
err := testutil.CollectAndCompare(collector, f) | ||
require.Error(err) | ||
}, "Collecting metrics should not panic on failure") | ||
} |
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,33 @@ | ||
# HELP radarr_movie_downloaded_total Total number of downloaded movies | ||
# TYPE radarr_movie_downloaded_total gauge | ||
radarr_movie_downloaded_total{url="SOMEURL"} 4 | ||
# HELP radarr_movie_editions Total number of movies with `edition` set | ||
# TYPE radarr_movie_editions gauge | ||
radarr_movie_editions{url="SOMEURL"} 2 | ||
# HELP radarr_movie_filesize_total Total filesize of all movies | ||
# TYPE radarr_movie_filesize_total gauge | ||
radarr_movie_filesize_total{url="SOMEURL"} 1.47062956689e+11 | ||
# HELP radarr_movie_missing_total Total number of missing movies | ||
# TYPE radarr_movie_missing_total gauge | ||
radarr_movie_missing_total{url="SOMEURL"} 2 | ||
# HELP radarr_movie_monitored_total Total number of monitored movies | ||
# TYPE radarr_movie_monitored_total gauge | ||
radarr_movie_monitored_total{url="SOMEURL"} 7 | ||
# HELP radarr_movie_quality_total Total number of downloaded movies by quality | ||
# TYPE radarr_movie_quality_total gauge | ||
radarr_movie_quality_total{quality="Bluray-1080p",url="SOMEURL"} 1 | ||
radarr_movie_quality_total{quality="Bluray-2160p",url="SOMEURL"} 2 | ||
radarr_movie_quality_total{quality="Remux-2160p",url="SOMEURL"} 1 | ||
# HELP radarr_movie_tag_total Total number of downloaded movies by tag | ||
# TYPE radarr_movie_tag_total gauge | ||
radarr_movie_tag_total{tag="somelabel",url="SOMEURL"} 3 | ||
radarr_movie_tag_total{tag="someotherlabel",url="SOMEURL"} 3 | ||
# HELP radarr_movie_total Total number of movies | ||
# TYPE radarr_movie_total gauge | ||
radarr_movie_total{url="SOMEURL"} 8 | ||
# HELP radarr_movie_unmonitored_total Total number of unmonitored movies | ||
# TYPE radarr_movie_unmonitored_total gauge | ||
radarr_movie_unmonitored_total{url="SOMEURL"} 1 | ||
# HELP radarr_movie_wanted_total Total number of wanted movies | ||
# TYPE radarr_movie_wanted_total gauge | ||
radarr_movie_wanted_total{url="SOMEURL"} 1 |
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,93 @@ | ||
[ | ||
{ | ||
"status": "released", | ||
"hasFile": true, | ||
"monitored": true, | ||
"isAvailable": true, | ||
"movieFile": { | ||
"size": 75973665026, | ||
"quality": { | ||
"quality": { | ||
"name": "Remux-2160p" | ||
} | ||
} | ||
}, | ||
"qualityProfileId": 11 | ||
}, | ||
{ | ||
"status": "released", | ||
"hasFile": true, | ||
"monitored": true, | ||
"isAvailable": true, | ||
"movieFile": { | ||
"size": 29102046776, | ||
"quality": { | ||
"quality": { | ||
"name": "Bluray-2160p" | ||
} | ||
} | ||
}, | ||
"qualityProfileId": 10 | ||
}, | ||
{ | ||
"status": "released", | ||
"hasFile": true, | ||
"qualityProfileId": 10, | ||
"monitored": true, | ||
"isAvailable": true, | ||
"movieFile": { | ||
"size": 27913422877, | ||
"quality": { | ||
"quality": { | ||
"name": "Bluray-2160p" | ||
} | ||
}, | ||
"edition": "someOther" | ||
} | ||
}, | ||
{ | ||
"status": "announced", | ||
"hasFile": false, | ||
"qualityProfileId": 10, | ||
"monitored": true, | ||
"isAvailable": true | ||
}, | ||
{ | ||
"status": "announced", | ||
"hasFile": false, | ||
"qualityProfileId": 11, | ||
"monitored": true, | ||
"isAvailable": true | ||
}, | ||
{ | ||
"status": "announced", | ||
"hasFile": false, | ||
"qualityProfileId": 10, | ||
"monitored": false, | ||
"isAvailable": true | ||
}, | ||
{ | ||
"status": "announced", | ||
"hasFile": false, | ||
"qualityProfileId": 10, | ||
"monitored": true, | ||
"isAvailable": false | ||
}, | ||
{ | ||
"status": "released", | ||
"hasFile": true, | ||
"qualityProfileId": 9, | ||
"monitored": true, | ||
"minimumAvailability": "announced", | ||
"isAvailable": true, | ||
"movieFile": { | ||
"size": 14073822010, | ||
"quality": { | ||
"quality": { | ||
"name": "Bluray-1080p" | ||
} | ||
}, | ||
"edition": "IMAX" | ||
} | ||
} | ||
] |
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,34 @@ | ||
[ | ||
{ | ||
"label": "somelabel", | ||
"delayProfileIds": [], | ||
"importListIds": [], | ||
"notificationIds": [], | ||
"releaseProfileIds": [], | ||
"indexerIds": [], | ||
"downloadClientIds": [], | ||
"autoTagIds": [], | ||
"movieIds": [ | ||
37, | ||
47, | ||
69 | ||
], | ||
"id": 1 | ||
}, | ||
{ | ||
"label": "someotherlabel", | ||
"delayProfileIds": [], | ||
"importListIds": [], | ||
"notificationIds": [], | ||
"releaseProfileIds": [], | ||
"indexerIds": [], | ||
"downloadClientIds": [], | ||
"autoTagIds": [], | ||
"movieIds": [ | ||
12, | ||
34, | ||
99 | ||
], | ||
"id": 2 | ||
} | ||
] |