Skip to content
Snippets Groups Projects
Commit cd960e41 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

Resolve "Running the test suite creates plugins which prevent running the test suite again"


See merge request !330

Co-authored-by: default avatarAndre Sterba <andre.sterba@stud.h-da.de>
parent 42d13422
Branches
Tags
2 merge requests!330Resolve "Running the test suite creates plugins which prevent running the test suite again",!264WIP: Develop
Pipeline #104506 passed
...@@ -2,8 +2,12 @@ package nucleus ...@@ -2,8 +2,12 @@ package nucleus
import ( import (
"context" "context"
"io/fs"
"io/ioutil"
"os" "os"
"path/filepath"
"testing" "testing"
"time"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device" "code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
"code.fbi.h-da.de/danet/gosdn/controller/store" "code.fbi.h-da.de/danet/gosdn/controller/store"
...@@ -166,3 +170,42 @@ func newPnd() pndImplementation { ...@@ -166,3 +170,42 @@ func newPnd() pndImplementation {
Id: defaultPndID, Id: defaultPndID,
} }
} }
// removeTestPlugins removes the plugins created during running the test in the current directory based on their name consisting of a uuid
// and the time since they`ve been created
func removeTestPlugins() {
currentDirectory := "./"
// pattern to match plugin uuid used as dir name
pattern := "*-*-*-*-*"
// max time passed since creation in seconds
var seconds int64 = 10
// get all available files
dirs, err := ioutil.ReadDir(currentDirectory)
if err != nil {
log.Info(err)
}
for _, dir := range dirs {
if !dir.IsDir() {
continue
} else if found, _ := filepath.Match(pattern, dir.Name()); found && isDirYoungerThanSeconds(dir.Name(), seconds) {
log.Infof("removing: %v", dir.Name())
err = os.RemoveAll(dir.Name())
if err != nil {
log.Info(err)
}
}
}
}
// isDirYoungerThanSeconds returns true if the provided dir is younger than the given amount in seconds
// and therefore was created as part of the test suite
func isDirYoungerThanSeconds(dirName string, seconds int64) bool {
fileInfo, err := os.Stat(dirName)
if err != nil {
log.Info(err)
}
return fs.FileInfo.ModTime(fileInfo).Unix() > (time.Now().Unix() - seconds)
}
...@@ -1095,6 +1095,8 @@ func Test_pndImplementation_ConfirmedChanges(t *testing.T) { ...@@ -1095,6 +1095,8 @@ func Test_pndImplementation_ConfirmedChanges(t *testing.T) {
} }
func Test_pndImplementation_saveGoStructsToFile(t *testing.T) { func Test_pndImplementation_saveGoStructsToFile(t *testing.T) {
defer removeTestPlugins()
type genericGoStructClientArg struct { type genericGoStructClientArg struct {
fn string fn string
rtrn []interface{} rtrn []interface{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment