Skip to content
Snippets Groups Projects
Commit 9e247cdd authored by Malte Bauch's avatar Malte Bauch
Browse files

add test for BuildPlugin()

parent 06135b81
No related branches found
No related tags found
1 merge request!230Resolve "Containerised Southbound Interfaces and the corresponding device config representation within the controller"
Pipeline #95796 passed
This commit is part of merge request !230. Comments created here will be created in the context of that merge request.
...@@ -21,6 +21,7 @@ debug.test ...@@ -21,6 +21,7 @@ debug.test
# test files # test files
report.xml report.xml
test/plugin/plugin.so
# Binary # Binary
gosdn gosdn
......
...@@ -8,6 +8,7 @@ require ( ...@@ -8,6 +8,7 @@ require (
code.fbi.h-da.de/danet/forks/google v0.0.0-20210709163519-47ee8958ef40 code.fbi.h-da.de/danet/forks/google v0.0.0-20210709163519-47ee8958ef40
code.fbi.h-da.de/danet/yang-models v0.1.0 code.fbi.h-da.de/danet/yang-models v0.1.0
github.com/docker/docker v20.10.11+incompatible github.com/docker/docker v20.10.11+incompatible
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.2.0 github.com/google/uuid v1.2.0
github.com/openconfig/gnmi v0.0.0-20210914185457-51254b657b7d github.com/openconfig/gnmi v0.0.0-20210914185457-51254b657b7d
github.com/openconfig/goyang v0.3.1 github.com/openconfig/goyang v0.3.1
...@@ -29,7 +30,6 @@ require ( ...@@ -29,7 +30,6 @@ require (
github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/golang/glog v1.0.0 // indirect github.com/golang/glog v1.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect
......
package nucleus
import (
"crypto/md5"
"io"
"os"
"path/filepath"
"testing"
"github.com/google/go-cmp/cmp"
)
func generateHash(path, fileName string) (string, error) {
fp := filepath.Join("..", path, fileName)
f, err := os.Open(fp)
if err != nil {
return "", err
}
defer f.Close()
h := md5.New()
if _, err := io.Copy(h, f); err != nil {
return "", err
}
return string(h.Sum(nil)), nil
}
func TestBuildPlugin(t *testing.T) {
type args struct {
path, goStructName, pluginName string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{
name: "build success",
args: args{
path: "test/plugin",
goStructName: "gostructs.go",
pluginName: "plugin.so",
},
want: "874c9f3d36f9cba5eb03c1e48b3ccc33",
wantErr: false,
},
{
name: "fail: file does not exist",
args: args{
path: "test/plugin",
goStructName: "doesNotExist.go",
},
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := BuildPlugin(tt.args.path, tt.args.goStructName)
if (err != nil) != tt.wantErr {
t.Errorf("BuildPlugin() error = %v, wantErr %v", err, tt.wantErr)
return
}
hash, err := generateHash(tt.args.path, tt.args.pluginName)
if err != nil {
if tt.name != "fail: file does not exist" {
t.Errorf("BuildPlugin() error = %v", err)
return
}
}
cmp.Equal(hash, tt.want)
os.Remove(filepath.Join("..", tt.args.path, tt.args.pluginName))
})
}
}
func TestLoadPlugin(t *testing.T) {
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment