Skip to content

Commit

Permalink
ignore casing in vs code extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Steinke committed May 26, 2021
1 parent 5d147fb commit 108aa89
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 16 deletions.
12 changes: 5 additions & 7 deletions internal/vscode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (
"github.com/sirupsen/logrus"
)

var (
vscodeExe = "code"
)
var vscodeExe = "code"

// VSCode holds the information to automatically install VSCode extensions.
type VSCode struct {
Extensions []string
Commander Commander
Extensions []string
Commander Commander
}

// GetMissingPackages returns a list of VSCode extensions which are configured
Expand All @@ -24,15 +22,15 @@ func (v VSCode) GetMissingPackages() ([]string, error) {
return nil, err
}
logrus.WithField("output", string(stdout)).Debug("homebrew stdout")
installedBottles := strings.Split(string(stdout), "\n")
installedBottles := strings.Split(strings.ToLower(string(stdout)), "\n")
installedMap := map[string]bool{}
for _, p := range installedBottles {
installedMap[p] = true
}

missingBottles := []string{}
for _, bottle := range v.Extensions {
if ok := installedMap[bottle]; !ok {
if ok := installedMap[strings.ToLower(bottle)]; !ok {
missingBottles = append(missingBottles, bottle)
}
}
Expand Down
53 changes: 44 additions & 9 deletions internal/vscode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,51 @@ import (
)

func TestGetMissingVSCodeExtension(t *testing.T) {
commander := mockCommander{}
defer commander.AssertExpectations(t)
commander.ExpectOutput("code", []string{"--list-extensions"}, []byte("bar"), nil)
b := VSCode{
Extensions: []string{"bar", "foo"},
Commander: commander.Output,
testCases := []struct {
name string
input []string
applicationOutput []byte
expected []string
}{
{
name: "normal case",
input: []string{"bar", "foo"},
applicationOutput: []byte("bar"),
expected: []string{"foo"},
},
{
name: "multiple in output",
input: []string{"bar", "foo"},
applicationOutput: []byte("bar\nbaz"),
expected: []string{"foo"},
},
{
name: "upper-case in input",
input: []string{"Bar", "foo"},
applicationOutput: []byte("bar"),
expected: []string{"foo"},
},
{
name: "upper-case in output",
input: []string{"bar", "foo"},
applicationOutput: []byte("Bar"),
expected: []string{"foo"},
},
}

for _, testCase := range testCases {

commander := mockCommander{}
defer commander.AssertExpectations(t)
commander.ExpectOutput("code", []string{"--list-extensions"}, testCase.applicationOutput, nil)
b := VSCode{
Extensions: testCase.input,
Commander: commander.Output,
}
missingPackages, err := b.GetMissingPackages()
assert.NoError(t, err)
assert.Equal(t, testCase.expected, missingPackages, testCase.name)
}
missingPackages, err := b.GetMissingPackages()
assert.NoError(t, err)
assert.Equal(t, []string{"foo"}, missingPackages)
}

func TestInstallingVSCodeExtension(t *testing.T) {
Expand Down

0 comments on commit 108aa89

Please sign in to comment.