Skip to content

Commit

Permalink
modify unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Leospard committed Sep 18, 2022
1 parent 7464068 commit 4d8844e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
32 changes: 17 additions & 15 deletions metadata/definition/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ type ServiceDefiner interface {

// ServiceDefinition is the describer of service definition
type ServiceDefinition struct {
CanonicalName string `json:"canonicalName,omitempty"`
CodeSource string `json:"codeSource,omitempty"`
Methods []MethodDefinition `json:"methods,omitempty"`
Types []TypeDefinition `json:"types,omitempty"`
CanonicalName string `json:"canonicalName"`
CodeSource string `json:"codeSource"`
Methods []MethodDefinition `json:"methods"`
Types []TypeDefinition `json:"types"`
}

// ToBytes convert ServiceDefinition to json string
Expand Down Expand Up @@ -70,26 +70,28 @@ func (def *ServiceDefinition) String() string {

// FullServiceDefinition is the describer of service definition with parameters
type FullServiceDefinition struct {
Parameters map[string]string `json:"parameters,omitempty"`
Parameters map[string]string `json:"parameters"`
ServiceDefinition
}

// MethodDefinition is the describer of method definition
type MethodDefinition struct {
Name string `json:"name,omitempty"`
ParameterTypes []string `json:"parameterTypes,omitempty"`
ReturnType string `json:"returnTypes,omitempty"`
Parameters []TypeDefinition `json:"parameters,omitempty"`
Name string `json:"name"`
ParameterTypes []string `json:"parameterTypes"`
ReturnType string `json:"returnType"`
Parameters []TypeDefinition `json:"parameters"`
}

// TypeDefinition is the describer of type definition
type TypeDefinition struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Items []TypeDefinition `json:"items,omitempty"`
Enums []string `json:"enums,omitempty"`
Properties map[string]TypeDefinition `json:"properties,omitempty"`
TypeBuilderName string `json:"typeBuilderName,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Items []TypeDefinition `json:"items"`
Enums []string `json:"enums"`
Properties map[string]TypeDefinition `json:"properties"`
TypeBuilderName string `json:"typeBuilderName
"`
}

// BuildServiceDefinition can build service definition which will be used to describe a service
Expand Down
6 changes: 3 additions & 3 deletions metadata/service/local/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func TestMetadataService(t *testing.T) {
assert.NoError(t, err)
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)
expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
expected := "{\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," +
"\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," +
"\"parameters\":null}],\"types\":null}"
def1, err := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions metadata/service/remote/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ func TestMockInmemoryProc(t *testing.T) {
err = mts.PublishServiceDefinition(u)
assert.NoError(t, err)

expected := "{\"CanonicalName\":\"com.ikurento.user.UserProvider\",\"CodeSource\":\"\"," +
"\"Methods\":[{\"Name\":\"GetUser\",\"ParameterTypes\":[\"slice\"],\"ReturnType\":\"ptr\"," +
"\"Parameters\":null}],\"Types\":null}"
expected := "{\"canonicalName\":\"com.ikurento.user.UserProvider\",\"codeSource\":\"\"," +
"\"methods\":[{\"name\":\"GetUser\",\"parameterTypes\":[\"slice\"],\"returnType\":\"ptr\"," +
"\"parameters\":null}],\"types\":null}"
def1, _ := mts.GetServiceDefinition(serviceName, group, version)
assert.Equal(t, expected, def1)
serviceKey := definition.ServiceDescriperBuild(serviceName, group, version)
Expand Down

0 comments on commit 4d8844e

Please sign in to comment.