PageRenderTime 21ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/github.com/mailgun/mailgun-go/acceptance/credentials_test.go

https://gitlab.com/admin-github-cloud/dex
Go | 53 lines | 45 code | 7 blank | 1 comment | 9 complexity | 4d872b58055ed1747d4ecdc4a771e507 MD5 | raw file
  1. // +build acceptance
  2. package acceptance
  3. import (
  4. "fmt"
  5. mailgun "github.com/mailgun/mailgun-go"
  6. "os"
  7. "testing"
  8. "text/tabwriter"
  9. )
  10. func TestGetCredentials(t *testing.T) {
  11. domain := reqEnv(t, "MG_DOMAIN")
  12. apiKey := reqEnv(t, "MG_API_KEY")
  13. mg := mailgun.NewMailgun(domain, apiKey, "")
  14. n, cs, err := mg.GetCredentials(mailgun.DefaultLimit, mailgun.DefaultSkip)
  15. if err != nil {
  16. t.Fatal(err)
  17. }
  18. tw := &tabwriter.Writer{}
  19. tw.Init(os.Stdout, 2, 8, 2, ' ', 0)
  20. fmt.Fprintf(tw, "Login\tCreated At\t\n")
  21. for _, c := range cs {
  22. fmt.Fprintf(tw, "%s\t%s\t\n", c.Login, c.CreatedAt)
  23. }
  24. tw.Flush()
  25. fmt.Printf("%d credentials listed out of %d\n", len(cs), n)
  26. }
  27. func TestCreateDeleteCredentials(t *testing.T) {
  28. domain := reqEnv(t, "MG_DOMAIN")
  29. apiKey := reqEnv(t, "MG_API_KEY")
  30. mg := mailgun.NewMailgun(domain, apiKey, "")
  31. randomPassword := randomString(16, "pw")
  32. randomID := randomString(16, "usr")
  33. randomLogin := fmt.Sprintf("%s@%s", randomID, domain)
  34. err := mg.CreateCredential(randomLogin, randomPassword)
  35. if err != nil {
  36. t.Fatal(err)
  37. }
  38. err = mg.ChangeCredentialPassword(randomID, randomString(16, "pw2"))
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. err = mg.DeleteCredential(randomID)
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. }