Skip to content

Commit 62a4d21

Browse files
committed
Default link alias which is just the service name
Closes #37. Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
1 parent 73bd4ac commit 62a4d21

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

fig/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,12 @@ def _get_links(self, link_to_self):
282282
links = []
283283
for service, link_name in self.links:
284284
for container in service.containers():
285-
if link_name:
286-
links.append((container.name, link_name))
285+
links.append((container.name, link_name or service.name))
287286
links.append((container.name, container.name))
288287
links.append((container.name, container.name_without_project))
289288
if link_to_self:
290289
for container in self.containers():
290+
links.append((container.name, self.name))
291291
links.append((container.name, container.name))
292292
links.append((container.name, container.name_without_project))
293293
return links

tests/integration/service_test.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,62 @@ def test_start_container_inherits_options_from_constructor(self):
171171
def test_start_container_creates_links(self):
172172
db = self.create_service('db')
173173
web = self.create_service('web', links=[(db, None)])
174+
175+
db.start_container()
174176
db.start_container()
175177
web.start_container()
176-
self.assertIn('figtest_db_1', web.containers()[0].links())
177-
self.assertIn('db_1', web.containers()[0].links())
178+
179+
self.assertEqual(
180+
set(web.containers()[0].links()),
181+
set([
182+
'figtest_db_1', 'db_1',
183+
'figtest_db_2', 'db_2',
184+
'db',
185+
]),
186+
)
178187

179188
def test_start_container_creates_links_with_names(self):
180189
db = self.create_service('db')
181190
web = self.create_service('web', links=[(db, 'custom_link_name')])
191+
192+
db.start_container()
182193
db.start_container()
183194
web.start_container()
184-
self.assertIn('custom_link_name', web.containers()[0].links())
195+
196+
self.assertEqual(
197+
set(web.containers()[0].links()),
198+
set([
199+
'figtest_db_1', 'db_1',
200+
'figtest_db_2', 'db_2',
201+
'custom_link_name',
202+
]),
203+
)
185204

186205
def test_start_normal_container_does_not_create_links_to_its_own_service(self):
187206
db = self.create_service('db')
188-
c1 = db.start_container()
189-
c2 = db.start_container()
190-
self.assertNotIn(c1.name, c2.links())
207+
208+
db.start_container()
209+
db.start_container()
210+
211+
c = db.start_container()
212+
self.assertEqual(set(c.links()), set([]))
191213

192214
def test_start_one_off_container_creates_links_to_its_own_service(self):
193215
db = self.create_service('db')
194-
c1 = db.start_container()
195-
c2 = db.start_container(one_off=True)
196-
self.assertIn(c1.name, c2.links())
216+
217+
db.start_container()
218+
db.start_container()
219+
220+
c = db.start_container(one_off=True)
221+
222+
self.assertEqual(
223+
set(c.links()),
224+
set([
225+
'figtest_db_1', 'db_1',
226+
'figtest_db_2', 'db_2',
227+
'db',
228+
]),
229+
)
197230

198231
def test_start_container_builds_images(self):
199232
service = Service(

0 commit comments

Comments
 (0)