From 36f8efd0e7e28a1aeba696ab288f859b5719b687 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 24 Apr 2025 21:14:37 -0600 Subject: [PATCH] main test --- main.go | 12 ++++++++---- main_test.go | 13 ++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index 20d19b7..d167318 100644 --- a/main.go +++ b/main.go @@ -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) +} diff --git a/main_test.go b/main_test.go index 9326499..1111c75 100644 --- a/main_test.go +++ b/main_test.go @@ -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) } }