github.com/cs3org/reva/v2@v2.27.7/pkg/storage/fs/s3ng/option_test.go (about) 1 // Copyright 2018-2021 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package s3ng_test 20 21 import ( 22 "github.com/mitchellh/mapstructure" 23 24 "github.com/cs3org/reva/v2/pkg/storage/fs/s3ng" 25 26 . "github.com/onsi/ginkgo/v2" 27 . "github.com/onsi/gomega" 28 ) 29 30 var _ = Describe("Options", func() { 31 var ( 32 o *s3ng.Options 33 raw map[string]interface{} 34 ) 35 36 BeforeEach(func() { 37 raw := map[string]interface{}{ 38 "s3.endpoint": "http://1.2.3.4:5000", 39 "s3.region": "default", 40 "s3.bucket": "the-bucket", 41 "s3.access_key": "foo", 42 "s3.secret_key": "bar", 43 } 44 o = &s3ng.Options{} 45 err := mapstructure.Decode(raw, o) 46 Expect(err).ToNot(HaveOccurred()) 47 }) 48 49 It("parses s3 configuration", func() { 50 Expect(o.S3Endpoint).To(Equal("http://1.2.3.4:5000")) 51 Expect(o.S3Region).To(Equal("default")) 52 Expect(o.S3AccessKey).To(Equal("foo")) 53 Expect(o.S3SecretKey).To(Equal("bar")) 54 }) 55 56 Describe("S3ConfigComplete", func() { 57 It("returns true", func() { 58 Expect(o.S3ConfigComplete()).To(BeTrue()) 59 }) 60 61 It("returns false", func() { 62 fields := []string{"s3.endpoint", "s3.region", "s3.bucket", "s3.access_key", "s3.secret_key"} 63 for _, f := range fields { 64 delete(raw, f) 65 o = &s3ng.Options{} 66 err := mapstructure.Decode(raw, o) 67 Expect(err).ToNot(HaveOccurred()) 68 69 Expect(o.S3ConfigComplete()).To(BeFalse(), "failed to return false on missing '%s' field", f) 70 } 71 }) 72 }) 73 })