File: pagination_test.go

package info (click to toggle)
golang-github-linode-linodego 1.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,112 kB
  • sloc: makefile: 96; sh: 52; python: 24
file content (49 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package linodego

import (
	"reflect"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func TestFlattenQueryStruct(t *testing.T) {
	type TestStruct struct {
		TestInt      int    `query:"test_int"`
		TestString   string `query:"test_string"`
		TestString2  string `query:"test_string_2"`
		TestInt64    int64  `query:"test_int64"`
		TestIn64Ptr  *int64 `query:"test_int64_ptr"`
		TestBool     bool   `query:"test_bool"`
		TestUntagged string
	}

	testInt64 := int64(789)

	inst := TestStruct{
		TestInt:      123,
		TestString:   "test+string",
		TestString2:  "",
		TestInt64:    567,
		TestIn64Ptr:  &testInt64,
		TestBool:     true,
		TestUntagged: "cool",
	}

	expectedOutput := map[string]string{
		"test_int":       "123",
		"test_string":    "test+string",
		"test_int64":     "567",
		"test_int64_ptr": "789",
		"test_bool":      "true",
	}

	result, err := flattenQueryStruct(inst)
	if err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(result, expectedOutput) {
		t.Fatalf("diff in result: %v", cmp.Diff(result, expectedOutput))
	}
}