remove duplicate tempdir pkg
This commit is contained in:
parent
88fe584fe1
commit
d815419c7b
@ -12,7 +12,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"fmt"
|
"fmt"
|
||||||
"decl/tests/tempdir"
|
"decl/internal/tempdir"
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"decl/tests/tempdir"
|
"decl/internal/tempdir"
|
||||||
"decl/internal/folio"
|
"decl/internal/folio"
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
@ -153,9 +153,14 @@ func (d *Declaration) Resource() data.Resource {
|
|||||||
func (d *Declaration) Apply(stateTransition string) (result error) {
|
func (d *Declaration) Apply(stateTransition string) (result error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
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)
|
result = fmt.Errorf("%s", r)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if result != nil {
|
if result != nil {
|
||||||
d.Error = result.Error()
|
d.Error = result.Error()
|
||||||
}
|
}
|
||||||
@ -192,12 +197,13 @@ func (d *Declaration) Apply(stateTransition string) (result error) {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = stater.Trigger("read")
|
result = stater.Trigger("read")
|
||||||
currentState := stater.CurrentState()
|
currentState := stater.CurrentState()
|
||||||
switch currentState {
|
switch currentState {
|
||||||
case "create", "present":
|
case "create", "present":
|
||||||
default:
|
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
|
return result
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
_ "os"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/url"
|
"net/url"
|
||||||
"github.com/sters/yaml-diff/yamldiff"
|
"github.com/sters/yaml-diff/yamldiff"
|
||||||
@ -275,9 +276,11 @@ func (d *Document) Apply(state string) error {
|
|||||||
|
|
||||||
if d.ResourceDeclarations[idx].Requires.Check() {
|
if d.ResourceDeclarations[idx].Requires.Check() {
|
||||||
|
|
||||||
if e := d.ResourceDeclarations[idx].Apply(state); e != nil {
|
// fmt.Fprintf(os.Stderr, "%s: ", d.ResourceDeclarations[idx].Resource().URI())
|
||||||
slog.Error("Document.Apply() error applying resource", "index", idx, "uri", 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()
|
d.ResourceDeclarations[idx].Error = e.Error()
|
||||||
switch d.ResourceDeclarations[idx].OnError.GetStrategy() {
|
switch d.ResourceDeclarations[idx].OnError.GetStrategy() {
|
||||||
case OnErrorStop:
|
case OnErrorStop:
|
||||||
@ -285,6 +288,8 @@ func (d *Document) Apply(state string) error {
|
|||||||
case OnErrorFail:
|
case OnErrorFail:
|
||||||
d.failedResources++
|
d.failedResources++
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// fmt.Fprintf(os.Stderr, "%s\n", state)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires)
|
d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"os"
|
"os"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"decl/tests/tempdir"
|
"decl/internal/tempdir"
|
||||||
_ "path/filepath"
|
_ "path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user