Beispiel #1
0
func (s *MySuite) TestVersion(c *C) {
	defer os.RemoveAll("test.json")
	type myStruct struct {
		Version  string
		User     string
		Password string
		Folders  []string
	}
	saveMe := myStruct{"1", "guest", "nopassword", []string{"Work", "Documents", "Music"}}
	config, err := quick.New(&saveMe)
	c.Assert(err, IsNil)
	c.Assert(config, Not(IsNil))
	err = config.Save("test.json")
	c.Assert(err, IsNil)

	valid, err := quick.CheckVersion("test.json", "1")
	c.Assert(err, IsNil)
	c.Assert(valid, Equals, true)

	valid, err = quick.CheckVersion("test.json", "2")
	c.Assert(err, IsNil)
	c.Assert(valid, Equals, false)

	_, err = quick.CheckVersion("test1.json", "1")
	c.Assert(err, Not(IsNil))

	file, err := os.Create("test.json")
	c.Assert(err, IsNil)
	c.Assert(file.Close(), IsNil)
	_, err = quick.CheckVersion("test.json", "1")
	c.Assert(err, Not(IsNil))
}
Beispiel #2
0
func migrateSharedURLsV2ToV3() {
	if !isSharedURLsDataFileExists() {
		return
	}
	conffile, err := getSharedURLsDataFile()
	if err != nil {
		return
	}
	v3, err := quick.CheckVersion(conffile, "3")
	if err != nil {
		fatalIf(err.Trace(), "Unable to check version on share list file")
	}
	if v3 {
		return
	}

	// try to load V2 if possible
	sURLsV2, err := loadSharedURLsV2()
	fatalIf(err.Trace(), "Unable to load shared url version ‘1.1.0’.")
	if sURLsV2.Version != "1.1.0" {
		fatalIf(errDummy().Trace(), "Invalid version loaded ‘"+sURLsV2.Version+"’.")
	}
	sURLsV3 := newSharedURLsV3()
	for _, value := range sURLsV2.URLs {
		entry := struct {
			Date    time.Time
			Message ShareMessageV3
		}{
			Date: value.Date,
			Message: ShareMessageV3{
				Expiry:      value.Message.Expiry,
				DownloadURL: value.Message.URL,
				Key:         value.Message.Key,
			},
		}
		sURLsV3.URLs = append(sURLsV3.URLs, entry)
	}
	err = saveSharedURLsV3(sURLsV3)
	fatalIf(err.Trace(), "Unable to save new shared url version ‘1.2.0’.")
}