thoth_test.go 663 B

123456789101112131415161718192021222324252627282930313233343536
  1. package thoth_test
  2. import (
  3. "os"
  4. "testing"
  5. "github.com/TecharoHQ/anubis/lib/thoth"
  6. "github.com/TecharoHQ/anubis/lib/thoth/thothmock"
  7. "github.com/joho/godotenv"
  8. )
  9. func loadSecrets(t testing.TB) *thoth.Client {
  10. t.Helper()
  11. if err := godotenv.Load(); err != nil {
  12. t.Log("using mock thoth")
  13. result := &thoth.Client{}
  14. result.WithIPToASNService(thothmock.MockIpToASNService())
  15. return result
  16. }
  17. cli, err := thoth.New(t.Context(), os.Getenv("THOTH_URL"), os.Getenv("THOTH_API_KEY"), false)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. return cli
  22. }
  23. func TestNew(t *testing.T) {
  24. cli := loadSecrets(t)
  25. if err := cli.Close(); err != nil {
  26. t.Fatal(err)
  27. }
  28. }