Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

local_test.go 1018B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package files_test
  2. import (
  3. "context"
  4. "io"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. "github.com/9seconds/mtg/v2/ipblocklist/files"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/suite"
  11. )
  12. type LocalTestSuite struct {
  13. suite.Suite
  14. }
  15. func (suite *LocalTestSuite) getLocalFile(name string) string {
  16. return filepath.Join("testdata", name)
  17. }
  18. func (suite *LocalTestSuite) TestIncorrect() {
  19. names := []string{
  20. "absent",
  21. "directory",
  22. }
  23. for _, v := range names {
  24. value := v
  25. suite.T().Run(v, func(t *testing.T) {
  26. _, err := files.NewLocal(suite.getLocalFile(value))
  27. assert.Error(t, err)
  28. })
  29. }
  30. }
  31. func (suite *LocalTestSuite) TestOk() {
  32. file, err := files.NewLocal(suite.getLocalFile("readable"))
  33. suite.NoError(err)
  34. reader, err := file.Open(context.Background())
  35. suite.NoError(err)
  36. data, err := io.ReadAll(reader)
  37. suite.NoError(err)
  38. suite.Equal("Hooray!", strings.TrimSpace(string(data)))
  39. }
  40. func TestLocal(t *testing.T) {
  41. t.Parallel()
  42. suite.Run(t, &LocalTestSuite{})
  43. }