-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathapps_test.go
More file actions
44 lines (37 loc) · 781 Bytes
/
apps_test.go
File metadata and controls
44 lines (37 loc) · 781 Bytes
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
package api
import (
"fmt"
"testing"
"github.com/semaphoreui/semaphore/pkg/conv"
)
func TestStructToMap(t *testing.T) {
type Address struct {
City string `json:"city"`
State string `json:"state"`
}
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Email string `json:"email"`
Active bool `json:"active"`
Address Address `json:"address"`
}
// Create an instance of the struct
p := Person{
Name: "John Doe",
Age: 30,
Email: "johndoe@example.com",
Active: true,
Address: Address{
City: "New York",
State: "NY",
},
}
// Convert the struct to a flat map
flatMap := conv.StructToFlatMap(&p)
if flatMap["address.city"] != "New York" {
t.Fail()
}
// Print the map
fmt.Println(flatMap)
}