|
| 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 | +} |
0 commit comments