Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
test(pkg/service): Add tests for service package
Browse files Browse the repository at this point in the history
Signed-off-by: Sneha Chhabria <snchh@microsoft.com>
  • Loading branch information
snehachhabria authored and nojnhuh committed Mar 12, 2021
1 parent 76222d6 commit 7df043e
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,80 @@ func TestServerName(t *testing.T) {
actual := namespacedService.ServerName()
assert.Equal("service-name-here.namespace-here.svc.cluster.local", actual)
}

func TestEquals(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
name string
service MeshService
anotherService MeshService
isEqual bool
}{
{
name: "services are equal",
service: MeshService{
Namespace: "default",
Name: "bookbuyer",
},
anotherService: MeshService{
Namespace: "default",
Name: "bookbuyer",
},
isEqual: true,
},
{
name: "services are NOT equal",
service: MeshService{
Namespace: "default",
Name: "bookbuyer",
},
anotherService: MeshService{
Namespace: "default",
Name: "bookstore",
},
isEqual: false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual := tc.service.Equals(tc.anotherService)
assert.Equal(actual, tc.isEqual)
})
}
}

func TestString(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
name string
service MeshService
serviceString string
}{
{
name: "service in default namespace",
service: MeshService{
Namespace: "default",
Name: "bookbuyer",
},
serviceString: "default/bookbuyer",
},
{
name: "service in custom namespace",
service: MeshService{
Namespace: "bookbuyer-ns",
Name: "bookbuyer",
},
serviceString: "bookbuyer-ns/bookbuyer",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual := tc.service.String()
assert.Equal(actual, tc.serviceString)
})
}
}

0 comments on commit 7df043e

Please sign in to comment.