| 1 | package e2e_test |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "os" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | "time" |
| 9 | |
| 10 | "github.com/onsi/ginkgo/v2" |
| 11 | "github.com/onsi/gomega" |
| 12 | ) |
| 13 | |
| 14 | //nolint:paralleltest // Avoid using parallel test when making external calls |
| 15 | func Test_Discord_E2E(t *testing.T) { |
| 16 | // Load .env file if it exists |
| 17 | loadEnvFile(".env") |
| 18 | |
| 19 | gomega.RegisterFailHandler(ginkgo.Fail) |
| 20 | |
| 21 | // Add delay between tests to respect rate limits |
| 22 | ginkgo.BeforeEach(func() { |
| 23 | // Add a small delay between tests to avoid hitting Discord rate limits |
| 24 | time.Sleep(100 * time.Millisecond) |
| 25 | }) |
| 26 | |
| 27 | ginkgo.RunSpecs(t, "Discord E2E Tests") |
| 28 | } |
| 29 | |
| 30 | // loadEnvFile loads environment variables from a .env file. |
| 31 | func loadEnvFile(filename string) { |
| 32 | file, err := os.Open(filename) |
| 33 | if err != nil { |
| 34 | // .env file doesn't exist, skip loading |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | defer func() { _ = file.Close() }() |
| 39 | |
| 40 | scanner := bufio.NewScanner(file) |
| 41 | for scanner.Scan() { |
| 42 | line := strings.TrimSpace(scanner.Text()) |
| 43 | if line == "" || strings.HasPrefix(line, "#") { |
| 44 | continue |
| 45 | } |
| 46 | |
| 47 | parts := strings.SplitN(line, "=", 2) |
| 48 | if len(parts) == 2 { |
| 49 | key := strings.TrimSpace(parts[0]) |
| 50 | value := strings.TrimSpace(parts[1]) |
| 51 | // Remove quotes if present |
| 52 | value = strings.Trim(value, `"'`) |
| 53 | _ = os.Setenv(key, value) // Ignore error as it's test setup |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if err := scanner.Err(); err != nil { |
| 58 | return |
| 59 | } |
| 60 | } |