func prepareFile(path string) (io.Reader, os.FileInfo) { file, err := os.Open(path) errors.Validate(err, "Failed to get file for upload") info, err := file.Stat() errors.Validate(err, "Failed to get info about file") return file, info }
func sendRequest(url string, file *io.Reader, info os.FileInfo) *http.Response { client := &http.Client{} request, err := http.NewRequest("PUT", url, *file) errors.Validate(err, "Failed to create HTTP request") request.Header.Add("Content-Type", "application/octet-stream") request.ContentLength = info.Size() resp, err := client.Do(request) errors.Validate(err, "Failed to upload file by S3 link") return resp }
// GetStatusOfRun returns status and result of run specified by ARN func GetStatusOfRun(client *devicefarm.DeviceFarm, arn string) (string, string) { params := &devicefarm.GetRunInput{ Arn: aws.String(arn), } resp, err := client.GetRun(params) errors.Validate(err, "Can't get status of run") return *resp.Run.Status, *resp.Run.Result }
func getConfig() *model.RunConfig { configFile := &model.RunConfig{} if *configJSON != "" { bytes, err := ioutil.ReadFile(*configJSON) errors.Validate(err, "Can't read model file") *configFile = model.Transform(bytes) } return configFile }
// GetUploadStatus returns status of upload file func GetUploadStatus(client *devicefarm.DeviceFarm, arn string) string { params := &devicefarm.GetUploadInput{ Arn: aws.String(arn), } resp, err := client.GetUpload(params) errors.Validate(err, "Failed to get status of upload") log.Println("Status of upload:", *resp.Upload.Status) return *resp.Upload.Status }
// RunWithConfig will schedule run with setup from JSON model func RunWithConfig(p *model.RunParameters) (string, string) { params := createScheduleRunInput(p) params.DevicePoolArn = aws.String(p.DeviceArn) params.AppArn = aws.String(p.AppArn) log.Println("Starting job ...") resp, err := p.Client.ScheduleRun(params) errors.Validate(err, "Failed to run tests") log.Println("Run ARN:", *resp.Run.Arn) return *resp.Run.Arn, *resp.Run.Status }
func internalCreateUpload(client *devicefarm.DeviceFarm, arn, appPath, appType string) (string, string) { params := &devicefarm.CreateUploadInput{ Name: aws.String(tools.GetFileName(appPath)), ProjectArn: aws.String(arn), Type: aws.String(appType), ContentType: aws.String("application/octet-stream"), } resp, err := client.CreateUpload(params) errors.Validate(err, "Failed to upload an app") log.Println("Upload ARN:", *resp.Upload.Arn) log.Println("Upload URL:", *resp.Upload.Url) return *resp.Upload.Arn, *resp.Upload.Url }
// GetProjectArn returns project ARN by project name func GetProjectArn(client *devicefarm.DeviceFarm, project string) string { var arn string params := &devicefarm.ListProjectsInput{} resp, err := client.ListProjects(params) errors.Validate(err, "Failed to get list of projects for account") for _, entry := range resp.Projects { if *entry.Name == project { arn = *entry.Arn } } log.Println("Project ARN:", arn) return arn }
func getStatusOfUpload(response *http.Response) int { result := response.StatusCode body, err := ioutil.ReadAll(response.Body) errors.Validate(err, "Failed to get body of response") log.Println("Response code:", result) log.Println("Response body:", string(body)) defer func() { // Drain and close the body to let the Transport reuse the connection io.Copy(ioutil.Discard, response.Body) response.Body.Close() }() return result }
// GetDevicePoolArn returns device pool ARN by device pool name func GetDevicePoolArn(client *devicefarm.DeviceFarm, projectArn, devicePool string) string { var arn string params := &devicefarm.ListDevicePoolsInput{ Arn: aws.String(projectArn), } resp, err := client.ListDevicePools(params) errors.Validate(err, "Failed to get list of device pools") for _, pool := range resp.DevicePools { if *pool.Name == devicePool { arn = *pool.Arn } } log.Println("Device pool ARN:", arn) return arn }
// Transform unmarshall JSON model file to struct func Transform(jsonBytes []byte) RunConfig { result := &RunConfig{} err := json.Unmarshal(jsonBytes, result) errors.Validate(err, "Can't read model file") return *result }