From 86c880f60c6a428a27635b339267b429eb09fe80 Mon Sep 17 00:00:00 2001 From: Felipe Cardozo Date: Fri, 17 Nov 2023 10:24:38 -0300 Subject: [PATCH] add more tests and logs --- cmd/photographer/exec.go | 2 ++ cmd/photographer/main.go | 4 ++-- pkg/store/fileinfo_test.go | 39 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 pkg/store/fileinfo_test.go diff --git a/cmd/photographer/exec.go b/cmd/photographer/exec.go index b5348e1..da51ab4 100644 --- a/cmd/photographer/exec.go +++ b/cmd/photographer/exec.go @@ -39,8 +39,10 @@ func getSnapshotName(historyMode snapshot.HistoryModeType) (string, error) { } func getSnapshotHeaderOutput(filepath string) string { + log.Printf("Getting snapshot header output for file: %q. \n", filepath) script := "/usr/local/bin/octez-node snapshot info --json" + filepath stdout, _ := execScript(script) + log.Printf("Snapshot header output: %q. \n", stdout.String()) return stdout.String() } diff --git a/cmd/photographer/main.go b/cmd/photographer/main.go index 8e27224..a1ee320 100644 --- a/cmd/photographer/main.go +++ b/cmd/photographer/main.go @@ -83,10 +83,10 @@ func execute(ctx context.Context, snapshotStorage *store.SnapshotStorage, histor createSnapshot(historyMode) snapshotfilename, err := getSnapshotName(historyMode) - snapshotHeaderOutput := getSnapshotHeaderOutput(snapshotfilename) - if err != nil { log.Fatalf("%v \n", err) } + snapshotHeaderOutput := getSnapshotHeaderOutput(snapshotfilename) + snapshotStorage.EphemeralUpload(ctx, snapshotfilename, snapshotHeaderOutput) } diff --git a/pkg/store/fileinfo_test.go b/pkg/store/fileinfo_test.go new file mode 100644 index 0000000..f47e824 --- /dev/null +++ b/pkg/store/fileinfo_test.go @@ -0,0 +1,39 @@ +package store + +import ( + "testing" +) + +func Test_fileinfo(t *testing.T) { + tests := []struct { + name string + args []string + want []string + }{ + { + name: "Test_fileinfo", + args: []string{ + "TEZOS_HANGZHOUNET_2022-01-22T15:00:00Z-BKpkmdGCx8D9KAUAYJrrrmFqgamcwZWFYo2W4KiyEP4PCBJQrsC-589926.full", + "TEZOS_ITHACANET_2022-01-22T15:00:00Z-BKpkmdGCx8D9KAUAYJrrrmFqgamcwZWFYo2W4KiyEP4PCBJQrsC-589926.rolling", + "TEZOS_MAINNET-BL4p3YRfxhiQP16PsuzFBbph8QqVcNN3qu42r5JgNgdaw3xW81g-2396664.rolling", + "TEZOS_MAINNET-BMBDsvNoA4wr4VANmUJfMPPEpCKKBYY7xBoYfhJkUuoGk54GYPa-4593763.rolling", + }, + want: []string{ + "hangzhounet", + "ghostnet", + "mainnet", + "mainnet", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + for i, want := range tt.want { + got := getInfoFromfilename(tt.args[i]) + if got.ChainName != want { + t.Errorf("got: %v, want: %v", got, want) + } + } + }) + } +}