1
- use std:: collections:: HashMap ;
2
-
3
1
use anyhow:: Context as _;
4
2
5
3
fn main ( ) {
6
- let dir = std:: fs:: read_dir ( "/Users/rylev/Code/fermyon/conformance-test/tests" ) . unwrap ( ) ;
7
- for entry in dir {
4
+ let tests_dir = download_tests ( ) ;
5
+
6
+ for entry in std:: fs:: read_dir ( tests_dir) . unwrap ( ) {
8
7
let entry = entry. unwrap ( ) ;
8
+ if !entry. path ( ) . is_dir ( ) {
9
+ continue ;
10
+ }
9
11
let spin_binary = "/Users/rylev/.local/bin/spin" . into ( ) ;
10
12
let test_config = std:: fs:: read_to_string ( entry. path ( ) . join ( "test.json5" ) ) . unwrap ( ) ;
11
13
let test_config: TestConfig = json5:: from_str ( & test_config) . unwrap ( ) ;
12
- let config = testing_framework:: TestEnvironmentConfig :: spin (
14
+ let env_config = testing_framework:: TestEnvironmentConfig :: spin (
13
15
spin_binary,
14
- [ "-f" . into ( ) , entry . path ( ) . to_str ( ) . unwrap ( ) . into ( ) ] ,
16
+ [ ] ,
15
17
move |e| {
18
+ e. copy_into ( entry. path ( ) . join ( "target" ) , "target" )
19
+ . context ( "failed to copy target directory" ) ?;
16
20
e. copy_into ( entry. path ( ) . join ( "spin.toml" ) , "spin.toml" )
17
21
. context ( "failed to copy spin.toml" ) ?;
18
- let mut cmd = std:: process:: Command :: new ( "spin" ) ;
19
- cmd. env ( "CARGO_TARGET_DIR" , entry. path ( ) . join ( "target" ) ) ;
20
- cmd. args ( [ "build" , "-f" , entry. path ( ) . to_str ( ) . unwrap ( ) ] ) ;
21
- e. run_in ( & mut cmd) ?;
22
22
Ok ( ( ) )
23
23
} ,
24
24
testing_framework:: ServicesConfig :: none ( ) ,
25
25
testing_framework:: runtimes:: SpinAppType :: Http ,
26
26
) ;
27
- let mut env = testing_framework:: TestEnvironment :: up ( config , |_| Ok ( ( ) ) ) . unwrap ( ) ;
27
+ let mut env = testing_framework:: TestEnvironment :: up ( env_config , |_| Ok ( ( ) ) ) . unwrap ( ) ;
28
28
let spin = env. runtime_mut ( ) ;
29
29
for invocation in test_config. invocations {
30
+ let Invocation :: Http ( invocation) = invocation;
30
31
let headers = invocation
31
32
. request
32
33
. headers
@@ -53,7 +54,7 @@ fn main() {
53
54
. headers ( )
54
55
. iter ( )
55
56
. map ( |( k, v) | ( k. to_lowercase ( ) , v. to_lowercase ( ) ) )
56
- . collect :: < HashMap < _ , _ > > ( ) ;
57
+ . collect :: < std :: collections :: HashMap < _ , _ > > ( ) ;
57
58
for expected_header in invocation. response . headers {
58
59
let expected_name = expected_header. name . to_lowercase ( ) ;
59
60
let expected_value = expected_header. value . map ( |v| v. to_lowercase ( ) ) ;
@@ -83,13 +84,45 @@ fn main() {
83
84
}
84
85
}
85
86
87
+ /// Download the conformance tests and return the path to the directory where they are written to
88
+ fn download_tests ( ) -> std:: path:: PathBuf {
89
+ let response = reqwest:: blocking:: get (
90
+ "https://github.com/fermyon/conformance-tests/releases/download/canary/tests.tar.gz" ,
91
+ )
92
+ . unwrap ( )
93
+ . error_for_status ( )
94
+ . unwrap ( ) ;
95
+ let response = flate2:: read:: GzDecoder :: new ( response) ;
96
+ let dir = std:: env:: temp_dir ( ) . join ( "conformance-tests" ) ;
97
+ for entry in tar:: Archive :: new ( response) . entries ( ) . unwrap ( ) {
98
+ let mut entry = entry. unwrap ( ) ;
99
+ if entry. header ( ) . entry_type ( ) != tar:: EntryType :: Regular {
100
+ continue ;
101
+ }
102
+ let path = dir. join ( entry. path ( ) . unwrap ( ) ) ;
103
+ let parent_dir = path. parent ( ) . unwrap ( ) ;
104
+ std:: fs:: create_dir_all ( & parent_dir) . unwrap ( ) ;
105
+ let mut file = std:: fs:: File :: create ( & path) . unwrap ( ) ;
106
+ std:: io:: copy ( & mut entry, & mut file) . unwrap ( ) ;
107
+ }
108
+ dir
109
+ }
110
+
111
+ /// The configuration of a conformance test
86
112
#[ derive( Debug , serde:: Deserialize ) ]
87
113
struct TestConfig {
88
114
invocations : Vec < Invocation > ,
89
115
}
90
116
91
117
#[ derive( Debug , serde:: Deserialize ) ]
92
- struct Invocation {
118
+ #[ serde( untagged) ]
119
+ enum Invocation {
120
+ Http ( HttpInvocation ) ,
121
+ }
122
+
123
+ /// An invocation of the runtime
124
+ #[ derive( Debug , serde:: Deserialize ) ]
125
+ struct HttpInvocation {
93
126
request : Request ,
94
127
response : Response ,
95
128
}
0 commit comments