Skip to content

Commit

Permalink
Make the tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
amishas157 committed Aug 6, 2024
1 parent c391e61 commit 687ff9d
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cmd/export_ledgers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ func sortByName(files []os.DirEntry) {
})
}

func runCLITestDefault(t *testing.T, test cliTest, goldenFolder string, update_in bool) {
update = &update_in
fmt.Println(update)
runCLITest(t, test, goldenFolder)
}

func runCLITest(t *testing.T, test cliTest, goldenFolder string) {
t.Run(test.name, func(t *testing.T) {
dir, err := os.Getwd()
Expand All @@ -141,6 +147,10 @@ func runCLITest(t *testing.T, test cliTest, goldenFolder string) {
outLocation := test.args[idxOfOutputArg+1]
stat, err := os.Stat(outLocation)
assert.NoError(t, err)
// _, err = clearOutputFile(outLocation)
// if err != nil {
// log.Fatal(err)
// }

// If the output arg specified is a directory, concat the contents for comparison.
if stat.IsDir() {
Expand Down Expand Up @@ -205,6 +215,19 @@ func getLastSeqNum(archiveURLs []string) uint32 {
return num
}

func clearOutputFile(outputFile string) (string, error) {
f, err := os.OpenFile(outputFile, os.O_RDWR, 0644)
if err != nil {
return "", err
}
defer f.Close()
err = os.Truncate(outputFile, 0)
if err != nil {
return "", err
}
return "", nil
}

func getGolden(t *testing.T, goldenFile string, actual string, update bool) (string, error) {
t.Helper()
f, err := os.OpenFile(goldenFile, os.O_RDWR, 0644)
Expand Down
11 changes: 9 additions & 2 deletions cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import (
)

func TestIntegration(t *testing.T) {
tests := []cliTest{}
tests := []cliTest{
{
name: "transactions from one ledger",
args: []string{"export_transactions", "-s", "30820015", "-e", "30820015", "-o", gotTestDir(t, "one_ledger_txs.txt")},
golden: "one_ledger_txs.golden",
wantErr: nil,
},
}

for _, test := range tests {
fmt.Println(test)
runCLITest(t, test, "testdata/transactions/")
runCLITestDefault(t, test, "testdata/integration/", false)
}
}
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ services:
dockerfile: docker/Dockerfile.test
container_name: stellar-etl-integration-tests
restart: always
volumes:
- $HOME/.config/gcloud/application_default_credentials.json:/usr/credential.json:ro
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/usr/credential.json
Loading

0 comments on commit 687ff9d

Please sign in to comment.