summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/rsc/plist/plist_test.go
blob: 42f496c67c670b379bbc65bdd0b2aaa3047c1072 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2012 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package plist

import (
	"reflect"
	"testing"
)

var thePlist = `<plist version="1.0">
    <dict>
        <key>BucketUUID</key>
        <string>C218A47D-DAFB-4476-9C67-597E556D7D8A</string>
        <key>BucketName</key>
        <string>rsc</string>
        <key>ComputerUUID</key>
        <string>E7859547-BB9C-41C0-871E-858A0526BAE7</string>
        <key>LocalPath</key>
        <string>/Users/rsc</string>
        <key>LocalMountPoint</key>
        <string>/Users</string>
        <key>IgnoredRelativePaths</key>
        <array>
            <string>/.Trash</string>
            <string>/go/pkg</string>
            <string>/go1/pkg</string>
            <string>/Library/Caches</string>
        </array>
        <key>Excludes</key>
        <dict>
            <key>excludes</key>
            <array>
                <dict>
                    <key>type</key>
                    <integer>2</integer>
                    <key>text</key>
                    <string>.unison.</string>
                </dict>
            </array>
        </dict>
    </dict>
</plist>
`

var plistTests = []struct {
	in  string
	out interface{}
}{
	{
		thePlist,
		&MyStruct{
			BucketUUID:      "C218A47D-DAFB-4476-9C67-597E556D7D8A",
			BucketName:      "rsc",
			ComputerUUID:    "E7859547-BB9C-41C0-871E-858A0526BAE7",
			LocalPath:       "/Users/rsc",
			LocalMountPoint: "/Users",
			IgnoredRelativePaths: []string{
				"/.Trash",
				"/go/pkg",
				"/go1/pkg",
				"/Library/Caches",
			},
			Excludes: Exclude1{
				Excludes: []Exclude2{
					{Type: 2,
						Text: ".unison.",
					},
				},
			},
		},
	},
	{
		thePlist,
		&struct{}{},
	},
}

type MyStruct struct {
	BucketUUID           string
	BucketName           string
	ComputerUUID         string
	LocalPath            string
	LocalMountPoint      string
	IgnoredRelativePaths []string
	Excludes             Exclude1
}

type Exclude1 struct {
	Excludes []Exclude2 `plist:"excludes"`
}

type Exclude2 struct {
	Type int    `plist:"type"`
	Text string `plist:"text"`
}

func TestUnmarshal(t *testing.T) {
	for _, tt := range plistTests {
		v := reflect.New(reflect.ValueOf(tt.out).Type().Elem()).Interface()
		if err := Unmarshal([]byte(tt.in), v); err != nil {
			t.Errorf("%s", err)
			continue
		}
		if !reflect.DeepEqual(tt.out, v) {
			t.Errorf("unmarshal not equal")
		}
	}
}