main test
parent
d14d73bf91
commit
36f8efd0e7
12
main.go
12
main.go
|
|
@ -8,10 +8,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
|
if err := Main(context.Background()); err != nil {
|
||||||
defer can()
|
|
||||||
|
|
||||||
if err := cmd.Main(ctx); err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Main(ctx context.Context) error {
|
||||||
|
ctx, can := signal.NotifyContext(ctx, syscall.SIGINT)
|
||||||
|
defer can()
|
||||||
|
|
||||||
|
return cmd.Main(ctx)
|
||||||
|
}
|
||||||
|
|
|
||||||
13
main_test.go
13
main_test.go
|
|
@ -2,21 +2,16 @@ package main_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os/signal"
|
main "show-rss"
|
||||||
"show-rss/src/cmd"
|
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCmdMain(t *testing.T) {
|
func TestMain(t *testing.T) {
|
||||||
ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
|
ctx, can := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer can()
|
defer can()
|
||||||
|
|
||||||
ctx, can = context.WithTimeout(ctx, 5*time.Second)
|
if err := main.Main(ctx); err != nil && ctx.Err() == nil {
|
||||||
defer can()
|
|
||||||
|
|
||||||
if err := cmd.Main(ctx); err != nil && ctx.Err() == nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue