Skip to content

Commit

Permalink
Fix thresholds in UTs and use specific version of go protoc (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisukox authored Jan 14, 2024
1 parent e4ed51b commit 762d651
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
- name: Setup protocol buffer compiler
run: |
sudo apt-get install protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
- name: Generate proto
run: go generate ./...
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The Google Flights API doesn't have official documentation, so the project relie

The project uses [go-retryablehttp](https://github.com/hashicorp/go-retryablehttp) under the hood. Every request to the Google Flights API is retried five times in case of an error.

### Go protoc plugin used in the project
```
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.31.0
```

## Installation

```
Expand Down
1 change: 1 addition & 0 deletions examples/example2/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This example gets PriceGraph offers and prints only those whose
// price is cheaper than the low price of the offer
// (the price is considered as low by the Google Flights)
package main

import (
Expand Down
1 change: 1 addition & 0 deletions examples/example3/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This example iterates over PriceGraph offers concurrently and prints only
// those whose price is cheaper than the low price of the offer.
// (The price is considered low by Google Flights)
// This example is the same as Example 2, but it sends requests concurrently.
package main

Expand Down
8 changes: 6 additions & 2 deletions flights/flight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ func compareWithThreshold(lv, rv float64) bool {
}

func testGetOffersTravelers(t *testing.T, session *Session, rootPrice float64, args Args, multiplier float64) {
percentageDiff := 10.0

offers, _, err := session.GetOffers(context.Background(), args)
if err != nil {
t.Fatal(err)
}
if len(offers) < 1 {
t.Fatalf("not enough offers (%d) for the following Travelers: %+v", len(offers), args.Travelers)
}
if !compareWithThreshold(rootPrice*multiplier, offers[0].Price) {
t.Fatalf("The received price should be %d times larger than the root price: %f, %f", int(multiplier), rootPrice, offers[0].Price)
lowerThreshold := rootPrice * multiplier * (100 - percentageDiff) / 100
upperThreshold := rootPrice * multiplier * (100 + percentageDiff) / 100
if offers[0].Price < lowerThreshold || offers[0].Price > upperThreshold {
t.Errorf("The received price %f: should be between threshold: %f %f", offers[0].Price, lowerThreshold, upperThreshold)
}
}

Expand Down
8 changes: 6 additions & 2 deletions flights/price_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ func TestGetPriceGraph(t *testing.T) {
}

func testGetPriceGraphTravelers(t *testing.T, session *Session, rootPrice float64, args PriceGraphArgs, multiplier float64) {
percentageDiff := 10.0

offers, err := session.GetPriceGraph(context.Background(), args)
if err != nil {
t.Fatal(err)
}
if len(offers) < 1 {
t.Fatalf("not enough offers (%d) for the following Travelers: %+v", len(offers), args.Travelers)
}
if !compareWithThreshold(rootPrice*multiplier, offers[0].Price) {
t.Fatalf("The received price should be %d times larger than the root price: %f, %f", int(multiplier), rootPrice, offers[0].Price)
lowerThreshold := rootPrice * multiplier * (100 - percentageDiff) / 100
upperThreshold := rootPrice * multiplier * (100 + percentageDiff) / 100
if offers[0].Price < lowerThreshold || offers[0].Price > upperThreshold {
t.Errorf("The received price %f: should be between threshold: %f %f", offers[0].Price, lowerThreshold, upperThreshold)
}
}

Expand Down

0 comments on commit 762d651

Please sign in to comment.