Skip to content

Commit 14b5ae8

Browse files
committed
tests: diskusage command
Signed-off-by: CrazyMax <[email protected]>
1 parent 67a9ba4 commit 14b5ae8

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/diskusage.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package tests
2+
3+
import (
4+
"encoding/json"
5+
"strings"
6+
"testing"
7+
8+
"github.com/moby/buildkit/client"
9+
"github.com/moby/buildkit/util/testutil/integration"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
var diskusageTests = []func(t *testing.T, sb integration.Sandbox){
14+
testDiskusage,
15+
testDiskusageVerbose,
16+
testDiskusageVerboseFormatError,
17+
testDiskusageFormatJSON,
18+
testDiskusageFormatGoTemplate,
19+
}
20+
21+
func testDiskusage(t *testing.T, sb integration.Sandbox) {
22+
buildTestProject(t, sb)
23+
cmd := buildxCmd(sb, withArgs("du"))
24+
out, err := cmd.Output()
25+
require.NoError(t, err, string(out))
26+
}
27+
28+
func testDiskusageVerbose(t *testing.T, sb integration.Sandbox) {
29+
buildTestProject(t, sb)
30+
cmd := buildxCmd(sb, withArgs("du", "--verbose"))
31+
out, err := cmd.Output()
32+
require.NoError(t, err, string(out))
33+
}
34+
35+
func testDiskusageVerboseFormatError(t *testing.T, sb integration.Sandbox) {
36+
buildTestProject(t, sb)
37+
cmd := buildxCmd(sb, withArgs("du", "--verbose", "--format=json"))
38+
out, err := cmd.Output()
39+
require.Error(t, err, string(out))
40+
}
41+
42+
func testDiskusageFormatJSON(t *testing.T, sb integration.Sandbox) {
43+
buildTestProject(t, sb)
44+
cmd := buildxCmd(sb, withArgs("du", "--format=json"))
45+
out, err := cmd.Output()
46+
require.NoError(t, err, string(out))
47+
48+
for _, line := range strings.Split(string(out), "\n") {
49+
var du client.UsageInfo
50+
err = json.Unmarshal([]byte(line), &du)
51+
require.NoError(t, err)
52+
require.NotEmpty(t, du.ID)
53+
}
54+
}
55+
56+
func testDiskusageFormatGoTemplate(t *testing.T, sb integration.Sandbox) {
57+
buildTestProject(t, sb)
58+
cmd := buildxCmd(sb, withArgs("du", "--format={{.ID}}: {{.Size}}"))
59+
out, err := cmd.Output()
60+
require.NoError(t, err, string(out))
61+
}

tests/integration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestIntegration(t *testing.T) {
3333
tests = append(tests, rmTests...)
3434
tests = append(tests, dialstdioTests...)
3535
tests = append(tests, composeTests...)
36+
tests = append(tests, diskusageTests...)
3637
testIntegration(t, tests...)
3738
}
3839

0 commit comments

Comments
 (0)