remove duplicate tempdir pkg
Some checks failed
Lint / golangci-lint (push) Failing after 10m28s
Declarative Tests / test (push) Failing after 12s
Declarative Tests / build-fedora (push) Failing after 1m57s
Declarative Tests / build-ubuntu-focal (push) Successful in 1m50s

This commit is contained in:
Matthew Rich 2024-09-27 03:18:13 +00:00
parent 88fe584fe1
commit d815419c7b
5 changed files with 19 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import (
"net/http"
"net/http/httptest"
"fmt"
"decl/tests/tempdir"
"decl/internal/tempdir"
"archive/tar"
"io"
"log"

View File

@ -7,7 +7,7 @@ import (
"log/slog"
"os"
"testing"
"decl/tests/tempdir"
"decl/internal/tempdir"
"decl/internal/folio"
"errors"
)

View File

@ -153,9 +153,14 @@ func (d *Declaration) Resource() data.Resource {
func (d *Declaration) Apply(stateTransition string) (result error) {
defer func() {
if r := recover(); r != nil {
slog.Info("Declaration.Apply()", "error", r, "stacktrace", string(debug.Stack()))
slog.Debug("Declaration.Apply()", "stacktrace", string(debug.Stack()))
slog.Info("Declaration.Apply()", "error", r, "resourceerror", d.Error)
if d.Error != "" {
result = fmt.Errorf("%s - %s", r, d.Error)
} else {
result = fmt.Errorf("%s", r)
}
}
if result != nil {
d.Error = result.Error()
}
@ -192,12 +197,13 @@ func (d *Declaration) Apply(stateTransition string) (result error) {
return result
}
}
result = stater.Trigger("read")
currentState := stater.CurrentState()
switch currentState {
case "create", "present":
default:
return fmt.Errorf("Failed to create resource: %s - state: %s, err: %s", d.URI(), currentState, result)
return fmt.Errorf("Failed to create resource: %s - state: %s, err: %s", d.URI(), currentState, d.Error)
}
}
return result

View File

@ -8,6 +8,7 @@ import (
"gopkg.in/yaml.v3"
"io"
"io/fs"
_ "os"
"log/slog"
"net/url"
"github.com/sters/yaml-diff/yamldiff"
@ -275,9 +276,11 @@ func (d *Document) Apply(state string) error {
if d.ResourceDeclarations[idx].Requires.Check() {
if e := d.ResourceDeclarations[idx].Apply(state); e != nil {
slog.Error("Document.Apply() error applying resource", "index", idx, "uri", d.ResourceDeclarations[idx].Resource().URI())
// fmt.Fprintf(os.Stderr, "%s: ", d.ResourceDeclarations[idx].Resource().URI())
if e := d.ResourceDeclarations[idx].Apply(state); e != nil {
// slog.Error("Document.Apply() error applying resource", "index", idx, "uri", d.ResourceDeclarations[idx].Resource().URI(), "error", e)
// fmt.Fprintf(os.Stderr, "%s\n", "error")
d.ResourceDeclarations[idx].Error = e.Error()
switch d.ResourceDeclarations[idx].OnError.GetStrategy() {
case OnErrorStop:
@ -285,6 +288,8 @@ func (d *Document) Apply(state string) error {
case OnErrorFail:
d.failedResources++
}
} else {
// fmt.Fprintf(os.Stderr, "%s\n", state)
}
} else {
d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires)

View File

@ -7,7 +7,7 @@ import (
"testing"
"os"
"log/slog"
"decl/tests/tempdir"
"decl/internal/tempdir"
_ "path/filepath"
)