2021-02-17 11:14:47 +02:00
|
|
|
package kratos
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-kratos/kratos/v2/transport/grpc"
|
|
|
|
"github.com/go-kratos/kratos/v2/transport/http"
|
2021-08-02 12:56:22 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-02-17 11:14:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestApp(t *testing.T) {
|
|
|
|
hs := http.NewServer()
|
|
|
|
gs := grpc.NewServer()
|
|
|
|
app := New(
|
|
|
|
Name("kratos"),
|
|
|
|
Version("v1.0.0"),
|
|
|
|
Server(hs, gs),
|
|
|
|
)
|
|
|
|
time.AfterFunc(time.Second, func() {
|
|
|
|
app.Stop()
|
|
|
|
})
|
|
|
|
if err := app.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2021-08-02 12:56:22 +02:00
|
|
|
|
|
|
|
func TestApp_ID(t *testing.T) {
|
|
|
|
v := "123"
|
|
|
|
o := New(ID(v))
|
|
|
|
assert.Equal(t, v, o.ID())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApp_Name(t *testing.T) {
|
|
|
|
v := "123"
|
|
|
|
o := New(Name(v))
|
|
|
|
assert.Equal(t, v, o.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApp_Version(t *testing.T) {
|
|
|
|
v := "123"
|
|
|
|
o := New(Version(v))
|
|
|
|
assert.Equal(t, v, o.Version())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestApp_Metadata(t *testing.T) {
|
|
|
|
v := map[string]string{
|
|
|
|
"a": "1",
|
|
|
|
"b": "2",
|
|
|
|
}
|
|
|
|
o := New(Metadata(v))
|
|
|
|
assert.Equal(t, v, o.Metadata())
|
|
|
|
}
|