github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/resources/resource_factories/create/remote_test.go (about) 1 // Copyright 2021 The Hugo Authors. All rights reserved. 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 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package create 15 16 import ( 17 "testing" 18 19 qt "github.com/frankban/quicktest" 20 ) 21 22 func TestDecodeRemoteOptions(t *testing.T) { 23 c := qt.New(t) 24 25 for _, test := range []struct { 26 name string 27 args map[string]interface{} 28 want fromRemoteOptions 29 wantErr bool 30 }{ 31 { 32 "POST", 33 map[string]interface{}{ 34 "meThod": "PoST", 35 "headers": map[string]interface{}{ 36 "foo": "bar", 37 }, 38 }, 39 fromRemoteOptions{ 40 Method: "POST", 41 Headers: map[string]interface{}{ 42 "foo": "bar", 43 }, 44 }, 45 false, 46 }, 47 { 48 "Body", 49 map[string]interface{}{ 50 "meThod": "POST", 51 "body": []byte("foo"), 52 }, 53 fromRemoteOptions{ 54 Method: "POST", 55 Body: []byte("foo"), 56 }, 57 false, 58 }, 59 { 60 "Body, string", 61 map[string]interface{}{ 62 "meThod": "POST", 63 "body": "foo", 64 }, 65 fromRemoteOptions{ 66 Method: "POST", 67 Body: []byte("foo"), 68 }, 69 false, 70 }, 71 } { 72 c.Run(test.name, func(c *qt.C) { 73 got, err := decodeRemoteOptions(test.args) 74 isErr := qt.IsNil 75 if test.wantErr { 76 isErr = qt.IsNotNil 77 } 78 79 c.Assert(err, isErr) 80 c.Assert(got, qt.DeepEquals, test.want) 81 }) 82 83 } 84 85 }