本文整理汇总了Golang中github.com/coreos/ignition/config/validate/report.ReportFromError函数的典型用法代码示例。如果您正苦于以下问题:Golang ReportFromError函数的具体用法?Golang ReportFromError怎么用?Golang ReportFromError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ReportFromError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Parse
func Parse(data []byte) (types.Config, report.Report) {
var cfg types.Config
var r report.Report
if err := yaml.Unmarshal(data, &cfg); err != nil {
return types.Config{}, report.ReportFromError(err, report.EntryError)
}
nodes := yaml.UnmarshalToNode(data)
if nodes == nil {
r.Add(report.Entry{
Kind: report.EntryWarning,
Message: "Configuration is empty",
})
r.Merge(validate.ValidateWithoutSource(reflect.ValueOf(cfg)))
} else {
root, err := fromYamlDocumentNode(*nodes)
if err != nil {
return types.Config{}, report.ReportFromError(err, report.EntryError)
}
r.Merge(validate.Validate(reflect.ValueOf(cfg), root, nil))
}
if r.IsFatal() {
return types.Config{}, r
}
return cfg, r
}
示例2: Validate
func (f Filesystem) Validate() report.Report {
if f.Mount == nil && f.Path == nil {
return report.ReportFromError(ErrFilesystemNoMountPath, report.EntryError)
}
if f.Mount != nil && f.Path != nil {
return report.ReportFromError(ErrFilesystemMountAndPath, report.EntryError)
}
return report.Report{}
}
示例3: Validate
func (v IgnitionVersion) Validate() report.Report {
if MaxVersion.Major > v.Major {
return report.ReportFromError(ErrOldVersion, report.EntryError)
}
if MaxVersion.LessThan(semver.Version(v)) {
return report.ReportFromError(ErrNewVersion, report.EntryError)
}
return report.Report{}
}
示例4: Validate
func (d PartitionTypeGUID) Validate() report.Report {
ok, err := regexp.MatchString("^(|[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12})$", string(d))
if err != nil {
return report.ReportFromError(fmt.Errorf("error matching type-guid regexp: %v", err), report.EntryError)
}
if !ok {
return report.ReportFromError(fmt.Errorf(`partition type-guid must have the form "01234567-89AB-CDEF-EDCB-A98765432101", got: %q`, string(d)), report.EntryError)
}
return report.Report{}
}
示例5: Parse
// Parse parses the raw config into a types.Config struct and generates a report of any
// errors, warnings, info, and deprecations it encountered
func Parse(rawConfig []byte) (types.Config, report.Report, error) {
switch majorVersion(rawConfig) {
case 1:
config, err := ParseFromV1(rawConfig)
if err != nil {
return types.Config{}, report.ReportFromError(err, report.EntryError), err
}
return config, report.ReportFromError(ErrDeprecated, report.EntryDeprecated), nil
default:
return ParseFromLatest(rawConfig)
}
}
示例6: Validate
func (h Hash) Validate() report.Report {
var hash crypto.Hash
switch h.Function {
case "sha512":
hash = crypto.SHA512
default:
return report.ReportFromError(ErrHashUnrecognized, report.EntryError)
}
if len(h.Sum) != hex.EncodedLen(hash.Size()) {
return report.ReportFromError(ErrHashWrongSize, report.EntryError)
}
return report.Report{}
}
示例7: TestFilesystemFormatValidate
func TestFilesystemFormatValidate(t *testing.T) {
type in struct {
format FilesystemFormat
}
type out struct {
err error
}
tests := []struct {
in in
out out
}{
{
in: in{format: FilesystemFormat("ext4")},
out: out{},
},
{
in: in{format: FilesystemFormat("btrfs")},
out: out{},
},
{
in: in{format: FilesystemFormat("")},
out: out{err: ErrFilesystemInvalidFormat},
},
}
for i, test := range tests {
err := test.in.format.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}
示例8: Validate
func (n Raid) Validate() report.Report {
switch n.Level {
case "linear", "raid0", "0", "stripe":
if n.Spares != 0 {
return report.ReportFromError(fmt.Errorf("spares unsupported for %q arrays", n.Level), report.EntryError)
}
case "raid1", "1", "mirror":
case "raid4", "4":
case "raid5", "5":
case "raid6", "6":
case "raid10", "10":
default:
return report.ReportFromError(fmt.Errorf("unrecognized raid level: %q", n.Level), report.EntryError)
}
return report.Report{}
}
示例9: TestSystemdUnitNameValidate
func TestSystemdUnitNameValidate(t *testing.T) {
type in struct {
unit SystemdUnitName
}
type out struct {
err error
}
tests := []struct {
in in
out out
}{
{
in: in{unit: SystemdUnitName("test.service")},
out: out{err: nil},
},
{
in: in{unit: SystemdUnitName("test.socket")},
out: out{err: nil},
},
{
in: in{unit: SystemdUnitName("test.blah")},
out: out{err: errors.New("invalid systemd unit extension")},
},
}
for i, test := range tests {
err := test.in.unit.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}
示例10: Validate
func (n SystemdUnitDropInName) Validate() report.Report {
switch filepath.Ext(string(n)) {
case ".conf":
return report.Report{}
default:
return report.ReportFromError(errors.New("invalid systemd unit drop-in extension"), report.EntryError)
}
}
示例11: Validate
func (u Url) Validate() report.Report {
// Empty url is valid, indicates an empty file
if u.String() == "" {
return report.Report{}
}
switch url.URL(u).Scheme {
case "http", "https", "oem":
return report.Report{}
case "data":
if _, err := dataurl.DecodeString(u.String()); err != nil {
return report.ReportFromError(err, report.EntryError)
}
return report.Report{}
default:
return report.ReportFromError(ErrInvalidScheme, report.EntryError)
}
}
示例12: Validate
func (c Compression) Validate() report.Report {
switch c {
case "", "gzip":
default:
return report.ReportFromError(ErrCompressionInvalid, report.EntryError)
}
return report.Report{}
}
示例13: Validate
func (u Url) Validate() report.Report {
// Empty url is valid, indicates an empty file
if u.String() == "" {
return report.Report{}
}
switch url.URL(u).Scheme {
case "http", "https", "oem", "data":
return report.Report{}
}
return report.ReportFromError(ErrInvalidScheme, report.EntryError)
}
示例14: TestURLValidate
func TestURLValidate(t *testing.T) {
type in struct {
u string
}
type out struct {
err error
}
tests := []struct {
in in
out out
}{
{
in: in{u: ""},
out: out{},
},
{
in: in{u: "http://example.com"},
out: out{},
},
{
in: in{u: "https://example.com"},
out: out{},
},
{
in: in{u: "oem:///foobar"},
out: out{},
},
{
in: in{u: "data:,example%20file%0A"},
out: out{},
},
{
in: in{u: "bad://"},
out: out{err: ErrInvalidScheme},
},
}
for i, test := range tests {
u, err := url.Parse(test.in.u)
if err != nil {
t.Errorf("URL failed to parse. This is an error with the test")
}
r := Url(*u).Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), r) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, r)
}
}
}
示例15: TestFileValidate
func TestFileValidate(t *testing.T) {
type in struct {
mode FileMode
}
type out struct {
err error
}
tests := []struct {
in in
out out
}{
{
in: in{mode: FileMode(0)},
out: out{},
},
{
in: in{mode: FileMode(0644)},
out: out{},
},
{
in: in{mode: FileMode(01755)},
out: out{},
},
{
in: in{mode: FileMode(07777)},
out: out{},
},
{
in: in{mode: FileMode(010000)},
out: out{err: ErrFileIllegalMode},
},
}
for i, test := range tests {
err := test.in.mode.Validate()
if !reflect.DeepEqual(report.ReportFromError(test.out.err, report.EntryError), err) {
t.Errorf("#%d: bad error: want %v, got %v", i, test.out.err, err)
}
}
}