diff --git a/README.md b/README.md index ffc26dce..570e2e18 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ # 🚀 Spacebin -[![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) +[![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) [![Go report card](https://goreportcard.com/badge/github.com/orca-group/spirit)](https://goreportcard.com/report/github.com/orca-group/spirit) 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. diff --git a/internal/server/server_test.go b/internal/server/server_test.go index fc5f8023..f616af7d 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -18,6 +18,7 @@ package server_test import ( "net/http" + "os" "testing" "github.com/orca-group/spirit/internal/database" @@ -25,6 +26,63 @@ import ( "github.com/stretchr/testify/require" ) +func TestMountStatic(t *testing.T) { + // Create server and mount expected static files + s := server.NewServer(&mockConfig, &database.MockDatabase{}) + + s.MountStatic() + + // Check robots.txt + req, _ := http.NewRequest(http.MethodGet, "/robots.txt", nil) + res := executeRequest(req, s) + + checkResponseCode(t, http.StatusOK, res.Result().StatusCode) + + file, _ := os.ReadFile("web/static/robots.txt") + require.Equal(t, res.Body.String(), string(file)) + + // Check presence of CSS files + globalCssRequest, _ := http.NewRequest(http.MethodGet, "/static/global.css", nil) + globalCssResponse := executeRequest(globalCssRequest, s) + checkResponseCode(t, http.StatusOK, globalCssResponse.Result().StatusCode) + + monokaiCssRequest, _ := http.NewRequest(http.MethodGet, "/static/monokai.min.css", nil) + monokaiCssResponse := executeRequest(monokaiCssRequest, s) + checkResponseCode(t, http.StatusOK, monokaiCssResponse.Result().StatusCode) + + normalizeCssRequest, _ := http.NewRequest(http.MethodGet, "/static/normalize.css", nil) + normalizeCssResponse := executeRequest(normalizeCssRequest, s) + checkResponseCode(t, http.StatusOK, normalizeCssResponse.Result().StatusCode) + + // Check presence of JS files + appJsRequest, _ := http.NewRequest(http.MethodGet, "/static/app.js", nil) + appJsResponse := executeRequest(appJsRequest, s) + checkResponseCode(t, http.StatusOK, appJsResponse.Result().StatusCode) + + highlightJsRequest, _ := http.NewRequest(http.MethodGet, "/static/highlight.min.js", nil) + highlightJsResponse := executeRequest(highlightJsRequest, s) + checkResponseCode(t, http.StatusOK, highlightJsResponse.Result().StatusCode) + + // Check presence of image files (logo.svg, favicon.ico) + faviconRequest, _ := http.NewRequest(http.MethodGet, "/static/favicon.ico", nil) + faviconResponse := executeRequest(faviconRequest, s) + checkResponseCode(t, http.StatusOK, faviconResponse.Result().StatusCode) + + logoRequest, _ := http.NewRequest(http.MethodGet, "/static/logo.svg", nil) + logoResponse := executeRequest(logoRequest, s) + checkResponseCode(t, http.StatusOK, logoResponse.Result().StatusCode) + + // Check index file exists and returns the correct content + indexRequest, _ := http.NewRequest(http.MethodGet, "/", nil) + indexResponse := executeRequest(indexRequest, s) + + checkResponseCode(t, http.StatusOK, indexResponse.Result().StatusCode) + + indexFile, _ := os.ReadFile("./web/index.html") + + require.Equal(t, string(indexFile), indexResponse.Body.String()) +} + func TestRegisterHeaders(t *testing.T) { s := server.NewServer(&mockConfig, &database.MockDatabase{})