Skip to content

Commit

Permalink
Fixed nil pointer excpetion in upload
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Feb 21, 2024
1 parent 65fb6e5 commit 7b1e354
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion commands/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
if programmer == "" && pme.GetProfile() != nil {
programmer = pme.GetProfile().Programmer
}
if programmer == "" {
if programmer == "" && sk != nil {
programmer = sk.GetDefaultProgrammer()
}

Expand Down
41 changes: 41 additions & 0 deletions internal/integrationtest/upload_mock/upload_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,44 @@ func generateBuildDir(sketchPath *paths.Path, t *testing.T) *paths.Path {
require.NoError(t, buildDir.ToAbs())
return buildDir
}

func TestUploadWithInputDirFlag(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "install", "arduino:mbed_opta")
require.NoError(t, err)

sketchPath := cli.SketchbookDir().Join("TestSketchForUpload")
_, _, err = cli.Run("sketch", "new", sketchPath.String())
require.NoError(t, err)

// Create a fake build directory
buildDir := sketchPath.Join("build")
require.NoError(t, buildDir.MkdirAll())
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.bin").WriteFile(nil))
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.elf").WriteFile(nil))
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.hex").WriteFile(nil))
require.NoError(t, buildDir.Join("TestSketchForUpload.ino.map").WriteFile(nil))

// Test with input-dir flag
_, _, err = cli.Run(
"upload",
"-b", "arduino:mbed_opta:opta",
"-i", buildDir.String(),
"-t",
"-p", "/dev/ttyACM0",
"--dry-run", "-v",
sketchPath.String())
require.NoError(t, err)

// Test with input-dir flag and no sketch
_, _, err = cli.Run(
"upload",
"-b", "arduino:mbed_opta:opta",
"-i", buildDir.String(),
"-t",
"-p", "/dev/ttyACM0",
"--dry-run", "-v")
require.NoError(t, err)
}

0 comments on commit 7b1e354

Please sign in to comment.