Compare commits

..

No commits in common. "fc85bd7eed7c1bd4e1c73f38710654d0c3b590ce" and "1d67fb694bc1a95487f7f74e9286db1b877ce251" have entirely different histories.

3 changed files with 23 additions and 36 deletions

View File

@ -5,13 +5,11 @@ import (
"fmt" "fmt"
"os" "os"
"path" "path"
"time"
"git.defalsify.org/vise.git/engine" "git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging" "git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource" "git.defalsify.org/vise.git/resource"
"git.grassecon.net/urdt/ussd/internal/handlers" "git.grassecon.net/urdt/ussd/internal/handlers"
"git.grassecon.net/urdt/ussd/internal/handlers/server"
"git.grassecon.net/urdt/ussd/internal/storage" "git.grassecon.net/urdt/ussd/internal/storage"
testdataloader "github.com/peteole/testdata-loader" testdataloader "github.com/peteole/testdata-loader"
) )
@ -22,13 +20,12 @@ var (
scriptDir = path.Join(baseDir, "services", "registration") scriptDir = path.Join(baseDir, "services", "registration")
) )
func TestEngine(sessionId string) (engine.Engine, func(), chan bool) { func TestEngine(sessionId string) (engine.Engine, func()) {
//var accountService server.AccountServiceInterface
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
pfp := path.Join(scriptDir, "pp.csv") pfp := path.Join(scriptDir, "pp.csv")
var eventChannel = make(chan bool)
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
SessionId: sessionId, SessionId: sessionId,
@ -78,21 +75,6 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
fmt.Fprintf(os.Stderr, err.Error()) fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1) 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) hl, err := lhs.GetHandler(AccountService)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, err.Error()) fmt.Fprintf(os.Stderr, err.Error())
@ -101,6 +83,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
en := lhs.GetEngine() en := lhs.GetEngine()
en = en.WithFirst(hl.Init) en = en.WithFirst(hl.Init)
cleanFn := func() { cleanFn := func() {
err := en.Finish() err := en.Finish()
if err != nil { if err != nil {
@ -115,5 +98,5 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
} }
//en = en.WithDebug(nil) //en = en.WithDebug(nil)
return en, cleanFn, eventChannel return en, cleanFn
} }

View File

@ -1,12 +1,15 @@
//go:build online
// +build online // +build online
package testutil package testutil
import "git.grassecon.net/urdt/ussd/internal/handlers/server" const OnlineTestEnabled = true
var AccountService server.AccountServiceInterface var AccountService server.AccountServiceInterface
func init() { func init() {
AccountService = &server.AccountService{} AccountService = &server.AccountService{}
} }

View File

@ -8,6 +8,7 @@ import (
"os" "os"
"regexp" "regexp"
"testing" "testing"
"time"
"git.grassecon.net/urdt/ussd/driver" "git.grassecon.net/urdt/ussd/driver"
"git.grassecon.net/urdt/ussd/internal/testutil" "git.grassecon.net/urdt/ussd/internal/testutil"
@ -54,7 +55,7 @@ func TestMain(m *testing.M) {
} }
func TestAccountCreationSuccessful(t *testing.T) { func TestAccountCreationSuccessful(t *testing.T) {
en, fn, eventChannel := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -85,8 +86,8 @@ func TestAccountCreationSuccessful(t *testing.T) {
} }
} }
} }
<-eventChannel // Adding a sleep after the test to wait for registration to complete the process
time.Sleep(5 * time.Second)
} }
func TestAccountRegistrationRejectTerms(t *testing.T) { func TestAccountRegistrationRejectTerms(t *testing.T) {
@ -97,7 +98,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
t.Fail() t.Fail()
} }
edgeCaseSessionID := v.String() edgeCaseSessionID := v.String()
en, fn, _ := testutil.TestEngine(edgeCaseSessionID) en, fn := testutil.TestEngine(edgeCaseSessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -132,7 +133,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
} }
func TestSendWithInvalidInputs(t *testing.T) { func TestSendWithInvalidInputs(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -173,7 +174,7 @@ func TestSendWithInvalidInputs(t *testing.T) {
} }
func TestMyAccount_Check_My_Balance(t *testing.T) { func TestMyAccount_Check_My_Balance(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -208,7 +209,7 @@ func TestMyAccount_Check_My_Balance(t *testing.T) {
} }
func TestMainMenuHelp(t *testing.T) { func TestMainMenuHelp(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -243,7 +244,7 @@ func TestMainMenuHelp(t *testing.T) {
} }
func TestMainMenuQuit(t *testing.T) { func TestMainMenuQuit(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -278,7 +279,7 @@ func TestMainMenuQuit(t *testing.T) {
} }
func TestMyAccount_Check_Community_Balance(t *testing.T) { func TestMyAccount_Check_Community_Balance(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -313,7 +314,7 @@ func TestMyAccount_Check_Community_Balance(t *testing.T) {
} }
func TestMyAccount_MyAddress(t *testing.T) { func TestMyAccount_MyAddress(t *testing.T) {
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
sessions := testData sessions := testData
@ -355,7 +356,7 @@ func TestGroups(t *testing.T) {
if err != nil { if err != nil {
log.Fatalf("Failed to load test groups: %v", err) log.Fatalf("Failed to load test groups: %v", err)
} }
en, fn, _ := testutil.TestEngine(sessionID) en, fn := testutil.TestEngine(sessionID)
defer fn() defer fn()
ctx := context.Background() ctx := context.Background()
// Create test cases from loaded groups // Create test cases from loaded groups