MCPcopy
hub / github.com/docker/compose / TestServiceLinks

Function TestServiceLinks

pkg/compose/convergence_test.go:64–220  ·  pkg/compose/convergence_test.go::TestServiceLinks
(t *testing.T)

Source from the content-addressed store, hash-verified

62}
63
64func TestServiceLinks(t *testing.T) {
65 const dbContainerName = "/" + testProject + "-db-1"
66 const webContainerName = "/" + testProject + "-web-1"
67 s := types.ServiceConfig{
68 Name: "web",
69 Scale: intPtr(1),
70 }
71
72 containerListOptions := client.ContainerListOptions{
73 Filters: projectFilter(testProject).Add("label",
74 serviceFilter("db"),
75 oneOffFilter(false),
76 api.ConfigHashLabel,
77 ),
78 All: true,
79 }
80
81 t.Run("service links default", func(t *testing.T) {
82 mockCtrl := gomock.NewController(t)
83 defer mockCtrl.Finish()
84
85 apiClient := mocks.NewMockAPIClient(mockCtrl)
86 cli := mocks.NewMockCli(mockCtrl)
87 tested, err := NewComposeService(cli)
88 assert.NilError(t, err)
89 cli.EXPECT().Client().Return(apiClient).AnyTimes()
90
91 s.Links = []string{"db"}
92
93 c := testContainer("db", dbContainerName, false)
94 apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return(client.ContainerListResult{
95 Items: []container.Summary{c},
96 }, nil)
97
98 links, err := tested.(*composeService).getLinks(t.Context(), testProject, s, 1)
99 assert.NilError(t, err)
100
101 assert.Equal(t, len(links), 3)
102 assert.Equal(t, links[0], "testProject-db-1:db")
103 assert.Equal(t, links[1], "testProject-db-1:db-1")
104 assert.Equal(t, links[2], "testProject-db-1:testProject-db-1")
105 })
106
107 t.Run("service links", func(t *testing.T) {
108 mockCtrl := gomock.NewController(t)
109 defer mockCtrl.Finish()
110 apiClient := mocks.NewMockAPIClient(mockCtrl)
111 cli := mocks.NewMockCli(mockCtrl)
112 tested, err := NewComposeService(cli)
113 assert.NilError(t, err)
114 cli.EXPECT().Client().Return(apiClient).AnyTimes()
115
116 s.Links = []string{"db:db"}
117
118 c := testContainer("db", dbContainerName, false)
119
120 apiClient.EXPECT().ContainerList(gomock.Any(), containerListOptions).Return(client.ContainerListResult{
121 Items: []container.Summary{c},

Callers

nothing calls this directly

Calls 14

EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewMockAPIClientFunction · 0.92
NewMockCliFunction · 0.92
intPtrFunction · 0.85
projectFilterFunction · 0.85
serviceFilterFunction · 0.85
oneOffFilterFunction · 0.85
NewComposeServiceFunction · 0.85
testContainerFunction · 0.85
getLinksMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected