Skip to content
Snippets Groups Projects

Resolve "Containerised Southbound Interfaces and the corresponding device config representation within the controller"

4 files
+ 172292
1
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 82
0
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) {
}
Loading