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.

74 lines
1.5 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "testing"
  6. "github.com/andreimarcu/linx-server/torrent"
  7. "github.com/zeebo/bencode"
  8. )
  9. func TestCreateTorrent(t *testing.T) {
  10. fileName := "server.go"
  11. var decoded torrent.Torrent
  12. f, err := os.Open("server.go")
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. defer f.Close()
  17. encoded, err := createTorrent(fileName, f, nil)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. bencode.DecodeBytes(encoded, &decoded)
  22. if decoded.Encoding != "UTF-8" {
  23. t.Fatalf("Encoding was %s, expected UTF-8", decoded.Encoding)
  24. }
  25. if decoded.Info.Name != "server.go" {
  26. t.Fatalf("Name was %s, expected server.go", decoded.Info.Name)
  27. }
  28. if decoded.Info.PieceLength <= 0 {
  29. t.Fatal("Expected a piece length, got none")
  30. }
  31. if len(decoded.Info.Pieces) <= 0 {
  32. t.Fatal("Expected at least one piece, got none")
  33. }
  34. if decoded.Info.Length <= 0 {
  35. t.Fatal("Length was less than or equal to 0, expected more")
  36. }
  37. tracker := fmt.Sprintf("%s%s%s", Config.siteURL, Config.selifPath, fileName)
  38. if decoded.UrlList[0] != tracker {
  39. t.Fatalf("First entry in URL list was %s, expected %s", decoded.UrlList[0], tracker)
  40. }
  41. }
  42. func TestCreateTorrentWithImage(t *testing.T) {
  43. var decoded torrent.Torrent
  44. f, err := os.Open("static/images/404.jpg")
  45. if err != nil {
  46. t.Fatal(err)
  47. }
  48. defer f.Close()
  49. encoded, err := createTorrent("test.jpg", f, nil)
  50. if err != nil {
  51. t.Fatal(err)
  52. }
  53. bencode.DecodeBytes(encoded, &decoded)
  54. if decoded.Info.Pieces != "r\x01\x80j\x99\x84\n\xd3dZ;1NX\xec;\x9d$+f" {
  55. t.Fatal("Torrent pieces did not match expected pieces for image")
  56. }
  57. }