(t *testing.T)
| 514 | } |
| 515 | |
| 516 | func TestHTTPGetterTarDownload(t *testing.T) { |
| 517 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 518 | f, _ := os.Open("testdata/empty-0.0.1.tgz") |
| 519 | defer f.Close() |
| 520 | |
| 521 | b := make([]byte, 512) |
| 522 | f.Read(b) |
| 523 | // Get the file size |
| 524 | FileStat, _ := f.Stat() |
| 525 | FileSize := strconv.FormatInt(FileStat.Size(), 10) |
| 526 | |
| 527 | // Simulating improper header values from bitbucket |
| 528 | w.Header().Set("Content-Type", "application/x-tar") |
| 529 | w.Header().Set("Content-Encoding", "gzip") |
| 530 | w.Header().Set("Content-Length", FileSize) |
| 531 | |
| 532 | f.Seek(0, 0) |
| 533 | io.Copy(w, f) |
| 534 | })) |
| 535 | |
| 536 | defer srv.Close() |
| 537 | |
| 538 | g, err := NewHTTPGetter(WithURL(srv.URL)) |
| 539 | if err != nil { |
| 540 | t.Fatal(err) |
| 541 | } |
| 542 | |
| 543 | data, _ := g.Get(srv.URL) |
| 544 | mimeType := http.DetectContentType(data.Bytes()) |
| 545 | |
| 546 | expectedMimeType := "application/x-gzip" |
| 547 | if mimeType != expectedMimeType { |
| 548 | t.Fatalf("Expected response with MIME type %s, but got %s", expectedMimeType, mimeType) |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | func TestHttpClientInsecureSkipVerify(t *testing.T) { |
| 553 | g := HTTPGetter{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…