Skip to content

Commit

Permalink
unit tests for parseConfig of appprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Jul 27, 2020
1 parent b46288b commit 5c2ae01
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ issues:
text: "SA1019:"
linters:
- staticcheck
# Exclude scopelint for tests files because of https://github.com/kyoh86/scopelint/issues/4
- path: _test\.go
linters:
- scopelint
linters:
enable:
- bodyclose
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/rs/cors v1.7.0
github.com/rs/zerolog v1.19.0
github.com/stretchr/testify v1.5.1
github.com/tus/tusd v1.1.1-0.20200416115059-9deabf9d80c2
go.opencensus.io v0.22.4
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
Expand Down
89 changes: 89 additions & 0 deletions internal/grpc/services/appprovider/appprovider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2018-2020 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package appprovider

import (
"testing"

"github.com/mitchellh/mapstructure"
"github.com/stretchr/testify/assert"
)

func Test_parseConfig(t *testing.T) {

tests := []struct {
name string
m map[string]interface{}
want *config
wantErr interface{}
}{
{
name: "all configurations set",
m: map[string]interface{}{
"Driver": "demo",
"Demo": map[string]interface{}{"a": "b", "c": "d"},
"IopSecret": "very-secret",
"WopiURL": "https://my.wopi:9871",
"UIURL": "https://the.ui",
"StorageID": "123-455",
},
want: &config{
Driver: "demo",
Demo: map[string]interface{}{"a": "b", "c": "d"},
IopSecret: "very-secret",
WopiURL: "https://my.wopi:9871",
UIURL: "", // this field seems not to get parsed see https://github.com/cs3org/reva/issues/991
StorageID: "123-455",
},
wantErr: nil,
},
{
name: "wrong type of setting",
m: map[string]interface{}{"Driver": 123, "IopSecret": 456},
want: nil,
wantErr: &mapstructure.Error{
Errors: []string{
"'driver' expected type 'string', got unconvertible type 'int'",
"'iopsecret' expected type 'string', got unconvertible type 'int'",
},
},
},
{
name: "undefined settings type",
m: map[string]interface{}{"Not-Defined": 123},
want: &config{
Driver: "",
Demo: map[string]interface{}(nil),
IopSecret: "",
WopiURL: "",
UIURL: "",
StorageID: "",
},
wantErr: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseConfig(tt.m)
assert.Equal(t, tt.wantErr, err)
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 5c2ae01

Please sign in to comment.