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.

60 lines
1.3 KiB

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