|
| 1 | +package extensions |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | +) |
| 9 | + |
| 10 | +// TestWebBotAuthDownloadable verifies that the web-bot-auth package can be downloaded from GitHub |
| 11 | +func TestWebBotAuthDownloadable(t *testing.T) { |
| 12 | + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) |
| 13 | + defer cancel() |
| 14 | + |
| 15 | + client := &http.Client{ |
| 16 | + Timeout: 30 * time.Second, |
| 17 | + } |
| 18 | + |
| 19 | + req, err := http.NewRequestWithContext(ctx, http.MethodGet, webBotAuthDownloadURL, nil) |
| 20 | + if err != nil { |
| 21 | + t.Fatalf("Failed to create request: %v", err) |
| 22 | + } |
| 23 | + |
| 24 | + resp, err := client.Do(req) |
| 25 | + if err != nil { |
| 26 | + t.Fatalf("Failed to download web-bot-auth: %v", err) |
| 27 | + } |
| 28 | + defer resp.Body.Close() |
| 29 | + |
| 30 | + if resp.StatusCode != http.StatusOK { |
| 31 | + t.Fatalf("Expected status 200, got %d", resp.StatusCode) |
| 32 | + } |
| 33 | + |
| 34 | + // Verify Content-Type indicates a zip file |
| 35 | + contentType := resp.Header.Get("Content-Type") |
| 36 | + if contentType != "application/zip" && contentType != "application/x-zip-compressed" { |
| 37 | + t.Logf("Warning: unexpected Content-Type: %s (expected application/zip)", contentType) |
| 38 | + } |
| 39 | + |
| 40 | + // Verify Content-Length is reasonable (should be at least 1KB) |
| 41 | + contentLength := resp.ContentLength |
| 42 | + if contentLength > 0 && contentLength < 1024 { |
| 43 | + t.Fatalf("Content-Length too small: %d bytes (expected at least 1KB)", contentLength) |
| 44 | + } |
| 45 | + |
| 46 | + t.Logf("Successfully verified web-bot-auth is downloadable") |
| 47 | + t.Logf("Content-Type: %s", contentType) |
| 48 | + t.Logf("Content-Length: %d bytes", contentLength) |
| 49 | +} |
| 50 | + |
| 51 | +// TestDownloadAndExtractWebBotAuth tests the full download and extraction process |
| 52 | +func TestDownloadAndExtractWebBotAuth(t *testing.T) { |
| 53 | + if testing.Short() { |
| 54 | + t.Skip("Skipping download test in short mode") |
| 55 | + } |
| 56 | + |
| 57 | + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) |
| 58 | + defer cancel() |
| 59 | + |
| 60 | + browserExtDir, cleanup, err := downloadAndExtractWebBotAuth(ctx) |
| 61 | + defer cleanup() |
| 62 | + |
| 63 | + if err != nil { |
| 64 | + t.Fatalf("Failed to download and extract web-bot-auth: %v", err) |
| 65 | + } |
| 66 | + |
| 67 | + if browserExtDir == "" { |
| 68 | + t.Fatal("Expected non-empty browser extension directory path") |
| 69 | + } |
| 70 | + |
| 71 | + t.Logf("Successfully downloaded and extracted to: %s", browserExtDir) |
| 72 | +} |
0 commit comments