feat(tfstated): implement states versioning
This commit is contained in:
parent
71702002cf
commit
3319e74279
5 changed files with 56 additions and 36 deletions
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
|
@ -20,12 +18,7 @@ func handleGet(db *database.DB) http.Handler {
|
|||
}
|
||||
|
||||
if data, err := db.GetState(r.URL.Path); err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
_ = errorResponse(w, http.StatusNotFound,
|
||||
fmt.Errorf("state path not found: %s", r.URL.Path))
|
||||
} else {
|
||||
_ = errorResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
_ = errorResponse(w, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(data)
|
||||
|
|
|
@ -18,7 +18,7 @@ func TestGet(t *testing.T) {
|
|||
msg string
|
||||
}{
|
||||
{"GET", &url.URL{Path: "/"}, nil, "", http.StatusBadRequest, "/"},
|
||||
{"GET", &url.URL{Path: "/non_existent_get"}, nil, "", http.StatusNotFound, "non existent"},
|
||||
{"GET", &url.URL{Path: "/non_existent_get"}, strings.NewReader(""), "", http.StatusOK, "non existent"},
|
||||
{"POST", &url.URL{Path: "/test_get"}, strings.NewReader("the_test_get"), "", http.StatusOK, "/test_get"},
|
||||
{"GET", &url.URL{Path: "/test_get"}, nil, "the_test_get", http.StatusOK, "/test_get"},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue