diff --git a/test/test.ml b/test/test.ml index ef662d4c..85a6ef0e 100644 --- a/test/test.ml +++ b/test/test.ml @@ -19,25 +19,34 @@ let get_mock_payloads () = let state_path = Caml.Filename.concat mock_state_dir fn in if Caml.Sys.file_exists state_path then kind, payload_path, Some state_path else kind, payload_path, None) -let process ~(ctx : Context.t) (kind, path, state_path) = - let%lwt ctx = +let process ~(secrets : Config_t.secrets) ~config (kind, path, state_path) = + let headers = [ "x-github-event", kind ] in + let make_test_context event = + let repo = Github.repo_of_notification @@ Github.parse_exn ~secret:secrets.gh_token headers event in + let ctx = Context.make () in + ctx.secrets <- Some secrets; + ignore (State.get_or_init_repo_state ctx.state repo.full_name); match state_path with - | None -> Lwt.return ctx + | None -> + State.set_repo_config ctx.state ~config ~repo_name:repo.full_name; + Lwt.return ctx | Some state_path -> match Common.get_local_file state_path with | Error e -> log#error "failed to read %s: %s" state_path e; Lwt.return ctx | Ok file -> - let state = State_j.state_of_string file in - state.config <- ctx.state.config; - Lwt.return { ctx with state } + let repo_state = State_j.repo_state_of_string file in + Hashtbl.set ctx.state ~key:repo.full_name ~data:repo_state; + State.set_repo_config ctx.state ~repo_name:repo.full_name ~config; + Lwt.return ctx in Stdio.printf "===== file %s =====\n" path; let headers = [ "x-github-event", kind ] in match Common.get_local_file path with | Error e -> Lwt.return @@ log#error "failed to read %s: %s" path e | Ok event -> + let%lwt ctx = make_test_context event in let%lwt _ctx = Action_local.process_github_notification ctx headers event in Lwt.return_unit @@ -51,12 +60,10 @@ let () = log#error "%s" e; Lwt.return_unit | Ok config -> - ctx.state.config <- Some config; - ( match Context.refresh_secrets ctx with - | Ok ctx -> Lwt_list.iter_s (process ~ctx) payloads - | Error e -> - log#error "failed to read secrets:"; - log#error "%s" e; - Lwt.return_unit - ) + match Context.refresh_secrets ctx with + | Ok ctx -> Lwt_list.iter_s (process ~secrets:(Option.value_exn ctx.secrets) ~config) payloads + | Error e -> + log#error "failed to read secrets:"; + log#error "%s" e; + Lwt.return_unit )