Contains the Concourse pipeline definition for building a line-server container
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.6 KiB

  1. package main
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "os"
  6. "strings"
  7. "testing"
  8. "github.com/zenazn/goji"
  9. )
  10. var a = 0
  11. func TestSetup(t *testing.T) {
  12. Config.siteURL = "http://linx.example.org/"
  13. Config.filesDir = "/tmp/" + randomString(10)
  14. Config.metaDir = Config.filesDir + "_meta"
  15. Config.noLogs = true
  16. Config.siteName = "linx"
  17. setup()
  18. }
  19. func TestIndex(t *testing.T) {
  20. w := httptest.NewRecorder()
  21. req, err := http.NewRequest("GET", "/", nil)
  22. if err != nil {
  23. t.Fatal(err)
  24. }
  25. goji.DefaultMux.ServeHTTP(w, req)
  26. if !strings.Contains(w.Body.String(), "file-uploader") {
  27. t.Error("String 'file-uploader' not found in index response")
  28. }
  29. }
  30. func TestNotFound(t *testing.T) {
  31. w := httptest.NewRecorder()
  32. req, err := http.NewRequest("GET", "/url/should/not/exist", nil)
  33. if err != nil {
  34. t.Fatal(err)
  35. }
  36. goji.DefaultMux.ServeHTTP(w, req)
  37. if w.Code != 404 {
  38. t.Fatalf("Expected 404, got %d", w.Code)
  39. }
  40. }
  41. func TestFileNotFound(t *testing.T) {
  42. w := httptest.NewRecorder()
  43. filename := randomString(10)
  44. req, err := http.NewRequest("GET", "/selif/"+filename, nil)
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. goji.DefaultMux.ServeHTTP(w, req)
  49. if w.Code != 404 {
  50. t.Fatalf("Expected 404, got %d", w.Code)
  51. }
  52. }
  53. func TestDisplayNotFound(t *testing.T) {
  54. w := httptest.NewRecorder()
  55. filename := randomString(10)
  56. req, err := http.NewRequest("GET", "/"+filename, nil)
  57. if err != nil {
  58. t.Fatal(err)
  59. }
  60. goji.DefaultMux.ServeHTTP(w, req)
  61. if w.Code != 404 {
  62. t.Fatalf("Expected 404, got %d", w.Code)
  63. }
  64. }
  65. func TestShutdown(t *testing.T) {
  66. os.RemoveAll(Config.filesDir)
  67. os.RemoveAll(Config.metaDir)
  68. }