* support flags commands, move to cmd * fix target name * test for happy path importer * add export cmd * fix wrong import, lint warns * increase test timeout * add sellp to allow main test server to start * implement all cmds * handle backup/restore errors * fix import status check, hide secret from logs * backup cmd err tests * randimize test port * avoid dup code in Last controller * add target to make all bin archives * remove container in make * add smiple scripts to simplify commands, update readme * add docs on dockerless, enforce app user * add restore info * move last to lastCommentsScope const
38 lines
965 B
Go
38 lines
965 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
flags "github.com/jessevdk/go-flags"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRestore_Execute(t *testing.T) {
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
assert.Equal(t, r.URL.Path, "/api/v1/admin/import")
|
|
assert.Equal(t, "POST", r.Method)
|
|
assert.Equal(t, "native", r.URL.Query().Get("provider"))
|
|
body, err := ioutil.ReadAll(r.Body)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, "blah\nblah2\n12345678\n", string(body))
|
|
|
|
fmt.Fprintln(w, "some response")
|
|
fmt.Fprintln(w, string(body))
|
|
}))
|
|
defer ts.Close()
|
|
|
|
cmd := RestoreCommand{}
|
|
p := flags.NewParser(&cmd, flags.Default)
|
|
_, err := p.ParseArgs([]string{"--secret=123456", "--site=remark", "--path=testdata", "--file=import.txt",
|
|
"--url=" + ts.URL})
|
|
require.Nil(t, err)
|
|
err = cmd.Execute(nil)
|
|
assert.NoError(t, err)
|
|
}
|