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

Function TestCollectObservedState

pkg/compose/observed_state_test.go:82–203  ·  pkg/compose/observed_state_test.go::TestCollectObservedState
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestCollectObservedState(t *testing.T) {
83 mockCtrl := gomock.NewController(t)
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 project := &types.Project{
92 Name: "myproject",
93 Services: types.Services{
94 "web": {Name: "web"},
95 "db": {Name: "db"},
96 },
97 Networks: types.Networks{
98 "frontend": {Name: "myproject_frontend"},
99 },
100 Volumes: types.Volumes{
101 "data": {Name: "myproject_data"},
102 },
103 }
104
105 // Mock ContainerList
106 apiClient.EXPECT().ContainerList(gomock.Any(), gomock.Any()).Return(client.ContainerListResult{
107 Items: []container.Summary{
108 {
109 ID: "c1",
110 Names: []string{"/myproject-web-1"},
111 State: container.StateRunning,
112 Labels: map[string]string{
113 api.ServiceLabel: "web",
114 api.ProjectLabel: "myproject",
115 api.ConfigHashLabel: "hash1",
116 api.ContainerNumberLabel: "1",
117 api.OneoffLabel: "False",
118 },
119 },
120 {
121 ID: "c2",
122 Names: []string{"/myproject-db-1"},
123 State: container.StateRunning,
124 Labels: map[string]string{
125 api.ServiceLabel: "db",
126 api.ProjectLabel: "myproject",
127 api.ConfigHashLabel: "hash2",
128 api.ContainerNumberLabel: "1",
129 api.OneoffLabel: "False",
130 },
131 },
132 {
133 ID: "c3",
134 Names: []string{"/myproject-old-1"},
135 State: container.StateExited,
136 Labels: map[string]string{
137 api.ServiceLabel: "old",
138 api.ProjectLabel: "myproject",
139 api.ConfigHashLabel: "hash3",

Callers

nothing calls this directly

Calls 10

EXPECTMethod · 0.95
EXPECTMethod · 0.95
NewMockAPIClientFunction · 0.92
NewMockCliFunction · 0.92
NewComposeServiceFunction · 0.85
collectObservedStateMethod · 0.80
ClientMethod · 0.45
ContainerListMethod · 0.45
NetworkListMethod · 0.45
VolumeListMethod · 0.45

Tested by

no test coverage detected