fixed export, added tests for it, made tests more accurate, and excluded things from gitignore

This commit is contained in:
David Dworken 2022-04-06 23:05:30 -07:00
parent 7a6aece6dc
commit 581231d0ef
6 changed files with 15 additions and 9 deletions

5
.gitignore vendored
View File

@ -1,4 +1 @@
client
server
!client/
!server/
web/landing/www/binaries/hishtory-linux

View File

@ -2,7 +2,7 @@ test:
HISHTORY_TEST=1 go test -p 1 ./...
build-binary:
go build -o web/landing/www/binaries/hishtory-linux -ldflags "-X main.GitCommit=`git rev-list -1 HEAD`" client/client.go
go build -trimpath -o web/landing/www/binaries/hishtory-linux -ldflags "-X main.GitCommit=`git rev-list -1 HEAD`" client/client.go
build-static: build-binary
docker build -t gcr.io/dworken-k8s/hishtory-static -f web/caddy/Dockerfile .

View File

@ -152,7 +152,7 @@ func export() {
lib.CheckFatalError(retrieveAdditionalEntriesFromRemote(db))
data, err := shared.Search(db, "", 0)
lib.CheckFatalError(err)
for _, entry := range data {
fmt.Println(entry)
for i := len(data)-1; i >= 0; i-- {
fmt.Println(data[i].Command)
}
}

View File

@ -24,7 +24,11 @@ func RunInteractiveBashCommands(t *testing.T, script string) string {
var err bytes.Buffer
cmd.Stderr = &err
shared.CheckWithInfo(t, cmd.Run(), out.String()+err.String())
return out.String()
outStr := out.String()
if strings.Contains(outStr, "hishtory fatal error:") {
t.Fatalf("Ran command, but hishtory had a fatal error! out=%#v", outStr)
}
return outStr
}
func TestIntegration(t *testing.T) {
@ -150,6 +154,12 @@ func TestIntegrationWithNewDevice(t *testing.T) {
if !strings.Contains(out, "othercomputer") {
t.Fatalf("hishtory query doesn't contain cmd run on another machine! out=%#v", out)
}
// Finally, test the export command
out = RunInteractiveBashCommands(t, `hishtory export`)
if out != fmt.Sprintf("/tmp/client install\n/tmp/client install\nhishtory status\nhishtory query\nhishtory query\nls /a\nls /bar\nls /foo\necho foo\necho bar\nhishtory enable\necho thisisrecorded\nhishtory query\nhishtory query foo\n/tmp/client install %s\nhishtory query\necho mynewcommand\nhishtory query\nhishtory init %s\nhishtory query\necho mynewercommand\nhishtory query\nothercomputer\nhishtory query\n", userSecret, userSecret) {
t.Fatalf("hishtory export had unexpected output! out=%#v", out)
}
}
func testIntegration(t *testing.T) string {
@ -233,4 +243,3 @@ func testIntegration(t *testing.T) string {
return userSecret
}
// TODO(ddworken): Test export

BIN
hishtory

Binary file not shown.