MCPcopy Create free account
hub / github.com/commander-cli/commander / Validate

Function Validate

pkg/runtime/validator.go:26–66  ·  view source on GitHub ↗

Validate validates the test results with the expected values The test should hold the result and expected to validate the result

(test TestCase)

Source from the content-addressed store, hash-verified

24// Validate validates the test results with the expected values
25// The test should hold the result and expected to validate the result
26func Validate(test TestCase) TestResult {
27 equalMatcher := matcher.NewMatcher(matcher.Equal)
28
29 log.Println("title: '"+test.Title+"'", " Stdout-Expected: ", test.Expected.Stdout)
30 matcherResult := validateExpectedOut(test.Result.Stdout, test.Expected.Stdout)
31 log.Println("title: '"+test.Title+"'", " Stdout-Result: ", matcherResult.Success)
32 if !matcherResult.Success {
33 return TestResult{
34 ValidationResult: newValidationResult(matcherResult),
35 TestCase: test,
36 FailedProperty: Stdout,
37 }
38 }
39
40 log.Println("title: '"+test.Title+"'", " Stderr-Expected: ", test.Expected.Stderr)
41 matcherResult = validateExpectedOut(test.Result.Stderr, test.Expected.Stderr)
42 log.Println("title: '"+test.Title+"'", " Stderr-Result: ", matcherResult.Success)
43 if !matcherResult.Success {
44 return TestResult{
45 ValidationResult: newValidationResult(matcherResult),
46 TestCase: test,
47 FailedProperty: Stderr,
48 }
49 }
50
51 log.Println("title: '"+test.Title+"'", " Exit-Expected: ", test.Expected.ExitCode)
52 matcherResult = equalMatcher.Match(test.Result.ExitCode, test.Expected.ExitCode)
53 log.Println("title: '"+test.Title+"'", " Exit-Result: ", matcherResult.Success)
54 if !matcherResult.Success {
55 return TestResult{
56 ValidationResult: newValidationResult(matcherResult),
57 TestCase: test,
58 FailedProperty: ExitCode,
59 }
60 }
61
62 return TestResult{
63 ValidationResult: newValidationResult(matcherResult),
64 TestCase: test,
65 }
66}
67
68func validateExpectedOut(got string, expected ExpectedOut) matcher.MatcherResult {
69 var m matcher.Matcher

Callers 7

ExecuteMethod · 0.85
ExecuteMethod · 0.85
Test_ValidateFunction · 0.85
ExecuteMethod · 0.85

Calls 4

MatchMethod · 0.95
NewMatcherFunction · 0.92
validateExpectedOutFunction · 0.85
newValidationResultFunction · 0.85

Tested by 4

Test_ValidateFunction · 0.68