Skip to content

Commit

Permalink
Small refactoring, replacing recivers from value to pointer where it …
Browse files Browse the repository at this point in the history
…make sense
  • Loading branch information
artemnikitin committed Apr 2, 2016
1 parent 2cd4b79 commit b747334
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
runJob(getAWSClient(), getConfig())
}

func runJob(client *devicefarm.DeviceFarm, config config.RunConfig) {
func runJob(client *devicefarm.DeviceFarm, config *config.RunConfig) {
projectArn := service.GetProjectArn(client, *project)
deviceArn := service.GetDevicePoolArn(client, projectArn, *devicePool)
appArn, url := service.CreateUpload(client, projectArn, *appPath)
Expand All @@ -52,14 +52,14 @@ func runJob(client *devicefarm.DeviceFarm, config config.RunConfig) {
}
}

func getConfig() config.RunConfig {
func getConfig() *config.RunConfig {
configFile := &config.RunConfig{}
if *configJSON != "" {
bytes, err := ioutil.ReadFile(*configJSON)
errors.Validate(err, "Can't read config file")
*configFile = config.Transform(bytes)
}
return *configFile
return configFile
}

func getAWSClient() *devicefarm.DeviceFarm {
Expand Down
6 changes: 3 additions & 3 deletions service/config_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/aws/aws-sdk-go/service/devicefarm"
)

func createScheduleRunInput(client *devicefarm.DeviceFarm, conf config.RunConfig, projectArn string) *devicefarm.ScheduleRunInput {
func createScheduleRunInput(client *devicefarm.DeviceFarm, conf *config.RunConfig, projectArn string) *devicefarm.ScheduleRunInput {
var wg sync.WaitGroup
result := &devicefarm.ScheduleRunInput{
ProjectArn: aws.String(projectArn),
Expand Down Expand Up @@ -70,7 +70,7 @@ func createScheduleRunInput(client *devicefarm.DeviceFarm, conf config.RunConfig
return result
}

func processTestBlock(conf config.RunConfig, sri *devicefarm.ScheduleRunInput) {
func processTestBlock(conf *config.RunConfig, sri *devicefarm.ScheduleRunInput) {
if conf.Test.Type != "" {
sri.Test.Type = aws.String(conf.Test.Type)
}
Expand All @@ -90,7 +90,7 @@ func processTestBlock(conf config.RunConfig, sri *devicefarm.ScheduleRunInput) {
}
}

func processConfigurationBlock(conf config.RunConfig, sri *devicefarm.ScheduleRunInput) {
func processConfigurationBlock(conf *config.RunConfig, sri *devicefarm.ScheduleRunInput) {
if conf.AdditionalData.BillingMethod != "" {
sri.Configuration.BillingMethod = aws.String(conf.AdditionalData.BillingMethod)
}
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetDevicePoolArn(client *devicefarm.DeviceFarm, projectArn, devicePool stri
}

// RunWithConfig will schedule run with setup from JSON config
func RunWithConfig(client *devicefarm.DeviceFarm, devicePoolArn, projectArn, appArn string, conf config.RunConfig) (string, string) {
func RunWithConfig(client *devicefarm.DeviceFarm, devicePoolArn, projectArn, appArn string, conf *config.RunConfig) (string, string) {
params := createScheduleRunInput(client, conf, projectArn)
params.DevicePoolArn = aws.String(devicePoolArn)
params.AppArn = aws.String(appArn)
Expand Down
2 changes: 1 addition & 1 deletion tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func UploadFile(path, url string) int {
log.Println("Uploading file from path:", path)
file, info := prepareFile(path)
resp := sendRequest(url, file, info)
resp := sendRequest(url, &file, info)
return getStatusOfUpload(resp)
}

Expand Down
6 changes: 3 additions & 3 deletions tools/upload_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/artemnikitin/devicefarm-ci-tool/errors"
)

func sendRequest(url string, file *os.File, info os.FileInfo) *http.Response {
func sendRequest(url string, file *io.Reader, info os.FileInfo) *http.Response {
client := &http.Client{}
request, err := http.NewRequest("PUT", url, file)
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()
Expand All @@ -21,7 +21,7 @@ func sendRequest(url string, file *os.File, info os.FileInfo) *http.Response {
return resp
}

func prepareFile(path string) (*os.File, os.FileInfo) {
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()
Expand Down

0 comments on commit b747334

Please sign in to comment.