parseTestCases converts test case string to a list of struct testCaseWithWeight.
(testCaseString string)
| 79 | |
| 80 | // parseTestCases converts test case string to a list of struct testCaseWithWeight. |
| 81 | func parseTestCases(testCaseString string) []testCaseWithWeight { |
| 82 | testCaseStrings := strings.Split(testCaseString, ",") |
| 83 | testCases := make([]testCaseWithWeight, len(testCaseStrings)) |
| 84 | for i, str := range testCaseStrings { |
| 85 | testCaseNameAndWeight := strings.Split(str, ":") |
| 86 | if len(testCaseNameAndWeight) != 2 { |
| 87 | panic(fmt.Sprintf("invalid test case with weight: %s", str)) |
| 88 | } |
| 89 | // Check if test case is supported. |
| 90 | testCaseName := strings.ToLower(testCaseNameAndWeight[0]) |
| 91 | switch testCaseName { |
| 92 | case |
| 93 | "empty_unary", |
| 94 | "large_unary", |
| 95 | "client_streaming", |
| 96 | "server_streaming", |
| 97 | "ping_pong", |
| 98 | "empty_stream", |
| 99 | "timeout_on_sleeping_server", |
| 100 | "cancel_after_begin", |
| 101 | "cancel_after_first_response", |
| 102 | "status_code_and_message", |
| 103 | "custom_metadata": |
| 104 | default: |
| 105 | panic(fmt.Sprintf("unknown test type: %s", testCaseNameAndWeight[0])) |
| 106 | } |
| 107 | testCases[i].name = testCaseName |
| 108 | w, err := strconv.Atoi(testCaseNameAndWeight[1]) |
| 109 | if err != nil { |
| 110 | panic(fmt.Sprintf("%v", err)) |
| 111 | } |
| 112 | testCases[i].weight = w |
| 113 | } |
| 114 | return testCases |
| 115 | } |
| 116 | |
| 117 | // weightedRandomTestSelector defines a weighted random selector for test case types. |
| 118 | type weightedRandomTestSelector struct { |