client_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package webmail
  2. import (
  3. "reflect"
  4. "testing"
  5. "time"
  6. )
  7. var (
  8. cli = NewClient("http://api.izene.org/winmail/mailalias.php", 60*time.Second)
  9. )
  10. func Test_client_CreateAlias(t *testing.T) {
  11. tests := []struct {
  12. alias string
  13. wantErr bool
  14. }{
  15. {
  16. alias: "gl0001",
  17. wantErr: false,
  18. },
  19. }
  20. for _, tt := range tests {
  21. t.Run("CreateAlias", func(t *testing.T) {
  22. if err := cli.CreateAlias(tt.alias); (err != nil) != tt.wantErr {
  23. t.Errorf("CreateAlias() error = %v, wantErr %v", err, tt.wantErr)
  24. }
  25. })
  26. }
  27. }
  28. func Test_client_ListAliases(t *testing.T) {
  29. tests := []struct {
  30. want []string
  31. wantErr bool
  32. }{
  33. {
  34. want: []string{
  35. "bf111", "bf123", "bfbfbf", "support002", "support003", "support004", "test", "test1",
  36. },
  37. wantErr: false,
  38. },
  39. }
  40. for _, tt := range tests {
  41. t.Run("ListAliases", func(t *testing.T) {
  42. got, err := cli.ListAliases()
  43. if (err != nil) != tt.wantErr {
  44. t.Errorf("ListAliases() error = %v, wantErr %v", err, tt.wantErr)
  45. return
  46. }
  47. if !reflect.DeepEqual(got, tt.want) {
  48. t.Errorf("ListAliases() got = %v, want %v", got, tt.want)
  49. }
  50. })
  51. }
  52. }
  53. func Test_client_RemoveAlias(t *testing.T) {
  54. tests := []struct {
  55. alias string
  56. wantErr bool
  57. }{
  58. {
  59. alias: "gl0001",
  60. wantErr: false,
  61. },
  62. }
  63. for _, tt := range tests {
  64. t.Run("RemoveAlias", func(t *testing.T) {
  65. if err := cli.RemoveAlias(tt.alias); (err != nil) != tt.wantErr {
  66. t.Errorf("RemoveAlias() error = %v, wantErr %v", err, tt.wantErr)
  67. }
  68. })
  69. }
  70. }