13
13
// You should have received a copy of the GNU Affero General Public License
14
14
// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
15
16
- package upload_test
16
+ package upload
17
17
18
18
import (
19
19
"log"
20
20
"strings"
21
21
"testing"
22
22
23
- "github.com/arduino/arduino-create-agent/upload"
24
23
homedir "github.com/mitchellh/go-homedir"
25
24
"github.com/sirupsen/logrus"
26
25
)
@@ -36,11 +35,11 @@ var TestSerialData = []struct {
36
35
Name string
37
36
Port string
38
37
Commandline string
39
- Extra upload. Extra
38
+ Extra Extra
40
39
}{
41
40
{
42
41
"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 }},
44
43
}
45
44
46
45
func TestSerial (t * testing.T ) {
@@ -51,7 +50,7 @@ func TestSerial(t *testing.T) {
51
50
52
51
for _ , test := range TestSerialData {
53
52
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 )
55
54
log .Println (err )
56
55
}
57
56
}
@@ -60,18 +59,58 @@ var TestResolveData = []struct {
60
59
Board string
61
60
File string
62
61
PlatformPath string
63
- Commandline string
64
- Extra upload. Extra
62
+ CommandLine string
63
+ Extra Extra
65
64
Result string
66
65
}{
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
+ },
70
82
}
71
83
72
84
func TestResolve (t * testing.T ) {
73
85
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 )
75
114
if result != test .Result {
76
115
t .Error ("expected " + test .Result + ", got " + result )
77
116
continue
0 commit comments