Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing #72

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix mock websites related code for integration tests
muly committed Jan 14, 2024
commit a0efc7f356343c26e3faced979ae28970562334b
8 changes: 6 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
@@ -189,8 +189,12 @@ func productHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

pr, err := callScraping(t.URL)
if err != nil {
log.Println("error in processing url", err)
w.WriteHeader(http.StatusInternalServerError)
if errors.Is(err, websiteNotSupported) {
w.WriteHeader(http.StatusNotAcceptable)
} else {
w.WriteHeader(http.StatusBadRequest)
}
w.Write([]byte(fmt.Sprintf("callScraping error in product handler: %v", err)))
return
}

2 changes: 2 additions & 0 deletions scraping.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,8 @@ func integrationTestingMock(rawURL string) (scrape.Product, error) {
return scrape.GetScraper("www.flipkart.com")(rawURL)
case "/mock/flipkart_unavailable.html":
return scrape.GetScraper("www.flipkart.com")(rawURL)
case "/mock/unsupported_file.html":
return scrape.Product{}, websiteNotSupported
default:
log.Printf("%s is not supported\n", u.Path)
return scrape.Product{}, errors.New("unsupported URL path")
10 changes: 6 additions & 4 deletions util_test.go
Original file line number Diff line number Diff line change
@@ -72,10 +72,12 @@ func Test_readSupportedWebsites(t *testing.T) {
{
name: "happy case",
want: map[string]bool{
"scrapeme.live": true,
"www.flipkart.com": true,
"www.amazon.in": true,
"mkp.gem.gov.in": true,
"scrapeme.live": true,
"www.flipkart.com": true,
"www.amazon.in": true,
"mkp.gem.gov.in": true,
"localhost": true,
"smuly-test-ground.ue.r.appspot.com": true,
},
wantErr: false,
},
2 changes: 1 addition & 1 deletion webscraping_test.go
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ func (s *scenarioData) iSendRequestToWithAboveProductUrlInBody(method, endpoint
EmailId string `json:"emailid"`
}{
ProductUrl: s.ProductUrl,
EmailId: s.EmailId,
EmailId: "some_email_id",
}
result, err := json.MarshalIndent(reqfileds, "", " ")
if err != nil {