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.

73 lines
1.5 KiB

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