return an event channel for the test engine
This commit is contained in:
parent
5869324c16
commit
fc85bd7eed
@ -5,11 +5,13 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||
"git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
)
|
||||
@ -20,12 +22,13 @@ var (
|
||||
scriptDir = path.Join(baseDir, "services", "registration")
|
||||
)
|
||||
|
||||
func TestEngine(sessionId string) (engine.Engine, func()) {
|
||||
//var accountService server.AccountServiceInterface
|
||||
func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
var eventChannel = make(chan bool)
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
SessionId: sessionId,
|
||||
@ -75,6 +78,21 @@ func TestEngine(sessionId string) (engine.Engine, func()) {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch AccountService.(type) {
|
||||
case *server.MockAccountService:
|
||||
go func() {
|
||||
eventChannel <- false
|
||||
}()
|
||||
case *server.AccountService:
|
||||
go func() {
|
||||
time.Sleep(5 * time.Second) // Wait for 5 seconds
|
||||
eventChannel <- true
|
||||
}()
|
||||
default:
|
||||
panic("Unknown account service type")
|
||||
}
|
||||
|
||||
hl, err := lhs.GetHandler(AccountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
@ -83,7 +101,6 @@ func TestEngine(sessionId string) (engine.Engine, func()) {
|
||||
|
||||
en := lhs.GetEngine()
|
||||
en = en.WithFirst(hl.Init)
|
||||
|
||||
cleanFn := func() {
|
||||
err := en.Finish()
|
||||
if err != nil {
|
||||
@ -98,5 +115,5 @@ func TestEngine(sessionId string) (engine.Engine, func()) {
|
||||
}
|
||||
|
||||
//en = en.WithDebug(nil)
|
||||
return en, cleanFn
|
||||
return en, cleanFn, eventChannel
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/driver"
|
||||
"git.grassecon.net/urdt/ussd/internal/testutil"
|
||||
@ -55,7 +54,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestAccountCreationSuccessful(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, eventChannel := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -86,8 +85,8 @@ func TestAccountCreationSuccessful(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Adding a sleep after the test to wait for registration to complete the process
|
||||
time.Sleep(5 * time.Second)
|
||||
<-eventChannel
|
||||
|
||||
}
|
||||
|
||||
func TestAccountRegistrationRejectTerms(t *testing.T) {
|
||||
@ -98,7 +97,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
||||
t.Fail()
|
||||
}
|
||||
edgeCaseSessionID := v.String()
|
||||
en, fn := testutil.TestEngine(edgeCaseSessionID)
|
||||
en, fn, _ := testutil.TestEngine(edgeCaseSessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -133,7 +132,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSendWithInvalidInputs(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -174,7 +173,7 @@ func TestSendWithInvalidInputs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMyAccount_Check_My_Balance(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -209,7 +208,7 @@ func TestMyAccount_Check_My_Balance(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMainMenuHelp(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -244,7 +243,7 @@ func TestMainMenuHelp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMainMenuQuit(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -279,7 +278,7 @@ func TestMainMenuQuit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -314,7 +313,7 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMyAccount_MyAddress(t *testing.T) {
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
sessions := testData
|
||||
@ -356,7 +355,7 @@ func TestGroups(t *testing.T) {
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load test groups: %v", err)
|
||||
}
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
en, fn, _ := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
// Create test cases from loaded groups
|
||||
|
Loading…
Reference in New Issue
Block a user