Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 12 additions & 5 deletions xcodebuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ func (c *CommandBuilder) SetTestPlan(testPlan string) *CommandBuilder {

func (c *CommandBuilder) cmdSlice() []string {
slice := []string{toolName}
slice = append(slice, c.actions...)
slice = append(slice, c.CommandArgs()...)

return slice
}

// CommandArgs returns the xcodebuild command arguments, including actions and options
func (c *CommandBuilder) CommandArgs() []string {
slice := append([]string{}, c.actions...)

if c.projectPath != "" {
if filepath.Ext(c.projectPath) == XCWorkspaceExtension {
Expand Down Expand Up @@ -190,25 +197,25 @@ func (c *CommandBuilder) cmdSlice() []string {
}

// PrintableCmd ...
func (c CommandBuilder) PrintableCmd() string {
func (c *CommandBuilder) PrintableCmd() string {
cmdSlice := c.cmdSlice()
return command.PrintableCommandArgs(false, cmdSlice)
}

// Command ...
func (c CommandBuilder) Command() *command.Model {
func (c *CommandBuilder) Command() *command.Model {
cmdSlice := c.cmdSlice()
return command.New(cmdSlice[0], cmdSlice[1:]...)
}

// ExecCommand ...
func (c CommandBuilder) ExecCommand() *exec.Cmd {
func (c *CommandBuilder) ExecCommand() *exec.Cmd {
command := c.Command()
return command.GetCmd()
}

// Run ...
func (c CommandBuilder) Run() error {
func (c *CommandBuilder) Run() error {
command := c.Command()

command.SetStdout(os.Stdout)
Expand Down
11 changes: 6 additions & 5 deletions xcodebuild/build_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xcodebuild

import (
"reflect"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestCommandBuilder_cmdSlice(t *testing.T) {
Expand Down Expand Up @@ -187,9 +187,10 @@ func TestCommandBuilder_cmdSlice(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.builder().cmdSlice()
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("CommandBuilder.cmdSlice() = %v\nwant %v", strings.Join(got, "\n"), strings.Join(tt.want, "\n"))
}
require.Equal(t, tt.want, got)

got2 := tt.builder().cmdSlice()
require.Equal(t, tt.want, got2, "Second run should return the same result")
})
}
}
22 changes: 15 additions & 7 deletions xcodebuild/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ func (c *ExportCommandModel) SetAuthentication(authenticationParams Authenticati
return c
}

func (c ExportCommandModel) cmdSlice() []string {
slice := []string{toolName, "-exportArchive"}
func (c *ExportCommandModel) cmdSlice() []string {
slice := []string{toolName}
slice = append(slice, c.CommandArgs()...)

return slice
}

// CommandArgs returns the xcodebuild command arguments for the export action
func (c *ExportCommandModel) CommandArgs() []string {
slice := []string{"-exportArchive"}
if c.archivePath != "" {
slice = append(slice, "-archivePath", c.archivePath)
}
Expand All @@ -75,25 +83,25 @@ func (c ExportCommandModel) cmdSlice() []string {
}

// PrintableCmd ...
func (c ExportCommandModel) PrintableCmd() string {
func (c *ExportCommandModel) PrintableCmd() string {
cmdSlice := c.cmdSlice()
return command.PrintableCommandArgs(false, cmdSlice)
}

// Command ...
func (c ExportCommandModel) Command() *command.Model {
func (c *ExportCommandModel) Command() *command.Model {
cmdSlice := c.cmdSlice()
return command.New(cmdSlice[0], cmdSlice[1:]...)
}

// Cmd ...
func (c ExportCommandModel) Cmd() *exec.Cmd {
func (c *ExportCommandModel) Cmd() *exec.Cmd {
command := c.Command()
return command.GetCmd()
}

// Run ...
func (c ExportCommandModel) Run() error {
func (c *ExportCommandModel) Run() error {
command := c.Command()

command.SetStdout(os.Stdout)
Expand All @@ -103,7 +111,7 @@ func (c ExportCommandModel) Run() error {
}

// RunAndReturnOutput ...
func (c ExportCommandModel) RunAndReturnOutput() (string, error) {
func (c *ExportCommandModel) RunAndReturnOutput() (string, error) {
command := c.Command()

var outBuffer bytes.Buffer
Expand Down
65 changes: 65 additions & 0 deletions xcodebuild/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package xcodebuild

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestExportCommandModel_cmdSlice(t *testing.T) {
tests := []struct {
name string
archivePath string
exportDir string
exportOptionsPlist string
authentication *AuthenticationParams
want []string
}{
{
name: "basic export",
archivePath: "sample.xcarchive",
exportDir: "/var/exported",
exportOptionsPlist: "/var/export_options.plist",
want: []string{"xcodebuild",
"-exportArchive",
"-archivePath", "sample.xcarchive",
"-exportPath", "/var/exported",
"-exportOptionsPlist", "/var/export_options.plist",
},
},
{
name: "export with authentication",
archivePath: "sample.xcarchive",
authentication: &AuthenticationParams{
KeyID: "keyID",
IsssuerID: "issuerID",
KeyPath: "/key/path",
},
want: []string{"xcodebuild",
"-exportArchive",
"-archivePath", "sample.xcarchive",
"-allowProvisioningUpdates",
"-authenticationKeyPath", "/key/path",
"-authenticationKeyID", "keyID",
"-authenticationKeyIssuerID", "issuerID",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := NewExportCommand()
c.SetArchivePath(tt.archivePath)
c.SetExportDir(tt.exportDir)
c.SetExportOptionsPlist(tt.exportOptionsPlist)
if tt.authentication != nil {
c.SetAuthentication(*tt.authentication)
}

got := c.cmdSlice()
require.Equal(t, tt.want, got)

got2 := c.cmdSlice()
require.Equal(t, tt.want, got2, "Second run should return the same result")
})
}
}