Compare commits
No commits in common. "fc85bd7eed7c1bd4e1c73f38710654d0c3b590ce" and "1d67fb694bc1a95487f7f74e9286db1b877ce251" have entirely different histories.
fc85bd7eed
...
1d67fb694b
@ -5,13 +5,11 @@ 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"
|
||||
)
|
||||
@ -22,13 +20,12 @@ var (
|
||||
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.WithValue(ctx, "SessionId", sessionId)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
var eventChannel = make(chan bool)
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
SessionId: sessionId,
|
||||
@ -78,21 +75,6 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
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())
|
||||
@ -101,6 +83,7 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
|
||||
en := lhs.GetEngine()
|
||||
en = en.WithFirst(hl.Init)
|
||||
|
||||
cleanFn := func() {
|
||||
err := en.Finish()
|
||||
if err != nil {
|
||||
@ -115,5 +98,5 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
|
||||
}
|
||||
|
||||
//en = en.WithDebug(nil)
|
||||
return en, cleanFn, eventChannel
|
||||
return en, cleanFn
|
||||
}
|
||||
|
@ -1,12 +1,15 @@
|
||||
//go:build online
|
||||
// +build online
|
||||
|
||||
package testutil
|
||||
|
||||
import "git.grassecon.net/urdt/ussd/internal/handlers/server"
|
||||
const OnlineTestEnabled = true
|
||||
|
||||
|
||||
|
||||
|
||||
var AccountService server.AccountServiceInterface
|
||||
|
||||
|
||||
func init() {
|
||||
AccountService = &server.AccountService{}
|
||||
}
|
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.grassecon.net/urdt/ussd/driver"
|
||||
"git.grassecon.net/urdt/ussd/internal/testutil"
|
||||
@ -54,7 +55,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
func TestAccountCreationSuccessful(t *testing.T) {
|
||||
en, fn, eventChannel := testutil.TestEngine(sessionID)
|
||||
en, fn := testutil.TestEngine(sessionID)
|
||||
defer fn()
|
||||
ctx := context.Background()
|
||||
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) {
|
||||
@ -97,7 +98,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
|
||||
@ -132,7 +133,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
|
||||
@ -173,7 +174,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
|
||||
@ -208,7 +209,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
|
||||
@ -243,7 +244,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
|
||||
@ -278,7 +279,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
|
||||
@ -313,7 +314,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
|
||||
@ -355,7 +356,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