Skip to content

Commit

Permalink
chore: fix test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Nov 16, 2023
1 parent a333001 commit 4c95908
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
10 changes: 5 additions & 5 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ func TestConfig(t *testing.T) {
{
name: "default config",
config: NewDefaultConfig(),
store: &CachingValidatingStore{ConfigStore: &YamlFileStore{Path: dir + "/default-config.yaml"}},
store: &CachingValidatingStore{ConfigStore: &JsonFileStore{Path: dir + "/default-config.json"}},
},
{
name: "simple valid config",
config: &v1.Config{
Repos: []*v1.Repo{testRepo},
Plans: []*v1.Plan{testPlan},
},
store: &CachingValidatingStore{ConfigStore: &YamlFileStore{Path: dir + "/valid-config.yaml"}},
store: &CachingValidatingStore{ConfigStore: &JsonFileStore{Path: dir + "/valid-config.json"}},
},
{
name: "plan references non-existent repo",
config: &v1.Config{
Plans: []*v1.Plan{testPlan},
},
store: &CachingValidatingStore{ConfigStore: &YamlFileStore{Path: dir + "/invalid-config.yaml"}},
store: &CachingValidatingStore{ConfigStore: &JsonFileStore{Path: dir + "/invalid-config.json"}},
wantErr: true,
wantErrContains: "repo \"test-repo\" not found",
},
Expand All @@ -62,7 +62,7 @@ func TestConfig(t *testing.T) {
testRepo,
},
},
store: &CachingValidatingStore{ConfigStore: &YamlFileStore{Path: dir + "/invalid-config2.yaml"}},
store: &CachingValidatingStore{ConfigStore: &JsonFileStore{Path: dir + "/invalid-config2.json"}},
wantErr: true,
wantErrContains: "repo test-repo: duplicate id",
},
Expand All @@ -81,7 +81,7 @@ func TestConfig(t *testing.T) {
},
},
},
store: &CachingValidatingStore{ConfigStore: &YamlFileStore{Path: dir + "/invalid-config3.yaml"}},
store: &CachingValidatingStore{ConfigStore: &JsonFileStore{Path: dir + "/invalid-config3.json"}},
wantErr: true,
wantErrContains: "invalid cron \"bad cron\"",
},
Expand Down
42 changes: 41 additions & 1 deletion internal/database/oplog/oplog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,50 @@ func TestAddOperation(t *testing.T) {
wantErr bool
}{
{
name: "basic operation",
name: "no operation",
op: &v1.Operation{
Id: 0,
},
wantErr: true,
},
{
name: "basic backup operation",
op: &v1.Operation{
Id: 0,
Op: &v1.Operation_OperationBackup{},
},
wantErr: false,
},
{
name: "basic snapshot operation",
op: &v1.Operation{
Id: 0,
Op: &v1.Operation_OperationIndexSnapshot{
OperationIndexSnapshot: &v1.OperationIndexSnapshot{
Snapshot: &v1.ResticSnapshot{
Id: "test",
},
},
},
},
wantErr: false,
},
{
name: "basic snapshot operation with no snapshot",
op: &v1.Operation{
Id: 0,
Op: &v1.Operation_OperationIndexSnapshot{
OperationIndexSnapshot: &v1.OperationIndexSnapshot{
},
},
},
wantErr: true,
},
{
name: "operation with ID",
op: &v1.Operation{
Id: 1,
Op: &v1.Operation_OperationBackup{},
},
wantErr: true,
},
Expand All @@ -50,13 +84,15 @@ func TestAddOperation(t *testing.T) {
op: &v1.Operation{
Id: 0,
RepoId: "testrepo",
Op: &v1.Operation_OperationBackup{},
},
},
{
name: "operation with plan",
op: &v1.Operation{
Id: 0,
PlanId: "testplan",
Op: &v1.Operation_OperationBackup{},
},
},
}
Expand Down Expand Up @@ -88,16 +124,19 @@ func TestListOperation(t *testing.T) {
PlanId: "plan1",
RepoId: "repo1",
DisplayMessage: "op1",
Op: &v1.Operation_OperationBackup{},
},
{
PlanId: "plan1",
RepoId: "repo2",
DisplayMessage: "op2",
Op: &v1.Operation_OperationBackup{},
},
{
PlanId: "plan2",
RepoId: "repo2",
DisplayMessage: "op3",
Op: &v1.Operation_OperationBackup{},
},
}

Expand Down Expand Up @@ -175,6 +214,7 @@ func TestBigIO(t *testing.T) {
if err := log.Add(&v1.Operation{
PlanId: "plan1",
RepoId: "repo1",
Op: &v1.Operation_OperationBackup{},
}); err != nil {
t.Fatalf("error adding operation: %s", err)
}
Expand Down
3 changes: 3 additions & 0 deletions internal/database/serializationutil/serializationutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ func BytesToKey(b []byte) []byte {
}

func NormalizeSnapshotId(id string) string {
if len(id) < 8 {
return id
}
return id[:8]
}
4 changes: 2 additions & 2 deletions internal/database/serializationutil/serializationutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ func TestItoa(t *testing.T) {
nums := []int64{0, 1, 2, 3, 4, 1 << 32, int64(1) << 62}
for _, num := range nums {
b := Itob(num)
if Btoi(b) != num {
if v, _ := Btoi(b); v != num {
t.Errorf("itob/btoi failed for %d", num)
}
}
Expand All @@ -16,7 +16,7 @@ func TestStob(t *testing.T) {
strs := []string{"", "a", "ab", "abc", "abcd", "abcde", "abcdef"}
for _, str := range strs {
b := Stob(str)
if val, _ := Btos(b); val != str {
if val, _, _ := Btos(b); val != str {
t.Errorf("stob/btos failed for %s", str)
}
}
Expand Down

0 comments on commit 4c95908

Please sign in to comment.