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

Function TestWatch_Sync

pkg/compose/watch_test.go:76–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestWatch_Sync(t *testing.T) {
77 mockCtrl := gomock.NewController(t)
78 cli := mocks.NewMockCli(mockCtrl)
79 cli.EXPECT().Err().Return(streams.NewOut(os.Stderr)).AnyTimes()
80 apiClient := mocks.NewMockAPIClient(mockCtrl)
81 apiClient.EXPECT().ContainerList(gomock.Any(), gomock.Any()).Return(client.ContainerListResult{
82 Items: []container.Summary{
83 testContainer("test", "123", false),
84 },
85 }, nil).AnyTimes()
86 // we expect the image to be pruned
87 apiClient.EXPECT().ImageList(gomock.Any(), client.ImageListOptions{
88 Filters: make(client.Filters).
89 Add("dangling", "true").
90 Add("label", api.ProjectLabel+"=myProjectName"),
91 }).Return(client.ImageListResult{
92 Items: []image.Summary{
93 {ID: "123"},
94 {ID: "456"},
95 },
96 }, nil).Times(1)
97 apiClient.EXPECT().ImageRemove(gomock.Any(), "123", client.ImageRemoveOptions{}).Times(1)
98 apiClient.EXPECT().ImageRemove(gomock.Any(), "456", client.ImageRemoveOptions{}).Times(1)
99 //
100 cli.EXPECT().Client().Return(apiClient).AnyTimes()
101
102 ctx, cancelFunc := context.WithCancel(t.Context())
103 t.Cleanup(cancelFunc)
104
105 proj := types.Project{
106 Name: "myProjectName",
107 Services: types.Services{
108 "test": {
109 Name: "test",
110 },
111 },
112 }
113
114 watcher := testWatcher{
115 events: make(chan watch.FileEvent),
116 errors: make(chan error),
117 }
118
119 syncer := newFakeSyncer()
120 clock := clockwork.NewFakeClock()
121 go func() {
122 service := composeService{
123 dockerCli: cli,
124 clock: clock,
125 }
126 rules, err := getWatchRules(&types.DevelopConfig{
127 Watch: []types.Trigger{
128 {
129 Path: "/sync",
130 Action: "sync",
131 Target: "/work",
132 Ignore: []string{"ignore"},
133 },

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
watchEventsMethod · 0.95
EventsMethod · 0.95
NewMockCliFunction · 0.92
NewMockAPIClientFunction · 0.92
NewFileEventFunction · 0.92
testContainerFunction · 0.85
newFakeSyncerFunction · 0.85
getWatchRulesFunction · 0.85
ErrorMethod · 0.80
ErrMethod · 0.65

Tested by

no test coverage detected