Skip to content

Commit

Permalink
Merge pull request #25 from metrumresearchgroup/fix/cmd_output_details
Browse files Browse the repository at this point in the history
fix: making sure logging is occurring and errors are wrapped and handed back up when failures occur
  • Loading branch information
shairozan authored Jan 4, 2024
2 parents 0d06124 + 6ec3f24 commit f4ccc1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 33 deletions.
17 changes: 1 addition & 16 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@ steps:
- name: Test
image: golang
commands:
- go test ./... -covermode=count -coverprofile=coverage.out
when:
event:
exclude:
- pull_request

- name: Coveralls
image: golang
environment:
COVERALLS_TOKEN:
from_secret: COVERALLS_TOKEN
commands:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
- go mod download
- goveralls -coverprofile=coverage.out -service=drone.io -repotoken $COVERALLS_TOKEN
- go test ./...
when:
event:
exclude:
Expand Down
20 changes: 7 additions & 13 deletions qstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type XmlResourceReader interface {
Read() (string, error)
}

//GetQstatOutput is used to pull in XML content from either the QSTAT command or generated data for testing purpoes
// GetQstatOutput is used to pull in XML content from either the QSTAT command or generated data for testing purpoes
func GetQstatOutput(filters map[string]string) (string, error) {

if os.Getenv(environmentPrefix+"TEST") != "true" {
Expand All @@ -65,7 +65,7 @@ func GetQstatOutput(filters map[string]string) (string, error) {
return generatedQstatOputput()
}

//DeleteQueuedJobByID is used to delete (1 or many) jobs by concatenating their IDs together and passing them to qdel
// DeleteQueuedJobByID is used to delete (1 or many) jobs by concatenating their IDs together and passing them to qdel
func DeleteQueuedJobByID(targets []string) (string, error) {

//If this is in test mode, just return empty error and exit quickly
Expand Down Expand Up @@ -109,7 +109,7 @@ func DeleteQueuedJobByID(targets []string) (string, error) {
return output.String(), nil
}

//DeleteQueuedJobByUsernames is used to delete (1 or many) jobs by concatenating usernames together and feeding them to qdel
// DeleteQueuedJobByUsernames is used to delete (1 or many) jobs by concatenating usernames together and feeding them to qdel
func DeleteQueuedJobByUsernames(targets []string) (string, error) {

//If this is in test mode, just return empty error and exit quickly
Expand Down Expand Up @@ -156,7 +156,7 @@ func DeleteQueuedJobByUsernames(targets []string) (string, error) {
return output.String(), nil
}

//Filters are meant to be in the form of [key] being being a switch and the value to be the anything passed to the option
// Filters are meant to be in the form of [key] being being a switch and the value to be the anything passed to the option
func qStatFromExec(filters map[string]string) (string, error) {

//Locate the binary in existing path
Expand All @@ -176,16 +176,11 @@ func qStatFromExec(filters map[string]string) (string, error) {

command := exec.CommandContext(ctx, binary, arguments...)
command.Env = os.Environ()
outputBytes, err := command.Output()
outputBytes, err := command.CombinedOutput()

if err != nil {
log.Error("An error occurred during execution of the requested binary: ", err)
return "", err
}

if err != nil {
log.Error("There was an error while attempting to run the ", binary, ": ", err)
return "", err
log.Errorf("An error occurred during execution of the the binary %s. Execution details are %s ", binary, string(outputBytes))
return "", fmt.Errorf("an error occurred during execution of the the binary %s. Execution details are %s. Error: %w", binary, string(outputBytes), err)
}

return string(outputBytes), nil
Expand Down Expand Up @@ -226,7 +221,6 @@ func buildQstatArgumentList(filters map[string]string) []string {
}

func generatedQstatOputput() (string, error) {

xmlLocation := XMLDataSource{location: "https://raw.githubusercontent.com/metrumresearchgroup/gogridengine/master/test_data/medium.xml"}

if os.Getenv("GOGRIDENGINE_TEST_SOURCE") != "" {
Expand Down
8 changes: 4 additions & 4 deletions qstat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCLIModeFailureGetQstatOutput(t *testing.T) {
}
}

//Just testing to make sure that it doesn't generate unexpected errors.
// Just testing to make sure that it doesn't generate unexpected errors.
func TestGeneratedOutputGenerateQState(t *testing.T) {
//Force to run output and fail
os.Setenv(environmentPrefix+"TEST", "true")
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestDeleteQueuedJobByID(t *testing.T) {
"2",
},
},
wantErr: false,
wantErr: true,
},
{
name: "Test Mode. Should pass",
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestDeleteQueuedJobByID(t *testing.T) {
purgeBinary("qdel")
}

//Create an executable qstat file that will exit ok. Will also print the raw input just so we can verify it
// Create an executable qstat file that will exit ok. Will also print the raw input just so we can verify it
func fakeBinary(name string) {
contents := `#!/bin/bash
echo $0 $@
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestDeleteQueuedJobByUsernames(t *testing.T) {
"dbreeden",
},
},
wantErr: false,
wantErr: true,
},
{
name: "Test Mode",
Expand Down
1 change: 1 addition & 0 deletions queueinfo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package gogridengine

0 comments on commit f4ccc1a

Please sign in to comment.