Skip to content

Commit

Permalink
test(server): MountStatic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewhrit committed Jun 28, 2024
1 parent 510c4db commit b5341cc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
58 changes: 58 additions & 0 deletions internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,71 @@ package server_test

import (
"net/http"
"os"
"testing"

"github.com/orca-group/spirit/internal/database"
"github.com/orca-group/spirit/internal/server"
"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{})

Expand Down

0 comments on commit b5341cc

Please sign in to comment.