Skip to content

Commit

Permalink
Add test for create_hash (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanG100 authored Apr 11, 2024
1 parent b678d6b commit dfdcbf4
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dataplane/saiserver/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,42 @@ func TestCreateRouterInterface(t *testing.T) {
}
}

func TestCreateHash(t *testing.T) {
tests := []struct {
desc string
req *saipb.CreateHashRequest
wantErr string
}{{
desc: "unknown type",
req: &saipb.CreateHashRequest{
NativeHashFieldList: []saipb.NativeHashField{saipb.NativeHashField_NATIVE_HASH_FIELD_UNSPECIFIED},
},
wantErr: "InvalidArgument",
}, {
desc: "success",
req: &saipb.CreateHashRequest{
NativeHashFieldList: []saipb.NativeHashField{
saipb.NativeHashField_NATIVE_HASH_FIELD_SRC_IP,
saipb.NativeHashField_NATIVE_HASH_FIELD_DST_IP,
saipb.NativeHashField_NATIVE_HASH_FIELD_L4_SRC_PORT,
saipb.NativeHashField_NATIVE_HASH_FIELD_L4_DST_PORT,
saipb.NativeHashField_NATIVE_HASH_FIELD_IPV6_FLOW_LABEL,
},
},
}}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
dplane := &fakeSwitchDataplane{}
c, _, stopFn := newTestHash(t, dplane)
defer stopFn()
_, gotErr := c.CreateHash(context.TODO(), tt.req)
if diff := errdiff.Check(gotErr, tt.wantErr); diff != "" {
t.Fatalf("CreateHash() unexpected err: %s", diff)
}
})
}
}

func newTestNeighbor(t testing.TB, api switchDataplaneAPI) (saipb.NeighborClient, *attrmgr.AttrMgr, func()) {
conn, mgr, stopFn := newTestServer(t, func(mgr *attrmgr.AttrMgr, srv *grpc.Server) {
newNeighbor(mgr, api, srv)
Expand Down Expand Up @@ -882,3 +918,10 @@ func newTestRouterInterface(t testing.TB, api switchDataplaneAPI) (saipb.RouterI
})
return saipb.NewRouterInterfaceClient(conn), mgr, stopFn
}

func newTestHash(t testing.TB, api switchDataplaneAPI) (saipb.HashClient, *attrmgr.AttrMgr, func()) {
conn, mgr, stopFn := newTestServer(t, func(mgr *attrmgr.AttrMgr, srv *grpc.Server) {
newHash(mgr, api, srv)
})
return saipb.NewHashClient(conn), mgr, stopFn
}

0 comments on commit dfdcbf4

Please sign in to comment.