Skip to content

Commit a253318

Browse files
authored
Merge pull request #4873 from vvoland/test-daemon-apiversion
testenv: Add DaemonAPIVersion helper
2 parents d1b8893 + 9831fea commit a253318

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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)