Beispiel #1
0
func (s *mySuite) TestReadConfigFile() {

	//------------------------------------------------
	//               Read JSON file
	//------------------------------------------------
	/*
		{
		  "lineitem1": {
			  "description": "SSD Drive",
			  "count": 2,
			  "priceUSD": "250.00"
		  },
		  "lineitem2": {
			  "description": "RAM Chip",
			  "count": 4,
			  "priceUSD": "125.50"
		  }
		}
	*/

	obj, err := jc.ReadFile("testdata/invoice.json")
	if err != nil {
		log.Fatal(err)
	}
	lineitem1 := obj.RequiredObject("lineitem1")

	//------------------------------------------------
	//          description == "SSD Drive"
	//------------------------------------------------
	s.Equal(lineitem1["description"], "SSD Drive")

	//------------------------------------------------
	//                count == 2
	//------------------------------------------------
	lineitem1_count, err := u.ConvNumToInt(lineitem1["count"])
	if err != nil {
		log.Fatal(err)
	}
	s.Equal(lineitem1_count, int(2))

	//------------------------------------------------
	//             priceUSD == 250.00
	//------------------------------------------------
	item1PriceUSD, err := ParseUSD(lineitem1["priceUSD"].(string))
	if err != nil {
		log.Fatal(err)
	}
	usd250, err := ParseUSD("250.00")
	if err != nil {
		log.Fatal(err)
	}
	s.Equal(item1PriceUSD, usd250)

	s.Equal(u.TypeOf(usd250), "go_currency.USD")
}
Beispiel #2
0
func initLineItemPrices(jsonFile string) (item1PriceUSD USD, item2PriceUSD USD) {
	obj, err := jc.ReadFile(jsonFile)
	if err != nil {
		log.Fatal(err)
	}
	lineitem1 := obj.RequiredObject("lineitem1")
	item1PriceUSD, _ = ParseUSD(lineitem1["priceUSD"].(string))
	lineitem2 := obj.RequiredObject("lineitem2")
	item2PriceUSD, _ = ParseUSD(lineitem2["priceUSD"].(string))
	return item1PriceUSD, item2PriceUSD
}