1
1
open Base
2
2
open Lib
3
+ open Common
3
4
4
5
let log = Devkit.Log. from " test"
5
6
7
+ let () = Devkit.Log. set_loglevels " error"
8
+
6
9
let mock_payload_dir = Caml.Filename. concat Caml.Filename. parent_dir_name " mock_payloads"
7
10
8
11
let mock_state_dir = Caml.Filename. concat Caml.Filename. parent_dir_name " mock_states"
9
12
13
+ let mock_secrets_dir = Caml.Filename. concat Caml.Filename. parent_dir_name " mock_secrets"
14
+
10
15
module Action_local = Action. Action (Api_local. Github ) (Api_local. Slack )
11
16
12
17
let get_mock_payloads () =
@@ -19,51 +24,29 @@ let get_mock_payloads () =
19
24
let state_path = Caml.Filename. concat mock_state_dir fn in
20
25
if Caml.Sys. file_exists state_path then kind, payload_path, Some state_path else kind, payload_path, None )
21
26
22
- let process ~(secrets : Config_t.secrets ) ~config (kind , path , state_path ) =
23
- let headers = [ " x-github-event" , kind ] in
24
- let make_test_context event =
25
- let repo = Github. repo_of_notification @@ Github. parse_exn headers event in
26
- let ctx = Context. make () in
27
- ctx.secrets < - Some secrets;
28
- ignore (State. find_or_add_repo ctx.state repo.url);
29
- match state_path with
30
- | None ->
31
- State. set_repo_config ctx.state ~config ~repo_url: repo.url;
32
- Lwt. return ctx
33
- | Some state_path ->
34
- match Common. get_local_file state_path with
35
- | Error e ->
36
- log#error " failed to read %s: %s" state_path e;
37
- Lwt. return ctx
38
- | Ok file ->
39
- let repo_state = State_j. repo_state_of_string file in
40
- Hashtbl. set ctx.state ~key: repo.url ~data: repo_state;
41
- State. set_repo_config ctx.state ~repo_url: repo.url ~config ;
42
- Lwt. return ctx
27
+ let process (kind , path , state_filepath ) =
28
+ let make_test_context () =
29
+ let config_filename = Context. default.config_filename in
30
+ let secrets_filepath = Caml.Filename. concat mock_secrets_dir Context. default.secrets_filepath in
31
+ let ctx = Context. make ~config_filename ~secrets_filepath ?state_filepath ~verbose: false () in
32
+ match Context. refresh_state ctx with
33
+ | Error e -> fmt_error " failed to read state: %s" e
34
+ | Ok ctx ->
35
+ match Context. refresh_secrets ctx with
36
+ | Error e -> fmt_error " failed to read secrets: %s" e
37
+ | Ok ctx -> Ok ctx
43
38
in
44
39
Stdio. printf " ===== file %s =====\n " path;
45
40
let headers = [ " x-github-event" , kind ] in
46
- match Common. get_local_file path with
41
+ match get_local_file path with
47
42
| Error e -> Lwt. return @@ log#error " failed to read %s: %s" path e
48
43
| Ok event ->
49
- let % lwt ctx = make_test_context event in
44
+ match make_test_context () with
45
+ | Error e -> Lwt. return @@ log#error " %s" e
46
+ | Ok ctx ->
50
47
let % lwt _ctx = Action_local. process_github_notification ctx headers event in
51
48
Lwt. return_unit
52
49
53
50
let () =
54
51
let payloads = get_mock_payloads () in
55
- let repo : Github_t.repository = { name = " " ; full_name = " " ; url = " " ; commits_url = " " ; contents_url = " " } in
56
- let ctx = Context. make ~state_filepath: " state.json" () in
57
- Lwt_main. run
58
- ( match % lwt Api_local.Github. get_config ~ctx ~repo with
59
- | Error e ->
60
- log#error " %s" e;
61
- Lwt. return_unit
62
- | Ok config ->
63
- match Context. refresh_secrets ctx with
64
- | Ok ctx -> Lwt_list. iter_s (process ~secrets: (Option. value_exn ctx.secrets) ~config ) payloads
65
- | Error e ->
66
- log#error " failed to read secrets:" ;
67
- log#error " %s" e;
68
- Lwt. return_unit
69
- )
52
+ Lwt_main. run (Lwt_list. iter_s process payloads)
0 commit comments