def testFilterInstances_FilterService(self): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), service='service1')), set([self.instances['service1/v1/i1'], self.instances['service1/v1/i2'], self.instances['service1/v2/i1']])) self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), service='service2')), set([self.instances['service2/v1/i1']]))
def Run(self, args): # `--user-output-enabled=false` needed to prevent Display method from # consuming returned generator, and also to prevent this command from # causing confusing output all_instances = self.cli.Execute(['compute', 'instances', 'list', '--user-output-enabled', 'false']) app_engine_instances = [] for instance in all_instances: if AppEngineInstance.IsInstance(instance): gae_instance = AppEngineInstance.FromComputeEngineInstance(instance) app_engine_instances.append(gae_instance) return instances_util.FilterInstances(app_engine_instances, args.service, args.version)
def testFilterInstances_NoFilter(self): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()))), set(self.instances.values()))
def testFilterInstances_FilterInstanceResourcePath(self): for instance in self.instances.values(): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), instance=str(instance))), set([]))
def testFilterInstances_FilterInstanceName(self): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), instance='i2')), set([self.instances['service1/v1/i2']]))
def testFilterInstances_FilterBothNoMatch(self): # service and version are both good, but don't match anything self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), service='service2', version='v2')), set())
def testFilterInstances_FilterVersionBadVersion(self): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), version='badversion')), set())
def testFilterInstances_FilterServiceBadService(self): self.assertEqual( set(instances_util.FilterInstances(list(self.instances.values()), service='badservice')), set())