main test

main
Bel LaPointe 2025-04-24 21:14:37 -06:00
parent d14d73bf91
commit 36f8efd0e7
2 changed files with 12 additions and 13 deletions

12
main.go
View File

@ -8,10 +8,14 @@ import (
)
func main() {
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
defer can()
if err := cmd.Main(ctx); err != nil {
if err := Main(context.Background()); err != nil {
panic(err)
}
}
func Main(ctx context.Context) error {
ctx, can := signal.NotifyContext(ctx, syscall.SIGINT)
defer can()
return cmd.Main(ctx)
}

View File

@ -2,21 +2,16 @@ package main_test
import (
"context"
"os/signal"
"show-rss/src/cmd"
"syscall"
main "show-rss"
"testing"
"time"
)
func TestCmdMain(t *testing.T) {
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
func TestMain(t *testing.T) {
ctx, can := context.WithTimeout(context.Background(), 2*time.Second)
defer can()
ctx, can = context.WithTimeout(ctx, 5*time.Second)
defer can()
if err := cmd.Main(ctx); err != nil && ctx.Err() == nil {
if err := main.Main(ctx); err != nil && ctx.Err() == nil {
t.Fatal(err)
}
}