@@ -215,7 +215,7 @@ pub enum CacheType {
215215 S3 ( S3CacheConfig ) ,
216216}
217217
218- #[ derive( Debug , Default , Serialize , Deserialize ) ]
218+ #[ derive( Debug , Default , Serialize , Deserialize , PartialEq , Eq ) ]
219219#[ serde( deny_unknown_fields) ]
220220pub struct CacheConfigs {
221221 pub azure : Option < AzureCacheConfig > ,
@@ -404,7 +404,7 @@ impl Default for DistConfig {
404404}
405405
406406// TODO: fields only pub for tests
407- #[ derive( Debug , Default , Serialize , Deserialize ) ]
407+ #[ derive( Debug , Default , Serialize , Deserialize , Eq , PartialEq ) ]
408408#[ serde( default ) ]
409409#[ serde( deny_unknown_fields) ]
410410pub struct FileConfig {
@@ -938,3 +938,92 @@ fn test_gcs_oauth_url() {
938938 None => unreachable ! ( ) ,
939939 } ;
940940}
941+
942+
943+
944+ #[ test]
945+ fn full_toml_parse ( ) {
946+ const CONFIG_STR : & str = r#"
947+ [dist]
948+ # where to find the scheduler
949+ scheduler_url = "http://1.2.3.4:10600"
950+ # a set of prepackaged toolchains
951+ toolchains = []
952+ # the maximum size of the toolchain cache in bytes
953+ toolchain_cache_size = 5368709120
954+ cache_dir = "/home/user/.cache/sccache-dist-client"
955+
956+ [dist.auth]
957+ type = "token"
958+ token = "secrettoken"
959+
960+
961+ #[cache.azure]
962+ # does not work as it appears
963+
964+ [cache.disk]
965+ dir = "/tmp/.cache/sccache"
966+ size = 7516192768 # 7 GiBytes
967+
968+ [cache.gcs]
969+ # optional url
970+ url = "..."
971+ rw_mode = "READ_ONLY"
972+ # rw_mode = "READ_WRITE"
973+ cred_path = "/psst/secret/cred"
974+ bucket = "bucket"
975+
976+ [cache.memcached]
977+ url = "..."
978+
979+ [cache.redis]
980+ url = "redis://user:[email protected] :6379/1" 981+
982+ [cache.s3]
983+ bucket = "name"
984+ endpoint = "s3-us-east-1.amazonaws.com"
985+ use_ssl = true
986+ "# ;
987+
988+ let file_config: FileConfig = toml:: from_str ( CONFIG_STR ) . expect ( "Is valid toml." ) ;
989+ assert_eq ! ( file_config,
990+ FileConfig {
991+ cache: CacheConfigs {
992+ azure: None , // TODO not sure how to represent a unit struct in TOML Some(AzureCacheConfig),
993+ disk: Some ( DiskCacheConfig {
994+ dir: PathBuf :: from( "/tmp/.cache/sccache" ) ,
995+ size: 7 * 1024 * 1024 * 1024 ,
996+ } ) ,
997+ gcs: Some ( GCSCacheConfig {
998+ url: Some ( "..." . to_owned( ) ) ,
999+ bucket: "bucket" . to_owned( ) ,
1000+ cred_path: Some ( PathBuf :: from( "/psst/secret/cred" ) ) ,
1001+ rw_mode: GCSCacheRWMode :: ReadOnly ,
1002+
1003+ } ) ,
1004+ redis: Some ( RedisCacheConfig {
1005+ url
: "redis://user:[email protected] :6379/1" . to_owned
( ) , 1006+ } ) ,
1007+ memcached: Some ( MemcachedCacheConfig {
1008+ url: "..." . to_owned( ) ,
1009+ } ) ,
1010+ s3: Some ( S3CacheConfig {
1011+ bucket: "name" . to_owned( ) ,
1012+ endpoint: "s3-us-east-1.amazonaws.com" . to_owned( ) ,
1013+ use_ssl: true ,
1014+ } ) ,
1015+ } ,
1016+ dist: DistConfig {
1017+ auth: DistAuth :: Token { token: "secrettoken" . to_owned( ) } ,
1018+ #[ cfg( any( feature = "dist-client" , feature = "dist-server" ) ) ]
1019+ scheduler_url: Some ( parse_http_url( "http://1.2.3.4:10600" ) . map( |url| { HTTPUrl :: from_url( url) } ) . expect( "Scheduler url must be valid url str" ) ) ,
1020+ #[ cfg( not( any( feature = "dist-client" , feature = "dist-server" ) ) ) ]
1021+ scheduler_url: Some ( "http://1.2.3.4:10600" . to_owned( ) ) ,
1022+ cache_dir: PathBuf :: from( "/home/user/.cache/sccache-dist-client" ) ,
1023+ toolchains: vec![ ] ,
1024+ toolchain_cache_size: 5368709120 ,
1025+ rewrite_includes_only: false ,
1026+ } ,
1027+ }
1028+ )
1029+ }
0 commit comments