1313// You should have received a copy of the GNU Affero General Public License
1414// along with this program. If not, see <https://www.gnu.org/licenses/>.
1515
16- package upload_test
16+ package upload
1717
1818import (
1919 "log"
2020 "strings"
2121 "testing"
2222
23- "github.com/arduino/arduino-create-agent/upload"
2423 homedir "github.com/mitchellh/go-homedir"
2524 "github.com/sirupsen/logrus"
2625)
@@ -36,11 +35,11 @@ var TestSerialData = []struct {
3635 Name string
3736 Port string
3837 Commandline string
39- Extra upload. Extra
38+ Extra Extra
4039}{
4140 {
4241 "leonardo" , "/dev/ttyACM0" ,
43- `"$HOME/.arduino-create/avrdude/6.3.0-arduino6/bin/avrdude" "-C$HOME/.arduino-create/avrdude/6.3.0-arduino6/etc/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"` , upload. Extra {Use1200bpsTouch : true , WaitForUploadPort : true }},
42+ `"$HOME/.arduino-create/avrdude/6.3.0-arduino6/bin/avrdude" "-C$HOME/.arduino-create/avrdude/6.3.0-arduino6/etc/avrdude.conf" -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"` , Extra {Use1200bpsTouch : true , WaitForUploadPort : true }},
4443}
4544
4645func TestSerial (t * testing.T ) {
@@ -51,7 +50,7 @@ func TestSerial(t *testing.T) {
5150
5251 for _ , test := range TestSerialData {
5352 commandline := strings .Replace (test .Commandline , "$HOME" , home , - 1 )
54- err := upload . Serial (test .Port , commandline , test .Extra , logger )
53+ err := Serial (test .Port , commandline , test .Extra , logger )
5554 log .Println (err )
5655 }
5756}
@@ -60,18 +59,58 @@ var TestResolveData = []struct {
6059 Board string
6160 File string
6261 PlatformPath string
63- Commandline string
64- Extra upload. Extra
62+ CommandLine string
63+ Extra Extra
6564 Result string
6665}{
67- {"arduino:avr:leonardo" , "./upload_test.hex" , "" ,
68- `"{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v {upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"` , upload.Extra {Use1200bpsTouch : true , WaitForUploadPort : true },
69- `"$loc$loc{runtime.tools.avrdude.path}/bin/avrdude" "-C{runtime.tools.avrdude.path}/etc/avrdude.conf" -v $loc{upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:./upload_test.hex:i"` },
66+ {
67+ Board : "arduino:avr:leonardo" ,
68+ File : "./upload_test.hex" ,
69+ PlatformPath : "" ,
70+ CommandLine : `{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"` ,
71+ Extra : Extra {Use1200bpsTouch : true , WaitForUploadPort : true },
72+ Result : `$loc$loc{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v $loc{upload.verify} -patmega32u4 -cavr109 -P$loc{serial.port} -b57600 -D "-Uflash:w:./upload_test.hex:i"` ,
73+ },
74+ {
75+ Board : "arduino:renesas_uno:unor4wifi" ,
76+ File : "UpdateFirmware.bin" ,
77+ PlatformPath : "" ,
78+ CommandLine : `{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a {serial.port} -b {fqbn} -v --retries 5"` ,
79+ Extra : Extra {Use1200bpsTouch : true , WaitForUploadPort : true },
80+ Result : `$loc{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a $loc{serial.port} -b arduino:renesas_uno:unor4wifi -v --retries 5"` ,
81+ },
7082}
7183
7284func TestResolve (t * testing.T ) {
7385 for _ , test := range TestResolveData {
74- result , _ := upload .PartiallyResolve (test .Board , test .File , test .PlatformPath , test .Commandline , test .Extra , mockTools {})
86+ result , _ := PartiallyResolve (test .Board , test .File , test .PlatformPath , test .CommandLine , test .Extra , mockTools {})
87+ if result != test .Result {
88+ t .Error ("expected " + test .Result + ", got " + result )
89+ continue
90+ }
91+ }
92+ }
93+
94+ var TestFixupData = []struct {
95+ Port string
96+ CommandLine string
97+ Result string
98+ }{
99+ {
100+ Port : "/dev/ttyACM0" ,
101+ CommandLine : `{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P{serial.port} -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"` ,
102+ Result : `{runtime.tools.avrdude.path}/bin/avrdude -C{runtime.tools.avrdude.path}/etc/avrdude.conf -v {upload.verify} -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"` ,
103+ },
104+ {
105+ Port : "/dev/cu.usbmodemDC5475C5557C2" ,
106+ CommandLine : `{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a {serial.port} -b arduino:renesas_uno:unor4wifi -v --retries 5"` ,
107+ Result : `{runtime.tools.arduino-fwuploader.path}/arduino-fwuploader firmware flash -a /dev/cu.usbmodemDC5475C5557C2 -b arduino:renesas_uno:unor4wifi -v --retries 5"` ,
108+ },
109+ }
110+
111+ func TestFixupPort (t * testing.T ) {
112+ for _ , test := range TestFixupData {
113+ result := fixupPort (test .Port , test .CommandLine )
75114 if result != test .Result {
76115 t .Error ("expected " + test .Result + ", got " + result )
77116 continue
0 commit comments