-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
58 lines (47 loc) · 1.29 KB
/
Copy pathmain_test.go
File metadata and controls
58 lines (47 loc) · 1.29 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
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2026, Timo Pallach (timo@pallach.de).
package main
import (
"errors"
"io"
"testing"
"time"
)
func TestNewPluginSet(t *testing.T) {
pps := newPluginSet()
if pps == nil {
t.Fatal("newPluginSet() returned nil")
}
}
func TestMain_errorPath(t *testing.T) {
oldRun, oldExit, oldWriter := runPlugin, exitHook, errWriter
defer func() { runPlugin, exitHook, errWriter = oldRun, oldExit, oldWriter }()
runPlugin = func() error { return errors.New("plugin failed") }
var exitCode int
exitHook = func(code int) { exitCode = code }
errWriter = io.Discard
main()
if exitCode != 1 {
t.Fatalf("exitHook(%d), want 1", exitCode)
}
}
func TestMain_successPath(t *testing.T) {
oldRun, oldExit := runPlugin, exitHook
defer func() { runPlugin, exitHook = oldRun, oldExit }()
runPlugin = func() error { return nil }
exitHook = func(code int) { t.Fatalf("unexpected exitHook(%d)", code) }
main()
}
// Exercises defaultRunPlugin so the RPC entry point is linked in coverage builds.
// It is expected to block; the test times out quickly.
func TestDefaultRunPlugin_InvokesPluginRun(t *testing.T) {
done := make(chan struct{})
go func() {
_ = defaultRunPlugin()
close(done)
}()
select {
case <-done:
case <-time.After(5 * time.Millisecond):
}
}