File: pointer_helpers_test.go

package info (click to toggle)
golang-github-linode-linodego 1.47.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 10,032 kB
  • sloc: makefile: 95; sh: 52; python: 24
file content (47 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download
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
package linodego

import (
	"testing"
)

// TestPointer tests the Pointer helper function with various types
func TestPointer(t *testing.T) {
	// Test with an integer
	intValue := 11
	intPtr := Pointer(intValue)
	if *intPtr != intValue {
		t.Errorf("Expected %d, got %d", intValue, *intPtr)
	}

	// Test with a float
	floatValue := 1.23
	floatPtr := Pointer(floatValue)
	if *floatPtr != floatValue {
		t.Errorf("Expected %f, got %f", floatValue, *floatPtr)
	}

	// Test with a string
	stringValue := "hello world"
	stringPtr := Pointer(stringValue)
	if *stringPtr != stringValue {
		t.Errorf("Expected %s, got %s", stringValue, *stringPtr)
	}

	// Test with a boolean
	boolValue := true
	boolPtr := Pointer(boolValue)
	if *boolPtr != boolValue {
		t.Errorf("Expected %t, got %t", boolValue, *boolPtr)
	}

	// Test with a struct
	type myStruct struct {
		Field1 int
		Field2 string
	}
	structValue := myStruct{Field1: 1, Field2: "test"}
	structPtr := Pointer(structValue)
	if structPtr.Field1 != structValue.Field1 || structPtr.Field2 != structValue.Field2 {
		t.Errorf("Expected %+v, got %+v", structValue, *structPtr)
	}
}