|
| 1 | +package plugin |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestNewGithubPlugin(t *testing.T) { |
| 10 | + testCases := []struct { |
| 11 | + name string |
| 12 | + expected githubPlugin |
| 13 | + }{ |
| 14 | + { |
| 15 | + name: "parse basic github plugin", |
| 16 | + expected: githubPlugin{ |
| 17 | + raw: "jetpack-io/devbox-plugins", |
| 18 | + org: "jetpack-io", |
| 19 | + repo: "devbox-plugins", |
| 20 | + revision: "master", |
| 21 | + }, |
| 22 | + }, |
| 23 | + { |
| 24 | + name: "parse github plugin with dir param", |
| 25 | + expected: githubPlugin{ |
| 26 | + raw: "jetpack-io/devbox-plugins?dir=mongodb", |
| 27 | + org: "jetpack-io", |
| 28 | + repo: "devbox-plugins", |
| 29 | + revision: "master", |
| 30 | + dir: "mongodb", |
| 31 | + }, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "parse github plugin with dir param and rev", |
| 35 | + expected: githubPlugin{ |
| 36 | + raw: "jetpack-io/devbox-plugins/my-branch?dir=mongodb", |
| 37 | + org: "jetpack-io", |
| 38 | + repo: "devbox-plugins", |
| 39 | + revision: "my-branch", |
| 40 | + dir: "mongodb", |
| 41 | + }, |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "parse github plugin with dir param and rev", |
| 45 | + expected: githubPlugin{ |
| 46 | + raw: "jetpack-io/devbox-plugins/initials/my-branch?dir=mongodb", |
| 47 | + org: "jetpack-io", |
| 48 | + repo: "devbox-plugins", |
| 49 | + revision: "initials/my-branch", |
| 50 | + dir: "mongodb", |
| 51 | + }, |
| 52 | + }, |
| 53 | + } |
| 54 | + |
| 55 | + for _, testCase := range testCases { |
| 56 | + t.Run(testCase.name, func(t *testing.T) { |
| 57 | + actual, _ := newGithubPlugin(testCase.expected.raw) |
| 58 | + assert.Equal(t, actual, &testCase.expected) |
| 59 | + }) |
| 60 | + } |
| 61 | +} |
0 commit comments