diff --git a/README.md b/README.md index 5514cfe..be37f46 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ To use this template, fork it and change the module name in `go.mod`. Then you can modify the source in `src/plugin.go` to create your plugin. +A couple of test cases should also be added in `src/plugin_test.go`, view [vib-fsguard](https://github.com/vanilla-os/vib) and [vib-pacman](https://github.com/axtloss/vib-plugins/blob/main/pacman/plugin_test.go) for examples. + We recommend adding the `vib-plugin` tag to your repo so other people can discover it. ## Plugin requirements diff --git a/plugin_test.go b/plugin_test.go new file mode 100644 index 0000000..cffaafc --- /dev/null +++ b/plugin_test.go @@ -0,0 +1,34 @@ +package main + +import ( + "encoding/json" + "testing" + + "github.com/vanilla-os/vib/api" +) + +type testCases struct { + module interface{} + expected string +} + +// This slice is most likely the only thing that needs to be modified +// It should be filled with the cases that the function should run through +// it consists of the module that should be passed and the output that should result from the module +var test = []testCases{ + {ExampleModule{Name: "Case Descrition", Type: "PluginName", Source: api.Source{Type: "tar"}}, "expected result here"}, +} + +// Simply run through all the test cases defined above +func TestBuildModule(t *testing.T) { + for _, testCase := range test { + moduleInterface, err := json.Marshal(testCase.module) + if err != nil { + t.Errorf("Error in json %s", err.Error()) + } + if output := BuildModule(convertToCString(string(moduleInterface)), convertToCString("")); convertToGoString(output) != testCase.expected { + t.Errorf("Output %s not equivalent to expected %s", convertToGoString(output), testCase.expected) + } + } + +}