-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ignore: | ||
- "internal/**/*" | ||
- "cmd/**/*" | ||
- "docs/*" | ||
- "**/pkg/model/*" | ||
- "**/pkg/shared/*" | ||
- "**/pkg/stdio/*" | ||
- "**/pkg/service/backup_*.go" | ||
- "**/pkg/service/configuration_manager_*.go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aerospike/backup/pkg/model" | ||
"github.com/aerospike/backup/pkg/util" | ||
) | ||
|
||
func TestRestoreMemory(t *testing.T) { | ||
restoreService := NewRestoreMemory() | ||
restoreRequest := &model.RestoreRequest{ | ||
Host: util.Ptr("localhost"), | ||
Port: util.Ptr(int32(3000)), | ||
Directory: util.Ptr("./testout/backup"), | ||
SetList: []string{"set1"}, | ||
} | ||
jobID := restoreService.Restore(restoreRequest) | ||
|
||
jobStatus := restoreService.JobStatus(jobID) | ||
if jobStatus != jobStatusRunning { | ||
t.Errorf("Expected jobStatus to be %s", jobStatusRunning) | ||
} | ||
|
||
wrongJobStatus := restoreService.JobStatus(1111) | ||
if wrongJobStatus != jobStatusNA { | ||
t.Errorf("Expected jobStatus to be %s", jobStatusNA) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package util | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestLoadingCache(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
cache := NewLoadingCache(ctx, func(s string) (any, error) { | ||
return strconv.Atoi(s) | ||
}) | ||
value, _ := cache.Get("1") | ||
if value != 1 { | ||
t.Error("The value is expected to be 1") | ||
} | ||
value, _ = cache.Get("1") // existing | ||
if value != 1 { | ||
t.Error("The value is expected to be 1") | ||
} | ||
go cache.startCleanup() | ||
cancel() | ||
cache.clean() | ||
value, _ = cache.Get("2") | ||
if value != 2 { | ||
t.Error("The value is expected to be 2") | ||
} | ||
} | ||
|
||
func TestLoadingCache_Error(t *testing.T) { | ||
cache := NewLoadingCache(context.Background(), func(s string) (any, error) { | ||
return nil, errors.New("error") | ||
}) | ||
_, err := cache.Get("1") | ||
if err == nil { | ||
t.Error("Error must not be nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package util | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_libLogRegex(t *testing.T) { | ||
tests := []string{ | ||
"2023-01-01 00:00:00 UTC [INF] [74813] Starting backup for 4096 partitions from 0 to 4095", | ||
"2023-11-08 09:44:48 GMT [ERR] [ 14] The max S3 object size is 5497558138880"} | ||
"2023-11-08 09:44:48 GMT [ERR] [ 14] The max S3 object size is 5497558138880", | ||
} | ||
|
||
for _, e := range tests { | ||
match := libLogRegex.FindStringSubmatch(e) | ||
if len(match) != 5 { | ||
t.Fatal("libLogRegex error") | ||
} | ||
} | ||
LogCaptured(strings.Join(tests, "\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPtr(t *testing.T) { | ||
var n int32 | ||
np := Ptr(n) | ||
if n != *np { | ||
t.Error("Expected to be equal") | ||
} | ||
} | ||
|
||
func TestFind(t *testing.T) { | ||
elements := map[string]int{"a": 1} | ||
_, found := Find(elements, func(i int) bool { return i == 1 }) | ||
if !found { | ||
t.Error("Expected to be found") | ||
} | ||
_, found = Find(elements, func(i int) bool { return i == 2 }) | ||
if found { | ||
t.Error("Expected not to be found") | ||
} | ||
} |