mirror of
https://github.com/Smaug123/gitea-repo-config
synced 2025-10-07 00:18:40 +00:00
First test (#59)
This commit is contained in:
114
Gitea.InMemory/Client.fs
Normal file
114
Gitea.InMemory/Client.fs
Normal file
@@ -0,0 +1,114 @@
|
||||
namespace Gitea.InMemory
|
||||
|
||||
open System
|
||||
open Gitea.Declarative
|
||||
|
||||
type private ServerState =
|
||||
{
|
||||
Users : Map<User, Gitea.CreateUserOption>
|
||||
Repos : (User * Repo) list
|
||||
}
|
||||
|
||||
member this.WithUser (create : Gitea.CreateUserOption) : ServerState =
|
||||
let user = User create.Username
|
||||
|
||||
match Map.tryFind user this.Users with
|
||||
| Some _ ->
|
||||
create.Username
|
||||
|> failwithf "Behaviour of in-memory Gitea is not defined for adding the same user multiple times. Got: %s"
|
||||
| None ->
|
||||
{ this with
|
||||
Users = Map.add user create this.Users
|
||||
}
|
||||
|
||||
static member Empty =
|
||||
{
|
||||
Users = Map.empty
|
||||
Repos = []
|
||||
}
|
||||
|
||||
type private ServerMessage = | AddUser of Gitea.CreateUserOption * AsyncReplyChannel<unit>
|
||||
|
||||
type Server =
|
||||
private
|
||||
| Server of MailboxProcessor<ServerMessage>
|
||||
|
||||
interface IDisposable with
|
||||
member this.Dispose () =
|
||||
match this with
|
||||
| Server t -> t.Dispose ()
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Client =
|
||||
|
||||
let rec private loop (state : ServerState) (mailbox : MailboxProcessor<ServerMessage>) : Async<unit> =
|
||||
async {
|
||||
let! message = mailbox.Receive ()
|
||||
|
||||
match message with
|
||||
| ServerMessage.AddUser (user, reply) ->
|
||||
reply.Reply ()
|
||||
return! loop (state.WithUser user) mailbox
|
||||
}
|
||||
|
||||
let make () : Server * IGiteaClient =
|
||||
let server = MailboxProcessor.Start (loop ServerState.Empty)
|
||||
|
||||
let client =
|
||||
{ new IGiteaClient with
|
||||
member _.AdminGetAllUsers (page, limit) = failwith "Not implemented"
|
||||
|
||||
member _.AdminCreateUser createUserOption =
|
||||
async {
|
||||
let! () = server.PostAndAsyncReply (fun reply -> AddUser (createUserOption, reply))
|
||||
let result = Gitea.User ()
|
||||
result.Email <- createUserOption.Email
|
||||
result.Restricted <- createUserOption.Restricted
|
||||
// TODO: what is this username used for anyway
|
||||
// result.LoginName <- createUserOption.Username
|
||||
result.Visibility <- createUserOption.Visibility
|
||||
result.Created <- createUserOption.CreatedAt
|
||||
result.FullName <- createUserOption.FullName
|
||||
result.LoginName <- createUserOption.LoginName
|
||||
return result
|
||||
}
|
||||
|> Async.StartAsTask
|
||||
|
||||
member _.AdminDeleteUser user = failwith "Not implemented"
|
||||
|
||||
member _.AdminEditUser (user, editUserOption) = failwith "Not implemented"
|
||||
|
||||
member _.AdminCreateRepo (user, createRepoOption) = failwith "Not implemented"
|
||||
|
||||
member _.UserListRepos (user, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoAddPushMirror (user, repo, createPushMirrorOption) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListPushMirrors (loginName, userName, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListBranchProtection (loginName, userName) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDeleteBranchProtection (user, repo, branch) = failwith "Not implemented"
|
||||
|
||||
member _.RepoCreateBranchProtection (user, repo, createBranchProtectionOption) =
|
||||
failwith "Not implemented"
|
||||
|
||||
member _.RepoEditBranchProtection (user, repo, branch, editBranchProtectionOption) =
|
||||
failwith "Not implemented"
|
||||
|
||||
member _.RepoMigrate migrateRepoOptions = failwith "Not implemented"
|
||||
|
||||
member _.RepoGet (user, repo) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDelete (user, repo) = failwith "Not implemented"
|
||||
|
||||
member _.RepoEdit (user, repo, editRepoOption) = failwith "Not implemented"
|
||||
|
||||
member _.RepoListCollaborators (loginName, userName, page, count) = failwith "Not implemented"
|
||||
|
||||
member _.RepoAddCollaborator (user, repo, collaborator) = failwith "Not implemented"
|
||||
|
||||
member _.RepoDeleteCollaborator (user, repo, collaborator) = failwith "Not implemented"
|
||||
}
|
||||
|
||||
Server server, client
|
Reference in New Issue
Block a user