| /* |
| Copyright 2019 Google Inc. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| https://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| package main |
| |
| import ( |
| "context" |
| "flag" |
| "log" |
| |
| fpb "github.com/maps-booking-v3/feeds" |
| |
| "github.com/maps-booking-v3/api" |
| "github.com/maps-booking-v3/order" |
| "github.com/maps-booking-v3/utils" |
| ) |
| |
| var ( |
| serverAddr = flag.String("server_addr", "example.com:80", "Your http server's address in the format of host:port") |
| credentialsFile = flag.String("credentials_file", "", "File containing credentials for your server. Leave blank to bypass authentication. File should have exactly one line of the form 'username:password'.") |
| testSlots = flag.Int("num_test_slots", 10, "Maximum number of slots to test from availability_feed. Slots will be selected randomly") |
| allFlows = flag.Bool("all_tests", false, "Whether to test all endpoints syncronously, including ListOrders flow.") |
| healthFlow = flag.Bool("health_check_test", false, "Whether to test the Health endpoint.") |
| checkFlow = flag.Bool("check_order_test", false, "Whether to test the CheckOrderFulfillability endpoint.") |
| orderFlow = flag.Bool("create_order_test", false, "Whether to test the CreateOrder endpoint.") |
| serviceFeed = flag.String("service_feed", "", "Absolute path to service feed required for all tests except health. Feeds can be in either json or pb3 format") |
| availabilityFeed = flag.String("availability_feed", "", "Absolute path to availability feed required for all tests except health. Feeds can be in either json or pb3 format") |
| outputDir = flag.String("output_dir", "", "Absolute path of dir to dump log file.") |
| caFile = flag.String("ca_file", "", "Absolute path to your server's Certificate Authority root cert. Downloading all roots currently recommended by the Google Internet Authority is a suitable alternative https://pki.google.com/roots.pem. Leave blank to connect using http rather than https.") |
| fullServerName = flag.String("full_server_name", "", "Fully qualified domain name. Same name used to sign CN. Only necessary if ca_file is specified and the base URL differs from the server address.") |
| outputToTerminal = flag.Bool("output_to_terminal", false, "Output to terminal rather than a file.") |
| ) |
| |
| func makeConfig(logger *log.Logger) *utils.Config { |
| conn, err := api.InitHTTPConnection(*serverAddr, *credentialsFile, *caFile, *fullServerName) |
| if err != nil { |
| logger.Fatalf("Failed to init http connection %v", err) |
| } |
| return &utils.Config{Conn: conn, |
| OrderAllFlows: *allFlows, |
| OrderHealthFlow: *healthFlow, |
| OrderCheckFlow: *checkFlow, |
| OrderOrderFlow: *orderFlow, |
| } |
| } |
| |
| func main() { |
| flag.Parse() |
| |
| logger, f, err := utils.MakeLogger(*outputToTerminal, *outputDir) |
| if err != nil { |
| log.Fatal("Could not create logger: ", err) |
| } |
| if f != nil { |
| defer f.Close() |
| } |
| |
| config := makeConfig(logger) |
| var summary utils.TestSummary |
| var services []*fpb.Service |
| var av []*fpb.Availability |
| if config.OrderAllFlows || config.OrderCheckFlow || config.OrderOrderFlow { |
| if *availabilityFeed == "" || *serviceFeed == "" { |
| log.Fatal("please set both availability_feed and service_feed flags") |
| } |
| |
| services, err = utils.ParseServiceFeed(*serviceFeed) |
| if err != nil { |
| log.Fatal(err.Error()) |
| } |
| |
| av, err = utils.AvailabilityFrom(logger, *availabilityFeed, *testSlots, false) |
| if err != nil { |
| log.Fatal(err.Error()) |
| } |
| } |
| order.RunTests(context.Background(), logger, config, av, services, &summary) |
| } |