Exemplo n.º 1
0
func TestGetFloat(t *testing.T) {
	Convey("Given an instance", t, func() {
		instance := new(fargo.Instance)
		Convey("With metadata", func() {
			metadata := new(fargo.InstanceMetadata)
			instance.Metadata = *metadata
			Convey("That has a float64 value", func() {
				key := "d"
				value := 1.9
				metadata.Raw = []byte("<" + key + ">" + strconv.FormatFloat(value, 'f', -1, 64) + "</" + key + ">")
				Convey("GetFloat64 should return that value", func() {
					actualValue, err := metadata.GetFloat64(key)
					So(err, ShouldBeNil)
					So(actualValue, ShouldEqual, value)
				})
			})
			Convey("That has a float32 value", func() {
				key := "d"
				value := 1.9
				metadata.Raw = []byte("<" + key + ">" + strconv.FormatFloat(value, 'f', -1, 32) + "</" + key + ">")
				Convey("GetFloat32 should return that value", func() {
					actualValue, err := metadata.GetFloat32(key)
					So(err, ShouldBeNil)
					So(actualValue, ShouldEqual, float32(1.9))
				})
			})
		})
	})
}
Exemplo n.º 2
0
func TestGetInt(t *testing.T) {
	Convey("Given an instance", t, func() {
		instance := new(fargo.Instance)
		Convey("With metadata", func() {
			metadata := new(fargo.InstanceMetadata)
			instance.Metadata = *metadata
			Convey("That has a single integer value", func() {
				key := "d"
				value := 1
				metadata.Raw = []byte("<" + key + ">" + strconv.Itoa(value) + "</" + key + ">")
				Convey("GetInt should return that value", func() {
					actualValue, err := metadata.GetInt(key)
					So(err, ShouldBeNil)
					So(actualValue, ShouldEqual, value)
				})
			})
		})
	})
}