Skip to content

Commit

Permalink
test: Add some tests to the GetSitemapData function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 26, 2024
1 parent c3cf107 commit 10bb240
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions cmd/server/handle-routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,42 @@ func TestHandleRoutes(t *testing.T) {
assert.NotEqual(t, nil, body["error"])

os.Setenv("CS_API_KEY", oldApiKey)

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "sitemap-data"),
true,
)
assert.Equal(t, nil, err)
assert.Equal(t, nil, body["error"])

oldApiKey = os.Getenv("CS_API_KEY")
os.Setenv("CS_API_KEY", "bogus")

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "sitemap-data"),
true,
)
assert.Equal(t, nil, err)
assert.Equal(t, nil, body["error"])

os.Setenv("CS_API_KEY", oldApiKey)

oldDb := os.Getenv("DB_CONN")
os.Setenv("DB_CONN", "file:/")
err = database.Connect()
assert.Equal(t, nil, err)

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "sitemap-data"),
true,
)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, body["error"])

os.Setenv("DB_CONN", oldDb)
}

func request(method string, path string, withAuthToken bool) (body map[string]interface{}, err error) {
Expand Down

0 comments on commit 10bb240

Please sign in to comment.