Skip to content

Commit

Permalink
improvements based on Manith's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkisielewski-arista committed Feb 24, 2025
1 parent cc3ba16 commit c8221bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions executor/dryrun_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type DryRunExecutor struct {
// extra abstractions feel unnecessary.

// human friendly description of what an invocation would do
Invocations []string
invocations []string

// a script that would be equivalent to the invocations requested
shellScript []string
Expand All @@ -25,7 +25,7 @@ func (ex *DryRunExecutor) Exec(name string, arg ...string) error {
escapedInvocation := shellEscape(append([]string{name}, arg...))
message := fmt.Sprintf("Would execute: %s", escapedInvocation)
fmt.Println(message)
ex.Invocations = append(ex.Invocations, message)
ex.invocations = append(ex.invocations, message)
ex.shellScript = append(ex.shellScript, escapedInvocation)
return nil
}
Expand All @@ -35,7 +35,7 @@ func (ex *DryRunExecutor) ExecInDir(dir string, name string, arg ...string) erro
message := fmt.Sprintf(
"In the directory '%s', would execute: %s", dir, escapedInvocation)

ex.Invocations = append(ex.Invocations, message)
ex.invocations = append(ex.invocations, message)

// empty `dir` means run in the same directory, but if we just simply
// interpolate arg for `cd` with an empty string, the result will change the
Expand All @@ -59,5 +59,5 @@ func (ex *DryRunExecutor) GenerateShellScript() string {
}

func (ex *DryRunExecutor) GenerateDescription() string {
return strings.Join(ex.Invocations, "\n")
return strings.Join(ex.invocations, "\n")
}
12 changes: 6 additions & 6 deletions executor/mocked_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type MockedExecutor struct {
Responses []Response

// records of what has been called on the executor
Calls []RecordedCall
RecordedCalls []RecordedCall
}

// RecordedCall stores information about what call was made
Expand Down Expand Up @@ -42,22 +42,22 @@ func NewResponse(code int, out string, err error) Response {
// Mocked Exec that instead of running the command, it stores the information
// about the call, and returns predefined return code and an error object.
func (ex *MockedExecutor) Exec(name string, arg ...string) error {
ex.Calls = append(ex.Calls, RecordedCall{"", name, arg})
ex.RecordedCalls = append(ex.RecordedCalls, RecordedCall{"", name, arg})
return ex.popResponse().Err
}

// Mocked ExecInDir that instead of running the command, it stores the information
// about the call, and returns predefined return code and an error object.
func (ex *MockedExecutor) ExecInDir(dir string, name string, arg ...string) error {
ex.Calls = append(ex.Calls, RecordedCall{dir, name, arg})
ex.RecordedCalls = append(ex.RecordedCalls, RecordedCall{dir, name, arg})
return ex.popResponse().Err
}

// Mocked Output that instead of running the command, it stores the information
// about the call, and returns predefined return code, the mocked Output that
// the command would have printed on the standard output, and an error object.
func (ex *MockedExecutor) Output(name string, arg ...string) (string, error) {
ex.Calls = append(ex.Calls, RecordedCall{"", name, arg})
ex.RecordedCalls = append(ex.RecordedCalls, RecordedCall{"", name, arg})
response := ex.popResponse()
return response.Output, response.Err
}
Expand All @@ -75,7 +75,7 @@ func (ex *MockedExecutor) popResponse() Response {

// Check if a call with exact params was made
func (ex *MockedExecutor) HasCall(call RecordedCall) bool {
for _, recordedCall := range ex.Calls {
for _, recordedCall := range ex.RecordedCalls {
if reflect.DeepEqual(call, recordedCall) {
return true
}
Expand All @@ -86,5 +86,5 @@ func (ex *MockedExecutor) HasCall(call RecordedCall) bool {
// Check whether the calls made with the executor match exactly (and are in
// the same order)
func (ex *MockedExecutor) HasExactCalls(calls []RecordedCall) bool {
return reflect.DeepEqual(calls, ex.Calls)
return reflect.DeepEqual(calls, ex.RecordedCalls)
}
6 changes: 3 additions & 3 deletions impl/create_srpm_from_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestGitArchive(t *testing.T) {
expectedCall := executor.NewRecordedCall("/tmp/fake-cloned-dir", "git",
[]string{"archive", "--prefix", "libpcap-1.10.1/", "-o", "/tmp/fake-working-dir/Source0.tar.gz", "libpcap-1.10.1"})
//expected := "In the directory '/tmp/fake-cloned-dir', would execute: git archive --prefix libpcap-1.10.1/ -o /tmp/fake-working-dir/Source0.tar.gz libpcap-1.10.1"
actual := mex.Calls[0]
actual := mex.RecordedCalls[0]
if !mex.HasCall(expectedCall) {
t.Fatalf("generateArchiveFile executed an unexpected command.\nExpected:\n%s\nActual:\n%s", expectedCall, actual)
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestVerifyGitSignatureRevIsTagPassing(t *testing.T) {
executor.NewRecordedCall(spec.ClonedDir, "git", []string{"verify-tag", "-v", spec.Revision}),
}
if !mex.HasExactCalls(expectedCalls) {
t.Fatalf("verifyGitSignature executed wrong commands.\nExpected:\n%v\nActual:\n%v", expectedCalls, mex.Calls)
t.Fatalf("verifyGitSignature executed wrong commands.\nExpected:\n%v\nActual:\n%v", expectedCalls, mex.RecordedCalls)
}
}

Expand Down Expand Up @@ -115,6 +115,6 @@ func TestVerifyGitSignatureRevIsCommitPassing(t *testing.T) {
executor.NewRecordedCall(spec.ClonedDir, "git", []string{"verify-commit", "-v", spec.Revision}),
}
if !mex.HasExactCalls(expectedCalls) {
t.Fatalf("verifyGitSignature executed wrong commands.\nExpected:\n%v\nActual:\n%v", expectedCalls, mex.Calls)
t.Fatalf("verifyGitSignature executed wrong commands.\nExpected:\n%v\nActual:\n%v", expectedCalls, mex.RecordedCalls)
}
}

0 comments on commit c8221bb

Please sign in to comment.