Repository: syncthing/syncthing
File: lib/config/config_test.go (Go)

Code before:

func TestDeviceConfig(t *testing.T) {
	for i := OldestHandledVersion; i <= CurrentVersion; i++ {
		cfgFile := fmt.Sprintf("v%d.xml", i)
		if _, err := testFs.Stat(cfgFile); os.IsNotExist(err) {
			continue
		}

		testFs.RemoveAll(DefaultMarkerName)
		wr, wrCancel, err := copyAndLoad(testFs, cfgFile, device1)
		defer wrCancel()
		if err != nil {
			t.Fatal(err)
		}

		_, err = testFs.Stat(DefaultMarkerName)
		if i < 6 && err != nil {
			t.Fatal(err)
		} else if i >= 6 && err == nil {
			t.Fatal("Unexpected file")
		}

		cfg := wr.Wrapper.(*wrapper).cfg

		fc := FolderConfiguration{}
		structutil.SetDefaults(&fc)
		fc.ID = "test"
		fc.FilesystemType = FilesystemTypeBasic
		fc.Path = "testdata"
		fc.Devices = []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}}
		fc.Type = FolderTypeSendOnly
		fc.RescanIntervalS = 600
		fc.FSWatcherEnabled = false
		fc.FSWatcherDelayS = 10
		fc.Copiers = 0
		fc.Hashers = 0
		fc.AutoNormalize = true
		fc.MinDiskFree = Size{1, "%"}
		fc.MaxConflicts = -1
		fc.JunctionsAsDirs = true
		fc.MaxConcurrentWrites = maxConcurrentWritesDefault
		fc.FSWatcherEnabled = true
		fc.Versioning.CleanupIntervalS = 3600
		fc.Versioning.Params = map[string]string{}
		fc.XattrFilter.Entries = []XattrFilterEntry{}

		expectedDevices := []DeviceConfiguration{
			{
				DeviceID:        device1,
				Name:            "node one",
				Addresses:       []string{"tcp://a"},

Review comment (suggestion):
We don't want to do this here. The purpose of the test, such as it is, is to verify that the config is created with the default values we expect. Running the default-setter on the expected result makes it an `a == a` type of comparison, so I think we want to keep this manually defined.

Code after:
func TestDeviceConfig(t *testing.T) {
	for i := OldestHandledVersion; i <= CurrentVersion; i++ {
		cfgFile := fmt.Sprintf("v%d.xml", i)
		if _, err := testFs.Stat(cfgFile); os.IsNotExist(err) {
			continue
		}

		testFs.RemoveAll(DefaultMarkerName)
		wr, wrCancel, err := copyAndLoad(testFs, cfgFile, device1)
		defer wrCancel()
		if err != nil {
			t.Fatal(err)
		}

		_, err = testFs.Stat(DefaultMarkerName)
		if i < 6 && err != nil {
			t.Fatal(err)
		} else if i >= 6 && err == nil {
			t.Fatal("Unexpected file")
		}

		cfg := wr.Wrapper.(*wrapper).cfg

		expectedFolders := []FolderConfiguration{
			{
				ID:               "test",
				FilesystemType:   FilesystemTypeBasic,
				Path:             "testdata",
				Devices:          []FolderDeviceConfiguration{{DeviceID: device1}, {DeviceID: device4}},
				Type:             FolderTypeSendOnly,
				RescanIntervalS:  600,
				FSWatcherEnabled: true,
				FSWatcherDelayS:  10,
				Copiers:          0,
				Hashers:          0,
				AutoNormalize:    true,
				MinDiskFree:      Size{1, "%"},
				MaxConflicts:     -1,
				Versioning: VersioningConfiguration{
					CleanupIntervalS: 3600,
					FSType:           FilesystemTypeBasic,
					Params:           map[string]string{},
				},
				WeakHashThresholdPct: 25,
				MarkerName:           DefaultMarkerName,
				JunctionsAsDirs:      true,
				MaxConcurrentWrites:  maxConcurrentWritesDefault,
				XattrFilter: XattrFilter{
					MaxSingleEntrySize: 1024,
					MaxTotalSize:       4096,
					Entries:            []XattrFilterEntry{},