Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first round of tests for plugin * missing yaml should be malformed yaml, implement that test * fix malformed plugin test and add test for loading multiple plugins of different types * add parallel testdata for windows due to the different folder layout and modify the tests to take that into account * remove windows specific test file * Change require.NotEmpty to assert.Equal(1, ...) * Move all test data into `testdata` and fix plugin tests to point to the new place.
- Loading branch information
Showing
30 changed files
with
258 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package plugin_test | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus/hooks/test" | ||
"github.com/spf13/afero" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/dcos/dcos-cli/pkg/plugin" | ||
) | ||
|
||
func TestLoadNoPlugin(t *testing.T) { | ||
subcommandsDir := targetSubcommandDir(t, "no_plugins") | ||
|
||
m := plugin.Manager{ | ||
Fs: afero.NewMemMapFs(), | ||
Dir: subcommandsDir, | ||
} | ||
|
||
plugins := m.Plugins() | ||
require.Empty(t, plugins) | ||
} | ||
|
||
func TestLoadNewPlugin(t *testing.T) { | ||
subcommandsDir := targetSubcommandDir(t, "only_new_plugin") | ||
logger, _ := test.NewNullLogger() | ||
|
||
m := plugin.Manager{ | ||
Fs: roFs(), | ||
Dir: subcommandsDir, | ||
Logger: logger, | ||
} | ||
|
||
plugins := m.Plugins() | ||
assert.Equal(t, 1, len(plugins)) | ||
plugin := plugins[0] | ||
|
||
assert.Equal(t, "new-test", plugin.Name) | ||
} | ||
|
||
func TestLoadOldPlugin(t *testing.T) { | ||
subcommandsDir := targetSubcommandDir(t, "only_old_plugin") | ||
|
||
logger, _ := test.NewNullLogger() | ||
|
||
m := plugin.Manager{ | ||
Fs: roFs(), | ||
Dir: subcommandsDir, | ||
Logger: logger, | ||
} | ||
|
||
plugins := m.Plugins() | ||
assert.Equal(t, 1, len(plugins)) | ||
|
||
plugin := plugins[0] | ||
|
||
assert.Equal(t, "old-test", plugin.Name, "plugin name does not match name found in package.json") | ||
|
||
pluginExists, err := afero.Exists(m.Fs, filepath.Join(subcommandsDir, "old", "env", "plugin.yaml")) | ||
require.NoError(t, err) | ||
|
||
assert.True(t, pluginExists, "plugin.yaml was not created") | ||
} | ||
|
||
func TestIgnoreMalformedYaml(t *testing.T) { | ||
dir := targetSubcommandDir(t, "malformed_yaml") | ||
logger, _ := test.NewNullLogger() | ||
|
||
m := plugin.Manager{ | ||
Fs: roFs(), | ||
Dir: dir, | ||
Logger: logger, | ||
} | ||
plugins := m.Plugins() | ||
|
||
assert.Empty(t, plugins) | ||
} | ||
|
||
func TestLoadingMultiple(t *testing.T) { | ||
dir := targetSubcommandDir(t, "correct_and_malformed") | ||
logger, _ := test.NewNullLogger() | ||
|
||
m := plugin.Manager{ | ||
Fs: roFs(), | ||
Dir: dir, | ||
Logger: logger, | ||
} | ||
|
||
plugins := m.Plugins() | ||
// 3 directories, one new plugin, one old, and one malformed | ||
// malformed should be ignored, leaving 2 loaded plugins | ||
assert.Equal(t, 2, len(plugins)) | ||
} | ||
|
||
func targetSubcommandDir(t *testing.T, name string) string { | ||
wd, err := os.Getwd() | ||
require.NoError(t, err) | ||
|
||
var testdataDir string | ||
if runtime.GOOS == "windows" { | ||
testdataDir = filepath.Join(wd, "testdata", "windows") | ||
} else { | ||
testdataDir = filepath.Join(wd, "testdata", "unix") | ||
} | ||
return filepath.Join(testdataDir, name) | ||
} | ||
|
||
func roFs() afero.Fs { | ||
base := afero.NewOsFs() | ||
roBase := afero.NewReadOnlyFs(base) | ||
overlay := afero.NewCopyOnWriteFs(roBase, afero.NewMemMapFs()) | ||
|
||
return overlay | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# env is ignored in the root gitignore, this resets that so the testdata can be tracked | ||
!env/ |
Empty file.
1 change: 1 addition & 0 deletions
1
pkg/plugin/testdata/unix/correct_and_malformed/malformed/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
not valid yaml |
Empty file.
2 changes: 2 additions & 0 deletions
2
pkg/plugin/testdata/unix/correct_and_malformed/new/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: new-test | ||
description: plugin test with the new schema |
Empty file.
5 changes: 5 additions & 0 deletions
5
pkg/plugin/testdata/unix/correct_and_malformed/old/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "old-test", | ||
"description": "barebones old style plugin", | ||
"version": "0.0.1" | ||
} |
Empty file.
1 change: 1 addition & 0 deletions
1
pkg/plugin/testdata/unix/malformed_yaml/malformed/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
not valid yaml |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: new-test | ||
description: plugin test with the new schema |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "old-test", | ||
"description": "barebones old style plugin", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# env is ignored in the root gitignore, this resets that so the testdata can be tracked | ||
!env/ |
Empty file.
1 change: 1 addition & 0 deletions
1
pkg/plugin/testdata/windows/correct_and_malformed/malformed/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
not valid yaml |
Empty file.
2 changes: 2 additions & 0 deletions
2
pkg/plugin/testdata/windows/correct_and_malformed/new/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: new-test | ||
description: plugin test with the new schema |
Empty file.
5 changes: 5 additions & 0 deletions
5
pkg/plugin/testdata/windows/correct_and_malformed/old/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "old-test", | ||
"description": "barebones old style plugin", | ||
"version": "0.0.1" | ||
} |
Empty file.
1 change: 1 addition & 0 deletions
1
pkg/plugin/testdata/windows/malformed_yaml/malformed/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
not valid yaml |
Empty file.
2 changes: 2 additions & 0 deletions
2
pkg/plugin/testdata/windows/only_new_plugin/new/env/plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name: new-test | ||
description: plugin test with the new schema |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "old-test", | ||
"description": "barebones old style plugin", | ||
"version": "0.0.1" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.