Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for create_hash #396

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading