hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

remote_test.go (2309B)

    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]any
   28 		want    fromRemoteOptions
   29 		wantErr bool
   30 	}{
   31 		{
   32 			"POST",
   33 			map[string]any{
   34 				"meThod": "PoST",
   35 				"headers": map[string]any{
   36 					"foo": "bar",
   37 				},
   38 			},
   39 			fromRemoteOptions{
   40 				Method: "POST",
   41 				Headers: map[string]any{
   42 					"foo": "bar",
   43 				},
   44 			},
   45 			false,
   46 		},
   47 		{
   48 			"Body",
   49 			map[string]any{
   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]any{
   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 }
   86 
   87 func TestCalculateResourceID(t *testing.T) {
   88 	c := qt.New(t)
   89 
   90 	c.Assert(calculateResourceID("foo", nil), qt.Equals, "5917621528921068675")
   91 	c.Assert(calculateResourceID("foo", map[string]any{"bar": "baz"}), qt.Equals, "7294498335241413323")
   92 
   93 	c.Assert(calculateResourceID("foo", map[string]any{"key": "1234", "bar": "baz"}), qt.Equals, "14904296279238663669")
   94 	c.Assert(calculateResourceID("asdf", map[string]any{"key": "1234", "bar": "asdf"}), qt.Equals, "14904296279238663669")
   95 	c.Assert(calculateResourceID("asdf", map[string]any{"key": "12345", "bar": "asdf"}), qt.Equals, "12191037851845371770")
   96 }