Skip to content

Commit

Permalink
Update AppRegistry tests with the mimetypes infos from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Sep 24, 2021
1 parent a06b938 commit e6d2f50
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions internal/grpc/services/appregistry/appregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Test_ListAppProviders(t *testing.T) {
tests := []struct {
name string
providers map[string]interface{}
mimeTypes map[string]map[string]string
want *registrypb.ListAppProvidersResponse
}{
{
Expand All @@ -54,6 +55,20 @@ func Test_ListAppProviders(t *testing.T) {
"mimetypes": []string{"currently/ignored"},
},
},
mimeTypes: map[string]map[string]string{
"text/json": {
"extension": "json",
"name": "JSON File",
"icon": "https://example.org/icons&file=json.png",
"default_app": "some Address",
},
"currently/ignored": {
"extension": "unknown",
"name": "Ignored file",
"icon": "https://example.org/icons&file=unknown.png",
"default_app": "some Address",
},
},

// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Expand All @@ -77,6 +92,7 @@ func Test_ListAppProviders(t *testing.T) {
{
name: "providers is nil",
providers: nil,
mimeTypes: nil,
want: &registrypb.ListAppProvidersResponse{
Status: &rpcv1beta1.Status{
Code: 1,
Expand All @@ -93,6 +109,7 @@ func Test_ListAppProviders(t *testing.T) {
{
name: "empty providers",
providers: map[string]interface{}{},
mimeTypes: map[string]map[string]string{},

// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Expand All @@ -114,6 +131,7 @@ func Test_ListAppProviders(t *testing.T) {
providers: map[string]interface{}{
"some Address": nil,
},
mimeTypes: map[string]map[string]string{},

// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Expand All @@ -129,7 +147,7 @@ func Test_ListAppProviders(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rr, err := static.New(map[string]interface{}{"Providers": tt.providers})
rr, err := static.New(map[string]interface{}{"providers": tt.providers, "mime_types": tt.mimeTypes})
if err != nil {
t.Errorf("could not create registry error = %v", err)
return
Expand Down Expand Up @@ -168,6 +186,45 @@ func Test_GetAppProviders(t *testing.T) {
},
}

mimeTypes := map[string]map[string]string{
"text/json": {
"extension": "json",
"name": "JSON File",
"icon": "https://example.org/icons&file=json.png",
"default_app": "some Address",
},
"text/xml": {
"extension": "xml",
"name": "XML File",
"icon": "https://example.org/icons&file=xml.png",
"default_app": "some Address",
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
"extension": "doc",
"name": "Word File",
"icon": "https://example.org/icons&file=doc.png",
"default_app": "some Address",
},
"application/vnd.oasis.opendocument.presentation": {
"extension": "odf",
"name": "OpenDocument File",
"icon": "https://example.org/icons&file=odf.png",
"default_app": "some Address",
},
"application/vnd.apple.installer+xml": {
"extension": "mpkg",
"name": "Mpkg File",
"icon": "https://example.org/icons&file=mpkg.png",
"default_app": "some Address",
},
"image/bmp": {
"extension": "bmp",
"name": "Image File",
"icon": "https://example.org/icons&file=bmp.png",
"default_app": "some Address",
},
}

tests := []struct {
name string
search *providerv1beta1.ResourceInfo
Expand Down Expand Up @@ -258,7 +315,7 @@ func Test_GetAppProviders(t *testing.T) {
},
}

rr, err := static.New(map[string]interface{}{"providers": providers})
rr, err := static.New(map[string]interface{}{"providers": providers, "mime_types": mimeTypes})
if err != nil {
t.Errorf("could not create registry error = %v", err)
return
Expand Down

0 comments on commit e6d2f50

Please sign in to comment.