Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organize and document the execution engine package
Change-Id: I43c482b90d9364f5e9f0cf9350a61d75ab554701 Reviewed-on: https://gerrit.instructure.com/58501 Reviewed-by: Simon Williams <simon@instructure.com> Tested-by: Jenkins
- Loading branch information
1 parent
9df8140
commit c070d9b
Showing
5 changed files
with
105 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package engine | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// RunChecks does sanity checks on the Language, including checks that | ||
// stdin/stdout work as expected, and basic verification that the AppArmor | ||
// profile is in effect. | ||
func (lang *Language) RunChecks() (err error) { | ||
err = lang.runCheck("simple", &lang.Checks.Simple) | ||
if lang.ApparmorProfile == "" { | ||
// skip the apparmor tests when it's been disabled | ||
return | ||
} | ||
|
||
if err == nil { | ||
err = lang.runCheck("apparmor", &lang.Checks.Apparmor) | ||
} | ||
if err == nil { | ||
err = lang.runCheck("rlimit", &lang.Checks.Rlimit) | ||
} | ||
return | ||
} | ||
|
||
type check struct { | ||
Source, Stdin, Stdout, Stderr string | ||
ExitStatus int | ||
} | ||
|
||
type checks struct { | ||
Simple, Apparmor, Rlimit check | ||
} | ||
|
||
func (lang *Language) runCheck(testName string, check *check) error { | ||
result, err := lang.Run(&RunOptions{ | ||
Source: check.Source, | ||
Stdin: check.Stdin, | ||
Timeout: 30, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("Failure testing '%s' (%s): %v", lang.Name, testName, err) | ||
} | ||
|
||
output, _ := yaml.Marshal(result) | ||
|
||
errorString := fmt.Sprintf("for '%s' (%s).\n%s", lang.Name, testName, output) | ||
|
||
if result.RunStep == nil { | ||
return fmt.Errorf("Didn't run %s", errorString) | ||
} | ||
|
||
if result.RunStep.ExitCode != check.ExitStatus { | ||
return fmt.Errorf("Incorrect exit code %s", errorString) | ||
} | ||
|
||
match, err := regexp.MatchString(check.Stderr, result.RunStep.Stderr) | ||
if err != nil { | ||
return err | ||
} | ||
if match == false { | ||
return fmt.Errorf("Incorrect stderr %s", errorString) | ||
} | ||
|
||
match, err = regexp.MatchString(check.Stdout, result.RunStep.Stdout) | ||
if err != nil { | ||
return err | ||
} | ||
if match == false { | ||
return fmt.Errorf("Incorrect stdout %s", errorString) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters