Skip to content

Commit

Permalink
Ensure default AppProvider is top of list and keep mime type order fr…
Browse files Browse the repository at this point in the history
…om config (#2138)

* Default AppProvider always on top of the list when asking for mime type list.
Providers are ordered according to the config.
Changed config from using a map to a list, for keeping the order.

* Add tests

* Add changelog

* Fix AppRegistry tests

* Simplified code
  • Loading branch information
gmgigi96 authored Oct 8, 2021
1 parent 9be4c4f commit a70d374
Show file tree
Hide file tree
Showing 6 changed files with 917 additions and 274 deletions.
12 changes: 12 additions & 0 deletions changelog/unreleased/app-registry-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Enhancement: Default AppProvider on top of the providers list
for each mime type

Now for each mime type, when asking for the list of mime types,
the default AppProvider, set both using the config and the
SetDefaultProviderForMimeType method, is always in the top of the
list of AppProviders.
The config for the Providers and Mime Types for the AppRegistry changed,
using a list instead of a map. In fact the list of mime types returned by
ListSupportedMimeTypes is now ordered according the config.

https://github.com/cs3org/reva/pull/2138
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require (
github.com/thanhpk/randstr v1.0.4
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tus/tusd v1.6.0
github.com/wk8/go-ordered-map v0.2.0
go.mongodb.org/mongo-driver v1.7.2 // indirect
go.opencensus.io v0.23.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.24.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ github.com/tus/tusd v1.6.0/go.mod h1:ygrT4B9ZSb27dx3uTnobX5nOFDnutBL6iWKLH4+KpA0
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/vimeo/go-util v1.2.0/go.mod h1:s13SMDTSO7AjH1nbgp707mfN5JFIWUFDU5MDDuRRtKs=
github.com/wk8/go-ordered-map v0.2.0 h1:KlvGyHstD1kkGZkPtHCyCfRYS0cz84uk6rrW/Dnhdtk=
github.com/wk8/go-ordered-map v0.2.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
Expand Down
67 changes: 29 additions & 38 deletions internal/grpc/services/appregistry/appregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,32 @@ func (a ByAddress) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func Test_ListAppProviders(t *testing.T) {
tests := []struct {
name string
providers map[string]interface{}
mimeTypes map[string]map[string]string
providers []map[string]interface{}
mimeTypes []map[string]interface{}
want *registrypb.ListAppProvidersResponse
}{
{
name: "simple test",
providers: map[string]interface{}{
"some Address": map[string]interface{}{
providers: []map[string]interface{}{
{
"address": "some Address",
"mimetypes": []string{"text/json"},
},
"another address": map[string]interface{}{
{
"address": "another address",
"mimetypes": []string{"currently/ignored"},
},
},
mimeTypes: map[string]map[string]string{
"text/json": {
mimeTypes: []map[string]interface{}{
{
"mime_type": "text/json",
"extension": "json",
"name": "JSON File",
"icon": "https://example.org/icons&file=json.png",
"default_app": "some Address",
},
"currently/ignored": {
{
"mime_type": "currently/ignored",
"extension": "unknown",
"name": "Ignored file",
"icon": "https://example.org/icons&file=unknown.png",
Expand Down Expand Up @@ -103,8 +105,8 @@ func Test_ListAppProviders(t *testing.T) {
},
{
name: "empty providers",
providers: map[string]interface{}{},
mimeTypes: map[string]map[string]string{},
providers: []map[string]interface{}{},
mimeTypes: []map[string]interface{}{},

// only Status and Providers will be asserted in the tests
want: &registrypb.ListAppProvidersResponse{
Expand All @@ -116,23 +118,6 @@ func Test_ListAppProviders(t *testing.T) {
Providers: []*registrypb.ProviderInfo{},
},
},
{
name: "provider value is nil",
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{
Status: &rpcv1beta1.Status{
Code: 1,
Trace: "00000000000000000000000000000000",
Message: "",
},
Providers: []*registrypb.ProviderInfo{nil},
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -161,53 +146,59 @@ func Test_ListAppProviders(t *testing.T) {
}

func Test_GetAppProviders(t *testing.T) {
providers := map[string]interface{}{
"text appprovider addr": map[string]interface{}{
providers := []map[string]interface{}{
{
"address": "text appprovider addr",
"mimetypes": []string{"text/json", "text/xml"},
},
"image appprovider addr": map[string]interface{}{
{
"address": "image appprovider addr",
"mimetypes": []string{"image/bmp"},
},
"misc appprovider addr": map[string]interface{}{
{
"address": "misc appprovider addr",
"mimetypes": []string{"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.oasis.opendocument.presentation", "application/vnd.apple.installer+xml"},
},
}

mimeTypes := map[string]map[string]string{
"text/json": {
mimeTypes := []map[string]string{
{
"mime_type": "text/json",
"extension": "json",
"name": "JSON File",
"icon": "https://example.org/icons&file=json.png",
"default_app": "some Address",
},
"text/xml": {
{
"mime_type": "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": {
{
"mime_type": "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": {
{
"mime_type": "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": {
{
"mime_type": "application/vnd.apple.installer+xml",
"extension": "mpkg",
"name": "Mpkg File",
"icon": "https://example.org/icons&file=mpkg.png",
"default_app": "some Address",
},
"image/bmp": {
{
"mime_type": "image/bmp",
"extension": "bmp",
"name": "Image File",
"icon": "https://example.org/icons&file=bmp.png",
Expand Down
Loading

0 comments on commit a70d374

Please sign in to comment.