Skip to content

Commit 3a8be14

Browse files
committed
[#76585] cli: Add tests for input file errors in write_{file,rootfs}
Signed-off-by: Piotr Wojnarowski <pwojnarowski@antmicro.com>
1 parent 24f42fa commit 3a8be14

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tools/rdfm-artifact/cli/write_file_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ func TestWriteSingleFileConflictingName(t *testing.T) {
3535
}
3636
}
3737

38+
func TestWriteSingleFileNonexistentSourceFile(t *testing.T) {
39+
app := NewApp()
40+
41+
filename := "somefilethatdoesnotexist"
42+
err := app.Run([]string{
43+
"rdfm-artifact",
44+
"write",
45+
"single-file",
46+
"--artifact-name", "dummy_name",
47+
"--device-type", "dummy_type",
48+
"--file", filename,
49+
"--dest-dir", "/dummy/dir",
50+
})
51+
52+
assert.ErrorContains(t, err, fmt.Sprintf("can not open data file: %v", filename))
53+
}
54+
3855
// Test writing a single file artifact, along with its metadata
3956
func TestWriteSingleFileArtifact(t *testing.T) {
4057
defer os.Remove(testFileArtifactPath)

tools/rdfm-artifact/cli/write_rootfs_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"os"
56
"testing"
67

@@ -14,6 +15,22 @@ const (
1415
testRootfsArtifactPath = "../tests/data/full-rootfs-test.rdfm"
1516
)
1617

18+
func TestWriteFullRootfsArtifactNonexistentSourceFile(t *testing.T) {
19+
app := NewApp()
20+
21+
filename := "somefilethatdoesnotexist"
22+
err := app.Run([]string{
23+
"rdfm-artifact",
24+
"write",
25+
"rootfs-image",
26+
"--artifact-name", "dummy_name",
27+
"--device-type", "dummy_type",
28+
"--file", filename,
29+
})
30+
31+
assert.ErrorContains(t, err, fmt.Sprintf("open %v: no such file or directory", filename))
32+
}
33+
1734
// Test writing a full rootfs artifact, along with its metadata
1835
func TestWriteFullRootfsArtifact(t *testing.T) {
1936
defer os.Remove(testRootfsArtifactPath)

0 commit comments

Comments
 (0)