import { FabricEnvironmentRegistry } from '../../src/registries/FabricEnvironmentRegistry' ; import * as chai from 'chai' ; import * as chaiAsPromised from 'chai-as-promised' ; import * as path from 'path' ; import { FabricEnvironmentRegistryEntry , EnvironmentType , EnvironmentFlags } from '../../src/registries/FabricEnvironmentRegistryEntry' ; import { FabricRuntimeUtil } from '../../src/util/FabricRuntimeUtil' ; chai . should ( ) ; chai . use ( chaiAsPromised ) ; describe ( 'FabricEnvironmentRegistry' , ( ) => { const registry = FabricEnvironmentRegistry . instance ( ) ; before ( async ( ) => { const registryPath = path . join ( __dirname , 'tmp' , 'registries' ) ; registry . setRegistryPath ( registryPath ) ; } ) ; beforeEach ( async ( ) => { await registry . clear ( ) ; } ) ; afterEach ( async ( ) => { await registry . clear ( ) ; } ) ; it ( 'should get all the environments and put microfab fabrics first' , async ( ) => { const environmentOne = new FabricEnvironmentRegistryEntry ( { name : 'environmentOne' , environmentType : EnvironmentType . ENVIRONMENT } ) ; await registry . getAll ( ) . should . eventually . deep . equal ( [ ] ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : 'otherLocalEnv' , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : FabricRuntimeUtil . LOCAL_FABRIC , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : 'anotherLocalEnv' , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : 'finalLocalEnv' , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ) ; const localFabricEntry = await FabricEnvironmentRegistry . instance ( ) . get ( FabricRuntimeUtil . LOCAL_FABRIC ) ; const otherLocalEntry = await FabricEnvironmentRegistry . instance ( ) . get ( 'otherLocalEnv' ) ; const finalLocalEntry = await FabricEnvironmentRegistry . instance ( ) . get ( 'finalLocalEnv' ) ; const anotherLocalEntry = await FabricEnvironmentRegistry . instance ( ) . get ( 'anotherLocalEnv' ) ; await registry . add ( environmentOne ) ; const result = await registry . getAll ( ) ; result . should . deep . equal ( [ localFabricEntry , anotherLocalEntry , finalLocalEntry , otherLocalEntry , environmentOne ] ) ; } ) ; it ( 'should get all environments but not show local microfabs' , async ( ) => { const environmentOne = new FabricEnvironmentRegistryEntry ( { name : 'environmentOne' , environmentType : EnvironmentType . ENVIRONMENT } ) ; await registry . getAll ( ) . should . eventually . deep . equal ( [ ] ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : 'localenv' , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ) ; await registry . add ( environmentOne ) ; await registry . getAll ( [ ] , [ EnvironmentFlags . LOCAL ] ) . should . eventually . deep . equal ( [ environmentOne ] ) ; } ) ; it ( 'should get all environments but not show microfabs' , async ( ) => { const environmentOne = new FabricEnvironmentRegistryEntry ( { name : 'environmentOne' , environmentType : EnvironmentType . ENVIRONMENT } ) ; await registry . getAll ( ) . should . eventually . deep . equal ( [ ] ) ; await FabricEnvironmentRegistry . instance ( ) . add ( new FabricEnvironmentRegistryEntry ( { name : 'microfab' , managedRuntime : false , environmentType : EnvironmentType . MICROFAB_ENVIRONMENT } ) ) ; await registry . add ( environmentOne ) ; await registry . getAll ( [ ] , [ EnvironmentFlags . MICROFAB ] ) . should . eventually . deep . equal ( [ environmentOne ] ) ; } ) ; it ( 'should get all the ops tools environments' , async ( ) => { const environmentOne = new FabricEnvironmentRegistryEntry ( { name : 'environmentOne' , environmentType : EnvironmentType . ENVIRONMENT } ) ; await registry . getAll ( ) . should . eventually . deep . equal ( [ ] ) ; const environmentThree = new FabricEnvironmentRegistryEntry ( { name : FabricRuntimeUtil . LOCAL_FABRIC , managedRuntime : true , environmentType : EnvironmentType . LOCAL_MICROFAB_ENVIRONMENT } ) ; await FabricEnvironmentRegistry . instance ( ) . add ( environmentThree ) ; const environmentFour = new FabricEnvironmentRegistryEntry ( { name : 'opsToolsEnv' , managedRuntime : true , environmentType : EnvironmentType . OPS_TOOLS_ENVIRONMENT } ) ; await FabricEnvironmentRegistry . instance ( ) . add ( environmentFour ) ; await registry . add ( environmentOne ) ; await registry . getAll ( [ EnvironmentFlags . OPS_TOOLS ] ) . should . eventually . deep . equal ( [ environmentFour ] ) ; } ) ; } ) ;