Exemplo n.º 1
0
func (s *JSONSuite) TestEncoding(c *C) {
	jsonFile := s.TmpDir + "/file2.json"

	testStruct := &TestStruct{
		String:  "test",
		Integer: 912,
		Boolean: true,
	}

	err := EncodeToFile(jsonFile, testStruct)

	c.Assert(err, IsNil)
	c.Assert(hash.FileHash(jsonFile), Equals,
		"b88184cc9c6c517e572a21acae7118d58c485b051c33f3f13d057b43461c4eec")

	err = EncodeToFile("/test.json", testStruct)

	c.Assert(err, NotNil)
}
Exemplo n.º 2
0
func (s *JSONSuite) TestDecoding(c *C) {
	jsonFile := s.TmpDir + "/file1.json"

	err := ioutil.WriteFile(jsonFile, []byte(_JSON_DATA), 0644)

	c.Assert(err, IsNil)
	c.Assert(hash.FileHash(jsonFile), Equals,
		"b88184cc9c6c517e572a21acae7118d58c485b051c33f3f13d057b43461c4eec")

	testStruct := &TestStruct{}

	err = DecodeFile(s.TmpDir+"/file-not-exists.json", &TestStruct{})

	c.Assert(err, NotNil)

	err = DecodeFile(s.TmpDir+"/file1.json", testStruct)

	c.Assert(err, IsNil)
	c.Assert(testStruct.String, Equals, "test")
	c.Assert(testStruct.Integer, Equals, 912)
	c.Assert(testStruct.Boolean, Equals, true)
}