Skip to content

Commit

Permalink
fix(database): integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp committed Jun 30, 2023
1 parent b432a66 commit db6e2f0
Showing 1 changed file with 126 additions and 1 deletion.
127 changes: 126 additions & 1 deletion database/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func testBuilds(t *testing.T, db Interface, resources *Resources) {
t.Errorf("unable to get last build for repo %d: %v", resources.Repos[0].GetID(), err)
}
if !reflect.DeepEqual(got, resources.Builds[1]) {
t.Errorf("GetBuildForRepo() is %v, want %v", got, resources.Builds[1])
t.Errorf("LastBuildForRepo() is %v, want %v", got, resources.Builds[1])
}
counter++

Expand Down Expand Up @@ -383,6 +383,16 @@ func testHooks(t *testing.T, db Interface, resources *Resources) {
}
counter++

// count the hooks for a repo
count, err = db.CountHooksForRepo(resources.Repos[0])
if err != nil {
t.Errorf("unable to count hooks for repo %d: %v", resources.Repos[0].GetID(), err)
}
if int(count) != len(resources.Builds) {
t.Errorf("CountHooksForRepo() is %v, want %v", count, len(resources.Builds))
}
counter++

// list the hooks
list, err := db.ListHooks()
if err != nil {
Expand All @@ -393,6 +403,29 @@ func testHooks(t *testing.T, db Interface, resources *Resources) {
}
counter++

// list the hooks for a repo
list, count, err = db.ListHooksForRepo(resources.Repos[0], 1, 10)
if err != nil {
t.Errorf("unable to list hooks for repo %d: %v", resources.Repos[0].GetID(), err)
}
if int(count) != len(resources.Hooks) {
t.Errorf("ListHooksForRepo() is %v, want %v", count, len(resources.Hooks))
}
if !reflect.DeepEqual(list, resources.Hooks) {
t.Errorf("ListHooks() is %v, want %v", list, resources.Hooks)
}
counter++

// lookup the last build by repo
got, err := db.LastHookForRepo(resources.Repos[0])
if err != nil {
t.Errorf("unable to get last hook for repo %d: %v", resources.Repos[0].GetID(), err)
}
if !reflect.DeepEqual(got, resources.Hooks[1]) {
t.Errorf("LastHookForRepo() is %v, want %v", got, resources.Hooks[1])
}
counter++

// lookup the hooks by name
for _, hook := range resources.Hooks {
repo := resources.Repos[hook.GetRepoID()-1]
Expand Down Expand Up @@ -468,6 +501,16 @@ func testLogs(t *testing.T, db Interface, resources *Resources) {
}
counter++

// count the logs for a build
count, err = db.CountLogsForBuild(resources.Builds[0])
if err != nil {
t.Errorf("unable to count logs for build %d: %v", resources.Builds[0].GetID(), err)
}
if int(count) != len(resources.Logs) {
t.Errorf("CountLogs() is %v, want %v", count, len(resources.Logs))
}
counter++

// list the logs
list, err := db.ListLogs()
if err != nil {
Expand All @@ -478,6 +521,19 @@ func testLogs(t *testing.T, db Interface, resources *Resources) {
}
counter++

// list the logs for a build
list, count, err = db.ListLogsForBuild(resources.Builds[0], 1, 10)
if err != nil {
t.Errorf("unable to list logs for build %d: %v", resources.Builds[0].GetID(), err)
}
if int(count) != len(resources.Logs) {
t.Errorf("ListLogsForBuild() is %v, want %v", count, len(resources.Logs))
}
if !reflect.DeepEqual(list, resources.Logs) {
t.Errorf("ListLogsForBuild() is %v, want %v", list, resources.Logs)
}
counter++

// lookup the logs by service
for _, log := range []*library.Log{resources.Logs[0], resources.Logs[1]} {
service := resources.Services[log.GetServiceID()-1]
Expand Down Expand Up @@ -566,6 +622,16 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) {
}
counter++

// count the pipelines for a repo
count, err = db.CountPipelinesForRepo(resources.Repos[0])
if err != nil {
t.Errorf("unable to count pipelines for repo %d: %v", resources.Repos[0].GetID(), err)
}
if int(count) != len(resources.Pipelines) {
t.Errorf("CountPipelinesForRepo() is %v, want %v", count, len(resources.Pipelines))
}
counter++

// list the pipelines
list, err := db.ListPipelines()
if err != nil {
Expand All @@ -576,6 +642,19 @@ func testPipelines(t *testing.T, db Interface, resources *Resources) {
}
counter++

// list the pipelines for a repo
list, count, err = db.ListPipelinesForRepo(resources.Repos[0], 1, 10)
if err != nil {
t.Errorf("unable to list pipelines for repo %d: %v", resources.Repos[0].GetID(), err)
}
if int(count) != len(resources.Pipelines) {
t.Errorf("ListPipelinesForRepo() is %v, want %v", count, len(resources.Pipelines))
}
if !reflect.DeepEqual(list, resources.Pipelines) {
t.Errorf("ListPipelines() is %v, want %v", list, resources.Pipelines)
}
counter++

// lookup the pipelines by name
for _, pipeline := range resources.Pipelines {
repo := resources.Repos[pipeline.GetRepoID()-1]
Expand Down Expand Up @@ -651,6 +730,26 @@ func testRepos(t *testing.T, db Interface, resources *Resources) {
}
counter++

// count the repos for an org
count, err = db.CountReposForOrg(resources.Repos[0].GetOrg(), nil)
if err != nil {
t.Errorf("unable to count repos for org %s: %v", resources.Repos[0].GetOrg(), err)
}
if int(count) != len(resources.Repos) {
t.Errorf("CountReposForOrg() is %v, want %v", count, len(resources.Repos))
}
counter++

// count the repos for a user
count, err = db.CountReposForUser(resources.Users[0], nil)
if err != nil {
t.Errorf("unable to count repos for user %d: %v", resources.Users[0].GetID(), err)
}
if int(count) != len(resources.Repos) {
t.Errorf("CountReposForUser() is %v, want %v", count, len(resources.Repos))
}
counter++

// list the repos
list, err := db.ListRepos()
if err != nil {
Expand All @@ -661,6 +760,32 @@ func testRepos(t *testing.T, db Interface, resources *Resources) {
}
counter++

// list the repos for an org
list, count, err = db.ListReposForOrg(resources.Repos[0].GetOrg(), "name", nil, 1, 10)
if err != nil {
t.Errorf("unable to list repos for org %s: %v", resources.Repos[0].GetOrg(), err)
}
if int(count) != len(resources.Repos) {
t.Errorf("ListReposForOrg() is %v, want %v", count, len(resources.Repos))
}
if !reflect.DeepEqual(list, resources.Repos) {
t.Errorf("ListReposForOrg() is %v, want %v", list, resources.Repos)
}
counter++

// list the repos for a user
list, count, err = db.ListReposForUser(resources.Users[0], "name", nil, 1, 10)
if err != nil {
t.Errorf("unable to list repos for user %d: %v", resources.Users[0].GetID(), err)
}
if int(count) != len(resources.Repos) {
t.Errorf("ListReposForUser() is %v, want %v", count, len(resources.Repos))
}
if !reflect.DeepEqual(list, resources.Repos) {
t.Errorf("ListReposForUser() is %v, want %v", list, resources.Repos)
}
counter++

// lookup the repos by name
for _, repo := range resources.Repos {
got, err := db.GetRepoForOrg(repo.GetOrg(), repo.GetName())
Expand Down

0 comments on commit db6e2f0

Please sign in to comment.