Skip to content

Commit a8ac347

Browse files
authored
Ability to only run one test section in file in yaml test runner (#4404)
You can now pass -s "Test section name" to the rest-api-spec test runner to only run a single test inside a file. Before you could only filter to a file as whole. This also makes sure args with spaces are quoted when passing down from our build tooling (super rudimentary) We now emit Skip messages during the run so we can see the test itself skipped. Because in our current flow we run the test setup before evaluating the `skip` block its hard to see nothing happened because things are happening (setup requests) Lastly the proxy detection now includes `xpack` test suite. `mitmproxy -k` will work if we reroute https traffic to it.
1 parent e11d269 commit a8ac347

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

build/scripts/Commandline.fs

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ Execution hints can be provided anywhere on the command line
127127
not (x.StartsWith("random:")) &&
128128
not (x.StartsWith("docs:")) &&
129129
not (x.StartsWith("ref:")))
130+
|> List.map(fun (s:string) ->
131+
let containsSpace = s.Contains(" ")
132+
match s with | x when containsSpace -> sprintf "\"%s\"" x | s -> s
133+
)
134+
130135
let target =
131136
match (filteredArgs |> List.tryHead) with
132137
| Some t -> t.Replace("-one", "")

tests/Tests.YamlRunner/Commands.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let ReadTests (tests:LocateResults list) =
3535

3636
tests |> List.map (fun t -> { Folder= t.Folder; Files = readPaths t.Paths})
3737

38-
let RunTests (tests:YamlTestFolder list) client version namedSuite = async {
38+
let RunTests (tests:YamlTestFolder list) client version namedSuite sectionFilter = async {
3939
do! Async.SwitchToNewThread()
4040

4141
let f = tests.Length
@@ -45,7 +45,7 @@ let RunTests (tests:YamlTestFolder list) client version namedSuite = async {
4545
runner.GlobalSetup()
4646
let a (i, v) = async {
4747
let mainMessage = sprintf "[%i/%i] Folders : %s | " (i+1) f v.Folder
48-
let! op = runner.RunTestsInFolder mainMessage v
48+
let! op = runner.RunTestsInFolder mainMessage v sectionFilter
4949
return v, op |> Seq.toList
5050
}
5151
let x =

tests/Tests.YamlRunner/Program.fs

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Arguments =
1212
| [<First; MainCommand; CliPrefix(CliPrefix.None)>] NamedSuite of TestSuite
1313
| [<AltCommandLine("-f")>]Folder of string
1414
| [<AltCommandLine("-t")>]TestFile of string
15+
| [<AltCommandLine("-s")>]TestSection of string
1516
| [<AltCommandLine("-e")>]Endpoint of string
1617
| [<AltCommandLine("-r")>]Revision of string
1718
| [<AltCommandLine("-o")>]JUnitOutputFile of string
@@ -24,6 +25,7 @@ type Arguments =
2425
| Revision _ -> "The git revision to reference (commit/branch/tag). defaults to `master`"
2526
| Folder _ -> "Only run tests in this folder"
2627
| TestFile _ -> "Only run tests starting with this filename"
28+
| TestSection _ -> "Only run test with this name (best used in conjuction with -t)"
2729
| Endpoint _ -> "The elasticsearch endpoint to run tests against"
2830
| JUnitOutputFile _ -> "The path and file name to use for the junit xml output, defaults to a random tmp filename"
2931
| Profile _ -> "Print out process id and wait for confirmation to kick off the tests"
@@ -33,7 +35,7 @@ let private runningProxy = runningMitmProxy || Process.GetProcessesByName("fiddl
3335
let private defaultEndpoint namedSuite =
3436
let host =
3537
match (runningProxy, namedSuite) with
36-
| (true, Oss) -> "ipv.fiddler"
38+
| (true, _) -> "ipv.fiddler"
3739
| _ -> "localhost"
3840
let https = match namedSuite with | XPack -> "s" | _ -> ""
3941
sprintf "http%s://%s:9200" https host;
@@ -54,7 +56,7 @@ let private createClient endpoint namedSuite =
5456
// proxy
5557
let proxySettings =
5658
match (runningMitmProxy, namedSuite) with
57-
| (true, Oss) -> settings.Proxy(Uri("http://ipv4.fiddler:8080"), String(null), String(null))
59+
| (true, _) -> settings.Proxy(Uri("http://ipv4.fiddler:8080"), String(null), String(null))
5860
| _ -> settings
5961
// auth
6062
let authSettings =
@@ -104,6 +106,7 @@ let runMain (parsed:ParseResults<Arguments>) = async {
104106
let namedSuite = parsed.TryGetResult NamedSuite |> Option.defaultValue Oss
105107
let directory = parsed.TryGetResult Folder //|> Option.defaultValue "indices.create" |> Some
106108
let file = parsed.TryGetResult TestFile //|> Option.defaultValue "10_basic.yml" |> Some
109+
let section = parsed.TryGetResult TestSection //|> Option.defaultValue "10_basic.yml" |> Some
107110
let endpoint = parsed.TryGetResult Endpoint |> Option.defaultValue (defaultEndpoint namedSuite)
108111
let profile = parsed.TryGetResult Profile |> Option.defaultValue false
109112
let passedRevision = parsed.TryGetResult Revision
@@ -115,13 +118,13 @@ let runMain (parsed:ParseResults<Arguments>) = async {
115118

116119
printfn "Found version %s downloading specs from: %s" version revision
117120

118-
let! locateResults = Commands.LocateTests namedSuite revision directory file
119-
let readResults = Commands.ReadTests locateResults
121+
let! locateResults = Commands.LocateTests namedSuite revision directory file
122+
let readResults = Commands.ReadTests locateResults
120123
if profile then
121124
printf "Waiting for profiler to attach to pid: %O" <| Process.GetCurrentProcess().Id
122125
Console.ReadKey() |> ignore
123126

124-
let! runResults = Commands.RunTests readResults client version namedSuite
127+
let! runResults = Commands.RunTests readResults client version namedSuite section
125128
let summary = Commands.ExportTests runResults outputFile
126129

127130
Commands.PrettyPrintResults outputFile

tests/Tests.YamlRunner/TestsRunner.fs

+10-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type TestRunner(client:IElasticLowLevelClient, version: string, suite: TestSuite
5454
})
5555
(m, executedOperations)
5656

57-
member private this.RunTestFile subProgressbar (file:YamlTestDocument) = async {
57+
member private this.RunTestFile subProgressbar (file:YamlTestDocument) sectionFilter = async {
5858
let m section ops = this.CreateOperations section file.FileInfo ops subProgressbar
5959
let bootstrap section operations =
6060
let ops = operations |> Option.map (m section) |> Option.toList |> List.collect (fun (s, ops) -> ops)
@@ -65,6 +65,10 @@ type TestRunner(client:IElasticLowLevelClient, version: string, suite: TestSuite
6565
let sections =
6666
file.Tests
6767
|> List.map (fun s -> s.Operations |> m s.Name)
68+
|> List.filter(fun s ->
69+
let (name, _) = s
70+
match sectionFilter with | Some s when s <> name -> false | _ -> true
71+
)
6872
|> List.collect (fun s ->
6973
let (name, ops) = s
7074
[(name, setup @ ops)]
@@ -88,7 +92,9 @@ type TestRunner(client:IElasticLowLevelClient, version: string, suite: TestSuite
8892
match r with
8993
| Succeeded context -> Some (r, tl)
9094
| NotSkipped context -> Some (r, tl)
91-
| Skipped (context, reason) -> Some (r, [])
95+
| Skipped (context, reason) ->
96+
subProgressbar.WriteLine <| sprintf "%s: %s " r.Name (r.Context.Operation.Log())
97+
Some (r, [])
9298
| Failed context -> Some (r, [])
9399
| [] -> None
94100
)
@@ -142,7 +148,7 @@ type TestRunner(client:IElasticLowLevelClient, version: string, suite: TestSuite
142148
client.Indices.Refresh<VoidResponse>("_all") |> ignore
143149

144150

145-
member this.RunTestsInFolder mainMessage (folder:YamlTestFolder) = async {
151+
member this.RunTestsInFolder mainMessage (folder:YamlTestFolder) sectionFilter = async {
146152
let l = folder.Files.Length
147153
let run (i, document) = async {
148154
let file = sprintf "%s/%s" document.FileInfo.Directory.Name document.FileInfo.Name
@@ -151,7 +157,7 @@ type TestRunner(client:IElasticLowLevelClient, version: string, suite: TestSuite
151157
let message = sprintf "Inspecting file for sections"
152158
use p = progress.Spawn(0, message, barOptions)
153159

154-
let! result = this.RunTestFile p document
160+
let! result = this.RunTestFile p document sectionFilter
155161

156162
return document, result
157163
}

0 commit comments

Comments
 (0)