Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
fixed regex bug on plugin installation match (related to #84)
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed May 20, 2022
1 parent 2c12ef1 commit 7507a2c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/plugins/plugdeps/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// bin, module version, and tag
var re = regexp.MustCompile(`.*(buffalo-[^/]+)/?(v[0-9]+)?@?(.*)?`)
var re = regexp.MustCompile(`.*(buffalo-[^/@]+)/?(v[0-9]+)?@?(.*)?`)

// Plugin represents a Go plugin for Buffalo applications
type Plugin struct {
Expand Down
58 changes: 58 additions & 0 deletions internal/plugins/plugdeps/plugin_test.go
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
package plugdeps

import (
"testing"

"github.com/gobuffalo/meta"
"github.com/stretchr/testify/require"
)

func TestNewPlugin_NoVersionNoTag(t *testing.T) {
r := require.New(t)

p := NewPlugin("example.com/user/buffalo-awesome")
r.Equal("buffalo-awesome", p.key())
r.Equal("buffalo-awesome", p.Binary)
r.Equal("example.com/user/buffalo-awesome@latest", p.GoGet)

r.Equal(meta.BuildTags(nil), p.Tags)
r.Equal(`{"binary":"buffalo-awesome","go_get":"example.com/user/buffalo-awesome@latest"}`, p.String())
}

func TestNewPlugin_BuildTags(t *testing.T) {
r := require.New(t)

p := NewPlugin("example.com/user/buffalo-awesome", meta.BuildTags{"sqlite", "awesome"})
r.Equal("buffalo-awesome", p.key())
r.Equal("buffalo-awesome", p.Binary)
r.Equal("example.com/user/buffalo-awesome@latest", p.GoGet)

r.Equal(meta.BuildTags{"sqlite", "awesome"}, p.Tags)
r.Equal(`{"binary":"buffalo-awesome","go_get":"example.com/user/buffalo-awesome@latest","tags":["sqlite","awesome"]}`, p.String())
}

func TestNewPlugin_NoVersionTag(t *testing.T) {
r := require.New(t)

p := NewPlugin("example.com/user/buffalo-awesome@v3.1")
r.Equal("buffalo-awesome", p.key())
r.Equal("buffalo-awesome", p.Binary)
r.Equal("example.com/user/buffalo-awesome@v3.1", p.GoGet)
}

func TestNewPlugin_VersionNoTag(t *testing.T) {
r := require.New(t)

p := NewPlugin("example.com/user/buffalo-awesome/v3")
r.Equal("buffalo-awesome", p.key())
r.Equal("buffalo-awesome", p.Binary)
r.Equal("example.com/user/buffalo-awesome/v3@latest", p.GoGet)
}

func TestNewPlugin_VersionTag(t *testing.T) {
r := require.New(t)

p := NewPlugin("example.com/user/buffalo-awesome/v3@v3.1")
r.Equal("buffalo-awesome", p.key())
r.Equal("buffalo-awesome", p.Binary)
r.Equal("example.com/user/buffalo-awesome/v3@v3.1", p.GoGet)
}
2 changes: 1 addition & 1 deletion internal/plugins/plugdeps/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (plugs *Plugins) Decode(r io.Reader) error {
tp := &tomlPlugins{
Plugins: []Plugin{},
}
if _, err := toml.DecodeReader(r, tp); err != nil {
if _, err := toml.NewDecoder(r).Decode(tp); err != nil {
return err
}
for _, p := range tp.Plugins {
Expand Down

0 comments on commit 7507a2c

Please sign in to comment.