fix lint errors
Some checks failed
Lint / golangci-lint (push) Failing after 9m59s
Declarative Tests / test (push) Successful in 1m48s

This commit is contained in:
Matthew Rich 2024-04-21 23:11:17 -07:00
parent 86264c1202
commit 85cff22da4
5 changed files with 32 additions and 20 deletions

View File

@ -83,7 +83,11 @@ func LoadSourceURI(uri string) []*resource.Document {
func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
ImportResource = cmd.String("resource", "", "(uri) Add a resource to the document.")
ImportMerge = cmd.Bool("merge", false, "Merge resources into a single document.")
cmd.Parse(os.Args[2:])
e := cmd.Parse(os.Args[2:])
if e != nil { // returns ErrHelp
return e
}
var encoder resource.Encoder
merged := resource.NewDocument()
documents := make([]*resource.Document, 0, 100)
@ -117,7 +121,9 @@ func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
if *GlobalQuiet {
for _, dr := range d.Resources() {
output.Write([]byte(dr.Resource().URI()))
if _,e := output.Write([]byte(dr.Resource().URI())); e != nil {
return e
}
}
} else {
if *ImportMerge {
@ -140,7 +146,9 @@ func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
}
func ApplySubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
cmd.Parse(os.Args[2:])
if e := cmd.Parse(os.Args[2:]); e != nil {
return e
}
var encoder resource.Encoder
documents := make([]*resource.Document, 0, 100)
for _,source := range cmd.Args() {
@ -165,7 +173,9 @@ func ApplySubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
}
if *GlobalQuiet {
for _, dr := range d.Resources() {
output.Write([]byte(dr.Resource().URI()))
if _,e := output.Write([]byte(dr.Resource().URI())); e != nil {
return e
}
}
} else {
if documentGenerateErr := encoder.Encode(d); documentGenerateErr != nil {
@ -177,7 +187,9 @@ func ApplySubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
}
func DiffSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
cmd.Parse(os.Args[2:])
if e := cmd.Parse(os.Args[2:]); e != nil {
return e
}
leftSource := cmd.Arg(0)
rightSource := cmd.Arg(1)
leftDocuments := make([]*resource.Document, 0, 100)

View File

@ -137,7 +137,10 @@ func (d *Document) Diff(with *Document, output io.Writer) (string, error) {
for _,diff := range yamldiff.Do(yamlDiff, withDiff, opts...) {
slog.Info("Diff()", "diff", diff)
fmt.Printf("yaml %#v with %#v\n", yamlDiff, withDiff)
output.Write([]byte(diff.Dump()))
_,e := output.Write([]byte(diff.Dump()))
if e != nil {
return "", e
}
}
slog.Info("Document.Diff() ", "document.yaml", ydata, "with.yaml", wdata)
if stringOutput, ok := output.(*strings.Builder); ok {

View File

@ -215,7 +215,8 @@ func TestFileUpdateAttributesFromFileInfo(t *testing.T) {
info, e := os.Lstat(TempDir)
assert.Nil(t, e)
f.UpdateAttributesFromFileInfo(info)
updateAttributesErr := f.UpdateAttributesFromFileInfo(info)
assert.Nil(t, updateAttributesErr)
assert.Equal(t, DirectoryFile, f.FileType)
}

View File

@ -25,7 +25,9 @@ type Ident struct {
func NewIdent() *Ident {
i := &Ident{}
i.authorized = []string{ "*" }
i.Generate()
if e := i.Generate(); e != nil {
return nil
}
return i
}

View File

@ -39,7 +39,6 @@ func (d *HTTP) Type() string { return "http" }
func (h *HTTP) ExtractResources(filter ResourceSelector) ([]*resource.Document, error) {
documents := make([]*resource.Document, 0, 100)
documents = append(documents, resource.NewDocument())
resp, err := http.Get(h.Endpoint)
if err != nil {
@ -67,12 +66,9 @@ func (h *HTTP) ExtractResources(filter ResourceSelector) ([]*resource.Document,
decoder := resource.NewYAMLDecoder(sumReadData)
index := 0
for {
doc := documents[index]
doc := resource.NewDocument()
e := decoder.Decode(doc)
if errors.Is(e, io.EOF) {
if len(documents) > 1 {
documents[index] = nil
}
break
}
if e != nil {
@ -81,18 +77,16 @@ func (h *HTTP) ExtractResources(filter ResourceSelector) ([]*resource.Document,
if validationErr := doc.Validate(); validationErr != nil {
return documents, validationErr
}
/*
if applyErr := doc.Apply(); applyErr != nil {
return documents, applyErr
}
*/
documents = append(documents, resource.NewDocument())
documents = append(documents, doc)
index++
}
if documentSignature != "" {
sig := &signature.Ident{}
sig.VerifySum(hash.Sum(nil), []byte(documentSignature))
sigErr := sig.VerifySum(hash.Sum(nil), []byte(documentSignature))
if sigErr != nil {
return documents, sigErr
}
}
return documents, nil