docker: add unit tests, reach 100% coverage, migrate to moby/moby client - #2147
Open
Seanstoppable wants to merge 3 commits into
Open
docker: add unit tests, reach 100% coverage, migrate to moby/moby client#2147Seanstoppable wants to merge 3 commits into
Seanstoppable wants to merge 3 commits into
Conversation
- Extract pure formatConversion functions formatContainerStates and formatSystemInfo from client.go so container/system formatting can be tested without a docker daemon. - Add table-driven tests for padSlice, formatContainerStates, formatSystemInfo, Settings (NewSettingsFromYAML), and Widget.display. - Coverage for modules/docker: 0.0%% -> 64.2%%.
- Introduce dockerAPIClient interface (Info/DiskUsage/ContainerList) implemented by *client.Client, so Widget.cli can be swapped for a fake in tests instead of requiring a real docker daemon. - Make client construction (newDockerClient var) injectable so NewWidget's success/error paths are testable, while still covering the real client.NewClientWithOpts call directly (no daemon needed to construct the client object). - Add fakeDockerClient test double plus table-driven tests for getSystemInfo, getContainerStates, refreshDisplayBuffer, Refresh, and NewWidget covering success and error paths. - Coverage: 64.2%% -> 100%%.
Replace github.com/docker/docker (the full moby monolith, +incompatible) with the split github.com/moby/moby/client and github.com/moby/moby/api modules, which have proper go.mod versioning and a much smaller transitive dependency graph. The new client redesigns Info/DiskUsage/ContainerList to return wrapped result types and pre-aggregated disk-usage totals, so formatSystemInfo no longer needs to manually sum SizeRw/Size/ UsageData.Size across container/image/volume slices - it now takes the already-computed per-category totals directly. go.mod: github.com/docker/docker removed; github.com/moby/moby/client and github.com/moby/moby/api added (go mod tidy also dropped several now-unused transitive deps).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
modules/dockercovering container-state formatting, system-info display, and settings, using manually constructed structs so tests don't require a running docker daemon. Table-driven throughout.dockerAPIClientinterface (and an injectablenewDockerClientconstructor) soNewWidget/Refresh/getSystemInfo/getContainerStatescan be tested with a fake client, bringing coverage from 0% → 100%.github.com/docker/docker(the full moby monolith,+incompatible) onto the split, properly-versionedgithub.com/moby/moby/client+github.com/moby/moby/apimodules for a smaller dependency footprint. Adapted to the redesigned client API (wrapped result types, pre-aggregated disk-usage totals), which also simplifiedformatSystemInfo— it no longer manually sums container/image/volume sizes.Coverage
dockerAPIClientinterface refactorDetails
client.go/utils.go/widget.go: extracted pure formatting functions (formatContainerStates,formatSystemInfo) from daemon-calling code, added thedockerAPIClientinterface, and made client construction injectable via a package-levelnewDockerClientvar.utils_test.go,container_states_test.go,system_info_test.go,settings_test.go,widget_test.go,fake_client_test.go,client_test.go,new_widget_test.go.go.mod: removedgithub.com/docker/docker; addedgithub.com/moby/moby/clientandgithub.com/moby/moby/api; rango mod tidy(dropped several now-unused transitive deps).Validation
go build ./...— cleango vet ./...— cleango test ./modules/docker/... -cover— 100.0% of statements, all tests passinggolangci-lint run ./modules/docker/...— clean (one pre-existing, unrelated gofmt issue insettings.gopredates this change and was left untouched per scope)