youtube_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is subject to a 1-clause BSD license.
  2. // Its contents can be found in the enclosed LICENSE file.
  3. package youtube
  4. import (
  5. "testing"
  6. "time"
  7. )
  8. // Put your youtube API key here.
  9. // see: https://console.developers.google.com/apis
  10. const ApiKey = ""
  11. func TestParseISO8601(t *testing.T) {
  12. testISO8601(t, "", 0)
  13. testISO8601(t, "PY", 0)
  14. testISO8601(t, "PT", 0)
  15. testISO8601(t, "P1Y", time.Hour*8760)
  16. testISO8601(t, "P1H", time.Hour)
  17. testISO8601(t, "PT1H", time.Hour)
  18. testISO8601(t, "PTz1H", 0)
  19. testISO8601(t, "P 1H", 0)
  20. testISO8601(t, "P2MT2M33S", 2*time.Hour*730+2*time.Minute+33*time.Second)
  21. }
  22. func testISO8601(t *testing.T, in string, want time.Duration) {
  23. have := parseISO8601(in)
  24. if want != have {
  25. t.Fatalf("ISO 8601 mismatch for %q; want: %s\nhave %s", in, want, have)
  26. }
  27. }
  28. func TestGetVideoInfo(t *testing.T) {
  29. if len(ApiKey) == 0 {
  30. return
  31. }
  32. const videoID = "dQw4w9WgXcQ"
  33. info, err := GetVideoInfo(ApiKey, videoID)
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. if info.ID != videoID {
  38. t.Fatalf("Video ID mismatch; want %q\nhave: %q", videoID, info.ID)
  39. }
  40. }