Skip to content

Commit

Permalink
feat: add example test unit
Browse files Browse the repository at this point in the history
  • Loading branch information
axtloss committed Apr 25, 2024
1 parent d19c2a5 commit faa80fa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

}

0 comments on commit faa80fa

Please sign in to comment.