@@ -758,6 +758,66 @@ test('should use host specified by the --s3_host option', (t) => {
758758 } ;
759759 } ;
760760
761+ const parsed_package_json = {
762+ name : 'test' ,
763+ main : 'test.js' ,
764+ version : '0.1.0' ,
765+ binary : {
766+ module_name : 'binary-module-name' ,
767+ module_path : 'binary-module-path' ,
768+ host : 's3-production-path' ,
769+ development_host : 's3-development-path' ,
770+ staging_host : 's3-staging-path'
771+ }
772+ } ;
773+
774+ const hosts = [ 'production' , 'staging' , 'development' ] ;
775+ const cmds = [ 'install' , 'info' , 'publish' , 'unpublish' ] ;
776+ cmds . forEach ( ( cmd ) => {
777+ hosts . forEach ( ( host ) => {
778+ const checkAgainst = host !== 'production' ? `${ host } _host` : 'host' ;
779+ const cloned = JSON . parse ( JSON . stringify ( parsed_package_json ) ) ;
780+ const opts = versioning . evaluate ( cloned , makeOoptions ( cmd , host ) ) ;
781+
782+ t . equal ( opts . host , parsed_package_json . binary [ checkAgainst ] + '/' ) ;
783+ t . equal ( opts . hosted_path , parsed_package_json . binary [ checkAgainst ] + '/' ) ;
784+ t . equal ( opts . hosted_tarball , parsed_package_json . binary [ checkAgainst ] + '/' + opts . package_name ) ;
785+ } ) ;
786+ } ) ;
787+ cmds . forEach ( ( cmd ) => {
788+ hosts . forEach ( ( host ) => {
789+ parsed_package_json . binary = {
790+ module_name : 'binary-module-name' ,
791+ module_path : 'binary-module-path' ,
792+ host : { endpoint : 's3-production-path' } ,
793+ development_host : { endpoint : 's3-development-path' } ,
794+ staging_host : { endpoint : 's3-staging-path' }
795+ } ;
796+
797+ const checkAgainst = host !== 'production' ? `${ host } _host` : 'host' ;
798+ const cloned = JSON . parse ( JSON . stringify ( parsed_package_json ) ) ;
799+ const opts = versioning . evaluate ( cloned , makeOoptions ( cmd , host ) ) ;
800+
801+ t . equal ( opts . host , parsed_package_json . binary [ checkAgainst ] . endpoint + '/' ) ;
802+ t . equal ( opts . hosted_path , parsed_package_json . binary [ checkAgainst ] . endpoint + '/' ) ;
803+ t . equal ( opts . hosted_tarball , parsed_package_json . binary [ checkAgainst ] . endpoint + '/' + opts . package_name ) ;
804+ } ) ;
805+ } ) ;
806+ t . end ( ) ;
807+ } ) ;
808+
809+ test ( 'should use host specified by the --s3_host option (production_host used)' , ( t ) => {
810+ const makeOoptions = ( cmd , host ) => {
811+ return {
812+ s3_host : host ,
813+ argv : {
814+ remain : [ cmd ] ,
815+ cooked : [ cmd , '--s3_host' , host ] ,
816+ original : [ cmd , `--s3_host=${ host } ` ]
817+ }
818+ } ;
819+ } ;
820+
761821 const parsed_package_json = {
762822 name : 'test' ,
763823 main : 'test.js' ,
0 commit comments