f-21: test: add test for agent dispatcher
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
712692d414
commit
ba2f8080be
4 changed files with 325 additions and 0 deletions
63
internal/dispatcher/agent/dispatcher_test.go
Normal file
63
internal/dispatcher/agent/dispatcher_test.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package dispatcher
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
func TestDispatcher_Prepare_Success(t *testing.T) {
|
||||
d, _ := newTestDispatcher(t)
|
||||
cmd := mockCmd{
|
||||
prepareFn: func(*badger.DB, *configuration.Config) error { return nil },
|
||||
executeFn: func(*badger.DB, *configuration.Config) error { return nil },
|
||||
}
|
||||
if err := d.Prepare(cmd); err != nil {
|
||||
t.Errorf("Prepare devrait retourner nil, obtenu : %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcher_Prepare_PropagatesError(t *testing.T) {
|
||||
d, _ := newTestDispatcher(t)
|
||||
want := errors.New("prepare failed")
|
||||
cmd := mockCmd{
|
||||
prepareFn: func(*badger.DB, *configuration.Config) error { return want },
|
||||
executeFn: func(*badger.DB, *configuration.Config) error { return nil },
|
||||
}
|
||||
if err := d.Prepare(cmd); !errors.Is(err, want) {
|
||||
t.Errorf("attendu %v, obtenu %v", want, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatcher_Dispatch_ExecutesCommand(t *testing.T) {
|
||||
d, _ := newTestDispatcher(t)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
cmd := mockCmd{
|
||||
prepareFn: func(*badger.DB, *configuration.Config) error { return nil },
|
||||
executeFn: func(*badger.DB, *configuration.Config) error {
|
||||
wg.Done()
|
||||
return nil
|
||||
},
|
||||
}
|
||||
d.Dispatch(cmd)
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestDispatcher_Dispatch_ExecuteErrorLogged(t *testing.T) {
|
||||
d, _ := newTestDispatcher(t)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
cmd := mockCmd{
|
||||
prepareFn: func(*badger.DB, *configuration.Config) error { return nil },
|
||||
executeFn: func(*badger.DB, *configuration.Config) error {
|
||||
defer wg.Done()
|
||||
return errors.New("execute failed")
|
||||
},
|
||||
}
|
||||
d.Dispatch(cmd)
|
||||
wg.Wait() // Execute s'est terminé — l'erreur est loggée, pas propagée
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue