Skip to content

Commit 4a73a8e

Browse files
committed
Navigate returns the default configuration
1 parent f5d7eae commit 4a73a8e

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

configs/navigate.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package configs
22

3+
import (
4+
paths "github.com/arduino/go-paths-helper"
5+
homedir "github.com/mitchellh/go-homedir"
6+
)
7+
38
func Navigate(root, pwd string) Configuration {
4-
return Configuration{}
9+
home, err := homedir.Dir()
10+
if err != nil {
11+
panic(err) // Should never happen
12+
}
13+
14+
return Configuration{
15+
SketchbookDir: paths.New(home, "Arduino"),
16+
DataDir: paths.New(home, ".arduino15"),
17+
}
518
}

configs/navigate_test.go

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
package configs_test
22

33
import (
4-
"reflect"
4+
"io/ioutil"
5+
"path/filepath"
6+
"strings"
57
"testing"
8+
9+
"github.com/arduino/arduino-cli/configs"
10+
homedir "github.com/mitchellh/go-homedir"
11+
"github.com/sergi/go-diff/diffmatchpatch"
612
)
713

814
func TestNavigate(t *testing.T) {
9-
type args struct {
10-
root string
11-
pwd string
12-
}
13-
tests := []struct {
14-
name string
15-
args args
16-
want Configuration
17-
}{
18-
// TODO: Add test cases.
15+
tests := []string{
16+
"noconfig",
1917
}
2018
for _, tt := range tests {
21-
t.Run(tt.name, func(t *testing.T) {
22-
if got := Navigate(tt.args.root, tt.args.pwd); !reflect.DeepEqual(got, tt.want) {
23-
t.Errorf("Navigate() = %v, want %v", got, tt.want)
24-
}
19+
t.Run(tt, func(t *testing.T) {
20+
root := filepath.Join("testdata", "navigate", tt)
21+
pwd := filepath.Join("testdata", "navigate", tt, "first", "second")
22+
golden := filepath.Join("testdata", "navigate", tt, "golden.yaml")
23+
24+
got := configs.Navigate(root, pwd)
25+
data, _ := got.SerializeToYAML()
26+
27+
diff(t, data, golden)
2528
})
2629
}
2730
}
31+
32+
func diff(t *testing.T, data []byte, goldenFile string) {
33+
golden, err := ioutil.ReadFile(goldenFile)
34+
if err != nil {
35+
t.Error(err)
36+
return
37+
}
38+
39+
dataStr := strings.TrimSpace(string(data))
40+
goldenStr := strings.TrimSpace(string(golden))
41+
42+
// Substitute home folder
43+
homedir, _ := homedir.Dir()
44+
dataStr = strings.Replace(dataStr, homedir, "$HOME", -1)
45+
46+
if dataStr != goldenStr {
47+
dmp := diffmatchpatch.New()
48+
diffs := dmp.DiffMain(goldenStr, dataStr, false)
49+
t.Errorf(dmp.DiffPrettyText(diffs))
50+
}
51+
}

configs/testdata/navigate/noconfig/first/second/.gitkeep

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
proxy_type: ""
2+
sketchbook_path: $HOME/Arduino
3+
arduino_data: $HOME/.arduino15
4+
board_manager: null

0 commit comments

Comments
 (0)