mirror of
https://github.com/octoleo/syncthing.git
synced 2024-09-21 06:09:02 +00:00
689cf2a5ee
* Fix ui, hide report date * Undo Goland madness * UR now web scale * Fix migration * Fix marshaling, force tick on start * Fix tests * Darwin build * Split "all" build target, add package name as a tag * Remove pq and sql dep from syncthing, split build targets * Empty line * Revert "Empty line" This reverts commit f74af2b067dadda8a343714123512bd545a643c3. * Revert "Remove pq and sql dep from syncthing, split build targets" This reverts commit 8fc295ad007c5bb7886c557f492dacf51be307ad. * Revert "Split "all" build target, add package name as a tag" This reverts commit f4dc88995106d2b06042f30bea781a0feb08e55f. * Normalise contract types * Fix build add more logging
131 lines
2.1 KiB
Go
131 lines
2.1 KiB
Go
// Copyright (C) 2020 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package contract
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
type PtrStruct struct {
|
|
A string `since:"2"`
|
|
B map[string]int `since:"3"`
|
|
}
|
|
|
|
type Nested struct {
|
|
A float32 `since:"4"`
|
|
B [4]int `since:"5"`
|
|
C bool `since:"1"`
|
|
}
|
|
|
|
type TestStruct struct {
|
|
A int
|
|
B map[string]string `since:"1"`
|
|
C []string `since:"2"`
|
|
Nested Nested `since:"3"`
|
|
|
|
Ptr *PtrStruct `since:"2"`
|
|
}
|
|
|
|
func testValue() TestStruct {
|
|
return TestStruct{
|
|
A: 1,
|
|
B: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
C: []string{"a", "b"},
|
|
Nested: Nested{
|
|
A: 0.10,
|
|
B: [4]int{1, 2, 3, 4},
|
|
C: true,
|
|
},
|
|
Ptr: &PtrStruct{
|
|
A: "value",
|
|
B: map[string]int{
|
|
"x": 1,
|
|
"b": 2,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestClean(t *testing.T) {
|
|
expect(t, 0, TestStruct{})
|
|
|
|
expect(t, 1, TestStruct{
|
|
// A unset, since it does not have "since"
|
|
B: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
})
|
|
|
|
expect(t, 2, TestStruct{
|
|
// A unset, since it does not have "since"
|
|
B: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
C: []string{"a", "b"},
|
|
Ptr: &PtrStruct{
|
|
A: "value",
|
|
},
|
|
})
|
|
|
|
expect(t, 3, TestStruct{
|
|
// A unset, since it does not have "since"
|
|
B: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
C: []string{"a", "b"},
|
|
Nested: Nested{
|
|
C: true,
|
|
},
|
|
Ptr: &PtrStruct{
|
|
A: "value",
|
|
B: map[string]int{
|
|
"x": 1,
|
|
"b": 2,
|
|
},
|
|
},
|
|
})
|
|
|
|
expect(t, 4, TestStruct{
|
|
// A unset, since it does not have "since"
|
|
B: map[string]string{
|
|
"foo": "bar",
|
|
},
|
|
C: []string{"a", "b"},
|
|
Nested: Nested{
|
|
A: 0.10,
|
|
C: true,
|
|
},
|
|
Ptr: &PtrStruct{
|
|
A: "value",
|
|
B: map[string]int{
|
|
"x": 1,
|
|
"b": 2,
|
|
},
|
|
},
|
|
})
|
|
|
|
x := testValue()
|
|
x.A = 0
|
|
|
|
expect(t, 5, x)
|
|
expect(t, 6, x)
|
|
}
|
|
|
|
func expect(t *testing.T, since int, b interface{}) {
|
|
t.Helper()
|
|
x := testValue()
|
|
if err := clear(&x, since); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
if !reflect.DeepEqual(x, b) {
|
|
t.Errorf("%#v != %#v", x, b)
|
|
}
|
|
}
|