Skip to content

Commit b5341cc

Browse files
committed
test(server): MountStatic tests
1 parent 510c4db commit b5341cc

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
# 🚀 Spacebin
1010

11-
[![codecov](https://codecov.io/gh/orca-group/spirit/branch/develop/graph/badge.svg?token=NNZDS74DB1)](https://codecov.io/gh/orca-group/spirit) [![GitHub license](https://img.shields.io/github/license/orca-group/spirit?color=%20%23e34b4a&logoColor=%23000000)](LICENSE) [![Build](https://github.com/orca-group/spirit/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/orca-group/spirit/actions/workflows/build.yml)
11+
[![codecov](https://codecov.io/gh/lukewhrit/spacebin/graph/badge.svg?token=NNZDS74DB1)](https://codecov.io/gh/lukewhrit/spacebin) [![GitHub license](https://img.shields.io/github/license/orca-group/spirit?color=%20%23e34b4a&logoColor=%23000000)](LICENSE) [![Build](https://github.com/orca-group/spirit/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/orca-group/spirit/actions/workflows/build.yml)
1212
[![Go report card](https://goreportcard.com/badge/github.com/orca-group/spirit)](https://goreportcard.com/report/github.com/orca-group/spirit)
1313

1414
Spacebin is a modern Pastebin server implemented in Go and maintained by Luke Whritenour. It is capable of serving notes, novels, code, or any other form of text! Spacebin was designed to be fast and reliable, avoiding the problems of many current pastebin servers. Spacebin features JavaScript-based text highlighting, but works completely fine with JS disabled. Besides text highlighting, we have many more features in the works. It is entirely self-hostable, and available in a Docker image.

internal/server/server_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,71 @@ package server_test
1818

1919
import (
2020
"net/http"
21+
"os"
2122
"testing"
2223

2324
"github.com/orca-group/spirit/internal/database"
2425
"github.com/orca-group/spirit/internal/server"
2526
"github.com/stretchr/testify/require"
2627
)
2728

29+
func TestMountStatic(t *testing.T) {
30+
// Create server and mount expected static files
31+
s := server.NewServer(&mockConfig, &database.MockDatabase{})
32+
33+
s.MountStatic()
34+
35+
// Check robots.txt
36+
req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil)
37+
res := executeRequest(req, s)
38+
39+
checkResponseCode(t, http.StatusOK, res.Result().StatusCode)
40+
41+
file, _ := os.ReadFile("web/static/robots.txt")
42+
require.Equal(t, res.Body.String(), string(file))
43+
44+
// Check presence of CSS files
45+
globalCssRequest, _ := http.NewRequest(http.MethodGet, "/static/global.css", nil)
46+
globalCssResponse := executeRequest(globalCssRequest, s)
47+
checkResponseCode(t, http.StatusOK, globalCssResponse.Result().StatusCode)
48+
49+
monokaiCssRequest, _ := http.NewRequest(http.MethodGet, "/static/monokai.min.css", nil)
50+
monokaiCssResponse := executeRequest(monokaiCssRequest, s)
51+
checkResponseCode(t, http.StatusOK, monokaiCssResponse.Result().StatusCode)
52+
53+
normalizeCssRequest, _ := http.NewRequest(http.MethodGet, "/static/normalize.css", nil)
54+
normalizeCssResponse := executeRequest(normalizeCssRequest, s)
55+
checkResponseCode(t, http.StatusOK, normalizeCssResponse.Result().StatusCode)
56+
57+
// Check presence of JS files
58+
appJsRequest, _ := http.NewRequest(http.MethodGet, "/static/app.js", nil)
59+
appJsResponse := executeRequest(appJsRequest, s)
60+
checkResponseCode(t, http.StatusOK, appJsResponse.Result().StatusCode)
61+
62+
highlightJsRequest, _ := http.NewRequest(http.MethodGet, "/static/highlight.min.js", nil)
63+
highlightJsResponse := executeRequest(highlightJsRequest, s)
64+
checkResponseCode(t, http.StatusOK, highlightJsResponse.Result().StatusCode)
65+
66+
// Check presence of image files (logo.svg, favicon.ico)
67+
faviconRequest, _ := http.NewRequest(http.MethodGet, "/static/favicon.ico", nil)
68+
faviconResponse := executeRequest(faviconRequest, s)
69+
checkResponseCode(t, http.StatusOK, faviconResponse.Result().StatusCode)
70+
71+
logoRequest, _ := http.NewRequest(http.MethodGet, "/static/logo.svg", nil)
72+
logoResponse := executeRequest(logoRequest, s)
73+
checkResponseCode(t, http.StatusOK, logoResponse.Result().StatusCode)
74+
75+
// Check index file exists and returns the correct content
76+
indexRequest, _ := http.NewRequest(http.MethodGet, "/", nil)
77+
indexResponse := executeRequest(indexRequest, s)
78+
79+
checkResponseCode(t, http.StatusOK, indexResponse.Result().StatusCode)
80+
81+
indexFile, _ := os.ReadFile("./web/index.html")
82+
83+
require.Equal(t, string(indexFile), indexResponse.Body.String())
84+
}
85+
2886
func TestRegisterHeaders(t *testing.T) {
2987
s := server.NewServer(&mockConfig, &database.MockDatabase{})
3088

0 commit comments

Comments
 (0)