-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit tests for parseConfig of appprovider
- Loading branch information
1 parent
7bc0cb7
commit 78dce53
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// 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 ( | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
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) | ||
}) | ||
} | ||
} |