Add more unit tests

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-04-29 09:47:26 +00:00
parent 2b1414d150
commit 2a3d524a71
7 changed files with 516 additions and 39 deletions

View file

@ -19,6 +19,7 @@ package testing
import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
@ -60,6 +61,30 @@ func ImpersonateAdminContext(ctx context.Context, db common.Store, s *testing.T)
return ctx
}
func CreateGARMTestUser(ctx context.Context, username string, db common.Store, s *testing.T) params.User {
newUserParams := params.NewUserParams{
Email: fmt.Sprintf("%s@localhost", username),
Username: username,
Password: "superSecretPassword@123",
IsAdmin: false,
Enabled: true,
}
user, err := db.CreateUser(ctx, newUserParams)
if err != nil {
if errors.Is(err, runnerErrors.ErrDuplicateEntity) {
user, err = db.GetUser(ctx, newUserParams.Username)
if err != nil {
s.Fatalf("failed to get user by email: %v", err)
}
return user
}
s.Fatalf("failed to create user: %v", err)
}
return user
}
func CreateDefaultGithubEndpoint(ctx context.Context, db common.Store, s *testing.T) params.GithubEndpoint {
endpointParams := params.CreateGithubEndpointParams{
Name: "github.com",