1+ use crate :: architecture:: Architecture ;
12use crate :: error:: { Error , Result } ;
23use crate :: ostype:: OsType ;
34use std:: { fs, io, path:: Path , path:: PathBuf } ;
@@ -9,14 +10,21 @@ mod tests {
910 use flate2:: write:: GzEncoder ;
1011 use flate2:: Compression ;
1112 use std:: env;
13+ use std:: env:: consts;
1214 use std:: fs:: File ;
1315 use tempfile:: NamedTempFile ;
1416
1517 #[ test]
1618 fn test_generate_filename ( ) {
17- assert_eq ! ( generate_filename( OsType :: Plan9 , "def" ) , "ec-plan9-def" ) ;
19+ assert_eq ! (
20+ generate_filename( OsType :: Plan9 , Architecture :: Amd64 ) ,
21+ "ec-plan9-amd64"
22+ ) ;
1823
19- assert_eq ! ( generate_filename( OsType :: Linux , "amd64" ) , "ec-linux-amd64" ) ;
24+ assert_eq ! (
25+ generate_filename( OsType :: Linux , Architecture :: I386 ) ,
26+ "ec-linux-386"
27+ ) ;
2028 }
2129
2230 #[ test]
@@ -68,9 +76,10 @@ mod tests {
6876 fn test_download ( ) -> Result < ( ) > {
6977 let base_url = generate_base_url ( "2.0.3" ) ;
7078 let base_path = get_base_path ( env:: current_exe ( ) . unwrap ( ) ) . unwrap ( ) ;
71- let os_type = sys_info:: os_type ( ) ?. parse :: < OsType > ( ) ?;
79+ let architecture = consts:: ARCH . parse :: < Architecture > ( ) ?;
80+ let os_type = consts:: OS . parse :: < OsType > ( ) ?;
7281
73- let filename = generate_filename ( os_type, get_architecture ( ) . unwrap ( ) ) ;
82+ let filename = generate_filename ( os_type, architecture ) ;
7483
7584 let result = download ( & base_url, & base_path, & filename) ;
7685 let tar_path = format ! ( "{}/{}.tar.gz" , base_path, filename) ;
@@ -118,25 +127,12 @@ mod tests {
118127 }
119128}
120129
121- // TODO: How to use cfg to pass a value into this function to be able to test it?
122- // TODO: Test
123- pub fn get_architecture ( ) -> Result < & ' static str > {
124- // TODO: This is not sufficient and needs to care for more cases
125- if cfg ! ( target_pointer_width = "64" ) {
126- Ok ( "amd64" )
127- } else if cfg ! ( target_pointer_width = "32" ) {
128- Ok ( "386" )
129- } else {
130- Err ( Error :: UnknownArch )
131- }
132- }
133-
134130pub fn path_exists ( filename : impl AsRef < std:: path:: Path > ) -> bool {
135131 filename. as_ref ( ) . exists ( )
136132}
137133
138- pub fn generate_filename ( os : OsType , arch : & str ) -> String {
139- format ! ( "ec-{}-{}" , os. stringify( ) , arch)
134+ pub fn generate_filename ( os : OsType , arch : Architecture ) -> String {
135+ format ! ( "ec-{}-{}" , os. stringify( ) , arch. stringify ( ) )
140136}
141137
142138pub fn generate_base_url ( version : & str ) -> String {
0 commit comments