forked from dotandev/hintents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
45 lines (39 loc) · 1.05 KB
/
main_test.go
File metadata and controls
45 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2026 Erst Users
// SPDX-License-Identifier: Apache-2.0
package main
import (
"bytes"
"errors"
"testing"
"github.com/dotandev/hintents/internal/cmd"
)
func TestRun_Interrupted(t *testing.T) {
var stderr bytes.Buffer
code := run(func() error { return cmd.ErrInterrupted }, &stderr)
if code != cmd.InterruptExitCode {
t.Fatalf("expected %d, got %d", cmd.InterruptExitCode, code)
}
if got := stderr.String(); got != "Interrupted. Shutting down...\n" {
t.Fatalf("unexpected stderr: %q", got)
}
}
func TestRun_GenericError(t *testing.T) {
var stderr bytes.Buffer
code := run(func() error { return errors.New("boom") }, &stderr)
if code != 1 {
t.Fatalf("expected 1, got %d", code)
}
if got := stderr.String(); got != "Error: boom\n" {
t.Fatalf("unexpected stderr: %q", got)
}
}
func TestRun_Success(t *testing.T) {
var stderr bytes.Buffer
code := run(func() error { return nil }, &stderr)
if code != 0 {
t.Fatalf("expected 0, got %d", code)
}
if stderr.Len() != 0 {
t.Fatalf("expected empty stderr, got %q", stderr.String())
}
}