Skip to content

Commit 9831fea

Browse files
committed
testenv: Add DaemonAPIVersion helper
Allow tests to check the negotiated API version used by the client. Can be used to skip tests based on API versions, for example: ```go skip.If(t, versions.LessThan(environment.DaemonAPIVersion(t), "1.44")) ``` will skip the test if the API version is older than 1.44 Signed-off-by: Paweł Gronowski <[email protected]>
1 parent d1b8893 commit 9831fea

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

internal/test/environment/testenv.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,14 @@ func SkipIfNotPlatform(t *testing.T, platform string) {
108108
daemonPlatform := strings.TrimSpace(result.Stdout())
109109
skip.If(t, daemonPlatform != platform, "running against a non %s daemon", platform)
110110
}
111+
112+
// DaemonAPIVersion returns the negotiated daemon API version.
113+
func DaemonAPIVersion(t *testing.T) string {
114+
t.Helper()
115+
// Use Client.APIVersion instead of Server.APIVersion.
116+
// The latter is the maximum version that the server supports
117+
// while the Client.APIVersion contains the negotiated version.
118+
result := icmd.RunCmd(icmd.Command("docker", "version", "--format", "{{.Client.APIVersion}}"))
119+
result.Assert(t, icmd.Expected{Err: icmd.None})
120+
return strings.TrimSpace(result.Stdout())
121+
}

0 commit comments

Comments
 (0)