func (s *S) TestForceInt(c *C) { sch := schema.ForceInt() out, err := sch.Coerce(42, aPath) c.Assert(err, IsNil) c.Assert(out, Equals, int(42)) out, err = sch.Coerce(int8(42), aPath) c.Assert(err, IsNil) c.Assert(out, Equals, int(42)) out, err = sch.Coerce(float32(42), aPath) c.Assert(err, IsNil) c.Assert(out, Equals, int(42)) out, err = sch.Coerce(float64(42), aPath) c.Assert(err, IsNil) c.Assert(out, Equals, int(42)) out, err = sch.Coerce(42.66, aPath) c.Assert(err, IsNil) c.Assert(out, Equals, int(42)) // If an out of range value is provided, that value is truncated, // generating unexpected results, but no error is raised. out, err = sch.Coerce(float64(math.MaxInt64+1), aPath) c.Assert(err, IsNil) out, err = sch.Coerce(true, aPath) c.Assert(out, IsNil) c.Assert(err, ErrorMatches, "<path>: expected number, got true") out, err = sch.Coerce(nil, aPath) c.Assert(out, IsNil) c.Assert(err, ErrorMatches, "<path>: expected number, got nothing") }
var fields = schema.Fields{ "type": schema.String(), "name": schema.String(), "default-series": schema.String(), "authorized-keys": schema.String(), "authorized-keys-path": schema.String(), "firewall-mode": schema.String(), "agent-version": schema.String(), "development": schema.Bool(), "admin-secret": schema.String(), "ca-cert": schema.String(), "ca-cert-path": schema.String(), "ca-private-key": schema.String(), "ca-private-key-path": schema.String(), "ssl-hostname-verification": schema.Bool(), "state-port": schema.ForceInt(), "api-port": schema.ForceInt(), } var defaults = schema.Defaults{ "default-series": DefaultSeries, "authorized-keys": "", "authorized-keys-path": "", "firewall-mode": FwDefault, "agent-version": schema.Omit, "development": false, "admin-secret": "", "ca-cert": schema.Omit, "ca-cert-path": "", "ca-private-key": schema.Omit, "ca-private-key-path": "",