-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode_test.go
More file actions
54 lines (45 loc) · 944 Bytes
/
Copy pathopencode_test.go
File metadata and controls
54 lines (45 loc) · 944 Bytes
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
package opencode
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
cfg := Config{
CWD: "/test/config",
Addr: "localhost:8080",
}
oc := New(cfg)
assert.NotNil(t, oc)
assert.Equal(t, cfg.CWD, oc.config.CWD)
assert.Equal(t, cfg.Addr, oc.config.Addr)
assert.NotNil(t, oc.client)
assert.Equal(t, cfg.Addr, oc.Addr())
}
func TestStopWhenNotRunning(t *testing.T) {
oc := New(Config{})
err := oc.Stop()
assert.NoError(t, err)
}
func TestStartWhenAlreadyRunning(t *testing.T) {
cfg := Config{
Addr: "localhost:6973",
}
oc := New(cfg)
oc.cmd = nil
err := oc.Start()
if err != nil {
assert.Contains(t, err.Error(), "failed to start opencode")
}
}
func TestStartAutoAllocatesPort(t *testing.T) {
cfg := Config{
CWD: "/test/config",
}
oc := New(cfg)
oc.cmd = nil
err := oc.Start()
if err == nil {
oc.Stop()
t.Log("Started successfully, would allocate random port")
}
}