feat(tfstated): implement states versioning

This commit is contained in:
Julien Dessaux 2024-10-14 23:54:49 +02:00
parent 71702002cf
commit 3319e74279
Signed by: adyxax
GPG key ID: F92E51B86E07177E
5 changed files with 56 additions and 36 deletions

View file

@ -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)

View file

@ -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"},
}