Don't run test if in CI

This commit is contained in:
2024-01-21 21:18:33 +01:00
parent 8f93f33a39
commit e4a9b8a790

View File

@ -1,11 +1,13 @@
package main package main
import ( import (
"os"
"testing" "testing"
) )
// Returns a string with a length between 1 and 2000 characters // Returns a string with a length between 1 and 2000 characters
func TestGetPostsFromReddit_ReturnsPostWithValidLength(t *testing.T) { func TestGetPostsFromReddit_ReturnsPostWithValidLength(t *testing.T) {
if os.Getenv("CI") == "" {
subreddit := "celebs" subreddit := "celebs"
post, err := GetPostsFromReddit(subreddit) post, err := GetPostsFromReddit(subreddit)
if err != nil { if err != nil {
@ -14,6 +16,9 @@ func TestGetPostsFromReddit_ReturnsPostWithValidLength(t *testing.T) {
if len(post) < 1 || len(post) > 2000 { if len(post) < 1 || len(post) > 2000 {
t.Errorf("Post length is not within the valid range") t.Errorf("Post length is not within the valid range")
} }
} else {
t.Skip("Skipping test in CI environment as the IP is probably blocked by Reddit")
}
} }
// Returns an error when the subreddit does not exist // Returns an error when the subreddit does not exist