Skip to content

Commit

Permalink
added unit tests for find logic
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Avramenko <avramenkomihail15@gmail.com>
  • Loading branch information
Mixaster995 committed Oct 12, 2021
1 parent bda9091 commit f644d2a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (n *etcdNSRegistryServer) Unregister(ctx context.Context, request *registry
if err != nil {
return nil, err
}
err = n.client.NetworkservicemeshV1().NetworkServices("").Delete(
err = n.client.NetworkservicemeshV1().NetworkServices(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{},
Expand Down
28 changes: 27 additions & 1 deletion pkg/registry/etcd/ns_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Test_NSReRegister(t *testing.T) {
require.NoError(t, err)
}

func Test_K8sNERegistry_ShouldMatchMetadataToName(t *testing.T) {
func Test_K8sNSRegistry_ShouldMatchMetadataToName(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

Expand Down Expand Up @@ -68,3 +68,29 @@ func Test_K8sNERegistry_ShouldMatchMetadataToName(t *testing.T) {

require.Equal(t, "ns-1", nse.Name)
}

func Test_K8sNSRegistry_Find(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

var myClientset = fake.NewSimpleClientset()
_, err := myClientset.NetworkservicemeshV1().NetworkServices("some namespace").Create(ctx, &v1.NetworkService{
ObjectMeta: metav1.ObjectMeta{
Name: "ns-1",
},
}, metav1.CreateOptions{})
require.NoError(t, err)

c := adapters.NetworkServiceServerToClient(etcd.NewNetworkServiceRegistryServer(ctx, "", myClientset))
stream, err := c.Find(ctx, &registry.NetworkServiceQuery{
NetworkService: &registry.NetworkService{
Name: "ns-1",
},
})
require.NoError(t, err)

nse, err := stream.Recv()
require.NoError(t, err)

require.Equal(t, "ns-1", nse.Name)
}
2 changes: 1 addition & 1 deletion pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (n *etcdNSERegistryServer) Unregister(ctx context.Context, request *registr
if err != nil {
return nil, err
}
err = n.client.NetworkservicemeshV1().NetworkServiceEndpoints("").Delete(
err = n.client.NetworkservicemeshV1().NetworkServiceEndpoints(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{})
Expand Down
26 changes: 26 additions & 0 deletions pkg/registry/etcd/nse_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,29 @@ func Test_K8sNSERegistry_ShouldMatchMetadataToName(t *testing.T) {

require.Equal(t, "nse-1", nse.Name)
}

func Test_K8sNSERegistry_Find(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

var myClientset = fake.NewSimpleClientset()
_, err := myClientset.NetworkservicemeshV1().NetworkServiceEndpoints("some namespace").Create(ctx, &v1.NetworkServiceEndpoint{
ObjectMeta: metav1.ObjectMeta{
Name: "nse-1",
},
}, metav1.CreateOptions{})
require.NoError(t, err)

c := adapters.NetworkServiceEndpointServerToClient(etcd.NewNetworkServiceEndpointRegistryServer(ctx, "", myClientset))
stream, err := c.Find(ctx, &registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Name: "nse-1",
},
})
require.NoError(t, err)

nse, err := stream.Recv()
require.NoError(t, err)

require.Equal(t, "nse-1", nse.Name)
}

0 comments on commit f644d2a

Please sign in to comment.