pyrogram_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package sessionimport
  2. import (
  3. "os"
  4. "path/filepath"
  5. "testing"
  6. )
  7. // Real protocol-number session file lives at D:\spider\tgs\13252753163\13252753163.session
  8. // Test skips when that file is missing so CI environments don't break.
  9. func TestConvertPyrogramSession_RealFile(t *testing.T) {
  10. path := `D:\spider\tgs\13252753163\13252753163.session`
  11. if _, err := os.Stat(path); err != nil {
  12. t.Skipf("real session file absent: %v", err)
  13. }
  14. data, err := ConvertPyrogramSession(path)
  15. if err != nil {
  16. t.Fatalf("convert failed: %v", err)
  17. }
  18. if data.DC < 1 || data.DC > 5 {
  19. t.Errorf("unexpected dc: %d", data.DC)
  20. }
  21. if len(data.AuthKey) != 256 {
  22. t.Errorf("auth_key length = %d, want 256", len(data.AuthKey))
  23. }
  24. if len(data.AuthKeyID) != 8 {
  25. t.Errorf("auth_key_id length = %d, want 8", len(data.AuthKeyID))
  26. }
  27. if data.Addr == "" {
  28. t.Error("addr empty")
  29. }
  30. }
  31. func TestConvertPyrogramSession_MissingFile(t *testing.T) {
  32. missing := filepath.Join(t.TempDir(), "does-not-exist.session")
  33. if _, err := ConvertPyrogramSession(missing); err == nil {
  34. t.Error("expected error for missing file")
  35. }
  36. }