Files
streambot_twitch/internal/tests/startup_checks.go
bryce d6c77a3c93 Impliment StartupTesting and started OAuth Server
Testing for IRC & Channels connection for debugging
OAuth Server (because it's better to roll my own for this)
internal/auth/oauth.go
tests/startup_checks.go

More tests to come for debugging

Plan to impliment Logging in internal/stoage/logs for internal & UI
debugging
2025-07-08 19:46:24 +12:00

53 lines
1.1 KiB
Go

package tests
import (
"context"
"fmt"
"log"
"time"
twitch "github.com/gempir/go-twitch-irc/v4"
twitchapi "streambot_twitch/internal/twitchapi"
)
// check Twitch API connectivity
func TestTwitchAPI(client *twitchapi.Client, streamerChannel string) error {
_, err := client.GetUserID(streamerChannel)
if err != nil {
return fmt.Errorf("Twitch API test failed: %w", err)
}
log.Println("Twitch API connection successful")
return nil
}
// check IRC connection to channels
func TestIRCConnection(botClient *twitch.Client, channels []string) error {
ctx, channel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
connected := make(chan struct{})
botClient.OnConnect(func() {
log.Println("IRC connected successfully")
close(connected)
})
for _, ch := range channels {
botClient.Join(ch)
}
go func() {
if err := botClient.Connect(); err != nil {
log.Printf("IRC connection error: %v", err)
}
}()
select{
case <-connected:
log.Println("IRC connecton test successful")
return nil
case <-ctx.Done():
return fmt.Errorf("IRC connection test timed out")
}
}