Newer
Older
package server
import (
"context"
"reflect"
"testing"
Fabian Seidl
committed
"time"
)
func Test_core_Set(t *testing.T) {
type args struct {
ctx context.Context
Fabian Seidl
committed
request *pb.CreatePndListRequest
}
tests := []struct {
name string
args args
Fabian Seidl
committed
want *pb.CreatePndListResponse
wantErr bool
}{
{
name: "default",
args: args{
ctx: context.Background(),
Fabian Seidl
committed
request: &pb.CreatePndListRequest{
Pnd: []*pb.PndCreateProperties{
{
Name: "test",
Description: "test",
Sbi: "test",
},
},
},
},
Fabian Seidl
committed
want: &pb.CreatePndListResponse{
Status: pb.Status_STATUS_OK,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := core{
UnimplementedCoreServiceServer: pb.UnimplementedCoreServiceServer{},
Fabian Seidl
committed
got, err := s.CreatePndList(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("core.Set() error = %v, wantErr %v", err, tt.wantErr)
return
}
tt.want.Timestamp = got.Timestamp
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("core.Set() = %v, want %v", got, tt.want)
}
})
}
}
Fabian Seidl
committed
func Test_core_GetPnd(t *testing.T) {
Fabian Seidl
committed
request *pb.GetPndRequest
}
tests := []struct {
name string
args args
want []string
wantErr bool
}{
{
name: "default",
args: args{
ctx: context.Background(),
Fabian Seidl
committed
request: &pb.GetPndRequest{
Pid: []string{
pndID,
},
want: []string{
pndID,
"test",
"test",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := core{
UnimplementedCoreServiceServer: pb.UnimplementedCoreServiceServer{},
Fabian Seidl
committed
resp, err := s.GetPnd(tt.args.ctx, tt.args.request)
Fabian Seidl
committed
t.Errorf("core.GetPnd() error = %v, wantErr %v", err, tt.wantErr)
if tt.name == "default" {
got := []string{
resp.Pnd[0].Id,
resp.Pnd[0].Name,
resp.Pnd[0].Description,
}
if !reflect.DeepEqual(got, tt.want) {
Fabian Seidl
committed
t.Errorf("core.GetPnd() = %v, want %v", got, tt.want)
length := len(resp.Pnd)
if tt.length != length {
Fabian Seidl
committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
t.Errorf("core.GetPnd() = %v, want %v", length, tt.length)
}
})
}
}
func Test_core_GetPndList(t *testing.T) {
type args struct {
ctx context.Context
request *pb.GetPndListRequest
}
tests := []struct {
name string
args args
want []string
length int
wantErr bool
}{
{
name: "getAll",
args: args{
ctx: context.Background(),
request: &pb.GetPndListRequest{
Timestamp: time.Now().UnixNano(),
},
},
length: 2,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := core{
UnimplementedCoreServiceServer: pb.UnimplementedCoreServiceServer{},
}
resp, err := s.GetPndList(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("core.GetPndList() error = %v, wantErr %v", err, tt.wantErr)
return
}
length := len(resp.Pnd)
if tt.length != length {
t.Errorf("core.GetPndList() = %v, want %v", length, tt.length)