Skip to content

Commit f47b798

Browse files
committed
test(remote): move remote config tests to remote package
1 parent fb4f765 commit f47b798

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

c_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/spf13/cobra"
2121
"github.com/stretchr/testify/assert"
22-
"go.etcd.io/etcd/client/v3"
2322
)
2423

2524
func TestC_Serve(t *testing.T) {
@@ -130,27 +129,6 @@ func TestC_Default(t *testing.T) {
130129
assert.Contains(t, string(output), "gorm:")
131130
}
132131

133-
func TestC_Remote(t *testing.T) {
134-
addr := os.Getenv("ETCD_ADDR")
135-
if addr == "" {
136-
t.Skip("set ETCD_ADDR for run remote test")
137-
return
138-
}
139-
key := "core.yaml"
140-
envEtcdAddrs := strings.Split(addr, ",")
141-
cfg := clientv3.Config{
142-
Endpoints: envEtcdAddrs,
143-
DialTimeout: time.Second,
144-
}
145-
if err := put(cfg, key, "name: remote"); err != nil {
146-
t.Fatal(err)
147-
}
148-
149-
c := New(WithRemoteYamlFile(key, cfg))
150-
c.ProvideEssentials()
151-
assert.Equal(t, "remote", c.String("name"))
152-
}
153-
154132
type m1 struct {
155133
di.Out
156134
A int
@@ -201,21 +179,3 @@ func TestNew_missingDependencyErrorMessage(t *testing.T) {
201179
return nil
202180
})
203181
}
204-
205-
func put(cfg clientv3.Config, key, val string) error {
206-
client, err := clientv3.New(cfg)
207-
if err != nil {
208-
return err
209-
}
210-
defer client.Close()
211-
212-
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
213-
defer cancel()
214-
215-
_, err = client.Put(ctx, key, val)
216-
if err != nil {
217-
return err
218-
}
219-
220-
return nil
221-
}

config/remote/integration_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package remote_test
2+
3+
import (
4+
"context"
5+
"github.com/DoNewsCode/core"
6+
"github.com/stretchr/testify/assert"
7+
clientv3 "go.etcd.io/etcd/client/v3"
8+
"os"
9+
"strings"
10+
"testing"
11+
"time"
12+
)
13+
14+
func Test_integration(t *testing.T) {
15+
addr := os.Getenv("ETCD_ADDR")
16+
if addr == "" {
17+
t.Skip("set ETCD_ADDR for run remote test")
18+
return
19+
}
20+
key := "core.yaml"
21+
envEtcdAddrs := strings.Split(addr, ",")
22+
cfg := clientv3.Config{
23+
Endpoints: envEtcdAddrs,
24+
DialTimeout: time.Second,
25+
}
26+
if err := put(cfg, key, "name: remote"); err != nil {
27+
t.Fatal(err)
28+
}
29+
30+
c := core.New(core.WithRemoteYamlFile(key, cfg))
31+
c.ProvideEssentials()
32+
assert.Equal(t, "remote", c.String("name"))
33+
}
34+
35+
func put(cfg clientv3.Config, key, val string) error {
36+
client, err := clientv3.New(cfg)
37+
if err != nil {
38+
return err
39+
}
40+
defer client.Close()
41+
42+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
43+
defer cancel()
44+
45+
_, err = client.Put(ctx, key, val)
46+
if err != nil {
47+
return err
48+
}
49+
50+
return nil
51+
}

0 commit comments

Comments
 (0)