|
| 1 | +let format_cmd cmd_lines = |
| 2 | + let cmd, args = cmd_lines in |
| 3 | + Printf.sprintf "%s:%s" cmd (String.concat " " args) |
| 4 | + |
| 5 | +let check exp ac () = |
| 6 | + let exp_str = format_cmd exp in |
| 7 | + let ac_str = ac |> format_cmd in |
| 8 | + let msg = Printf.sprintf "%s -- %s" exp_str ac_str in |
| 9 | + Alcotest.(check string) msg exp_str ac_str |
| 10 | + |
| 11 | +let test_dnf_repo_query_installed = |
| 12 | + [ |
| 13 | + ( "<null>" |
| 14 | + , `Quick |
| 15 | + , check |
| 16 | + ( !Xapi_globs.dnf_cmd |
| 17 | + , [ |
| 18 | + "repoquery" |
| 19 | + ; "-a" |
| 20 | + ; "--qf" |
| 21 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 22 | + ; "--installed" |
| 23 | + ] |
| 24 | + ) |
| 25 | + (Pkg_mgr.Dnf_cmd.repoquery_installed ()) |
| 26 | + ) |
| 27 | + ] |
| 28 | + |
| 29 | +let test_dnf_clean_all_cache = |
| 30 | + [ |
| 31 | + ( "<null>" |
| 32 | + , `Quick |
| 33 | + , check |
| 34 | + (!Xapi_globs.dnf_cmd, ["clean"; "all"]) |
| 35 | + (Pkg_mgr.Dnf_cmd.clean_cache ~repo_name:"*") |
| 36 | + ) |
| 37 | + ] |
| 38 | + |
| 39 | +let test_dnf_clean_repo_cache = |
| 40 | + [ |
| 41 | + ( "<null>" |
| 42 | + , `Quick |
| 43 | + , check |
| 44 | + ( !Xapi_globs.dnf_cmd |
| 45 | + , ["--disablerepo=*"; "--enablerepo=test_repo"; "clean"; "all"] |
| 46 | + ) |
| 47 | + (Pkg_mgr.Dnf_cmd.clean_cache ~repo_name:"test_repo") |
| 48 | + ) |
| 49 | + ] |
| 50 | + |
| 51 | +let test_dnf_get_pkgs_from_updateinfo = |
| 52 | + let sub_command = "upgrades" in |
| 53 | + let repositories = ["testrepo1"; "testrepo2"] in |
| 54 | + [ |
| 55 | + ( "<null>" |
| 56 | + , `Quick |
| 57 | + , check |
| 58 | + ( !Xapi_globs.dnf_cmd |
| 59 | + , [ |
| 60 | + "-q" |
| 61 | + ; "--disablerepo=*" |
| 62 | + ; "--enablerepo=testrepo1,testrepo2" |
| 63 | + ; "updateinfo" |
| 64 | + ; "list" |
| 65 | + ; "upgrades" |
| 66 | + ] |
| 67 | + ) |
| 68 | + (Pkg_mgr.Dnf_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories) |
| 69 | + ) |
| 70 | + ] |
| 71 | + |
| 72 | +let test_dnf_config_repo = |
| 73 | + let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in |
| 74 | + [ |
| 75 | + ( "<null>" |
| 76 | + , `Quick |
| 77 | + , check |
| 78 | + ( !Xapi_globs.dnf_cmd |
| 79 | + , [ |
| 80 | + "config-manager" |
| 81 | + ; "--setopt=testrepo.accesstoken=file:///some/path" |
| 82 | + ; "testrepo" |
| 83 | + ] |
| 84 | + ) |
| 85 | + (Pkg_mgr.Dnf_cmd.config_repo ~repo_name:"testrepo" ~config) |
| 86 | + ) |
| 87 | + ] |
| 88 | + |
| 89 | +let test_dnf_sync_repo = |
| 90 | + [ |
| 91 | + ( "<null>" |
| 92 | + , `Quick |
| 93 | + , check |
| 94 | + ( !Xapi_globs.dnf_cmd |
| 95 | + , [ |
| 96 | + "reposync" |
| 97 | + ; "-p" |
| 98 | + ; !Xapi_globs.local_pool_repo_dir |
| 99 | + ; "--downloadcomps" |
| 100 | + ; "--download-metadata" |
| 101 | + ; "--delete" |
| 102 | + ; "--newest-only" |
| 103 | + ; "--repoid=testrepo" |
| 104 | + ] |
| 105 | + ) |
| 106 | + (Pkg_mgr.Dnf_cmd.sync_repo ~repo_name:"testrepo") |
| 107 | + ) |
| 108 | + ] |
| 109 | + |
| 110 | +let test_yum_repo_query_installed = |
| 111 | + [ |
| 112 | + ( "<null>" |
| 113 | + , `Quick |
| 114 | + , check |
| 115 | + ( !Xapi_globs.repoquery_cmd |
| 116 | + , [ |
| 117 | + "-a" |
| 118 | + ; "--pkgnarrow=installed" |
| 119 | + ; "--qf" |
| 120 | + ; "%{name}:|%{epoch}:|%{version}:|%{release}:|%{arch}:|%{repoid}" |
| 121 | + ] |
| 122 | + ) |
| 123 | + (Pkg_mgr.Yum_cmd.repoquery_installed ()) |
| 124 | + ) |
| 125 | + ] |
| 126 | + |
| 127 | +let test_yum_clean_all_cache = |
| 128 | + [ |
| 129 | + ( "<null>" |
| 130 | + , `Quick |
| 131 | + , check |
| 132 | + (!Xapi_globs.yum_cmd, ["clean"; "all"]) |
| 133 | + (Pkg_mgr.Yum_cmd.clean_cache ~repo_name:"*") |
| 134 | + ) |
| 135 | + ] |
| 136 | + |
| 137 | +let test_yum_clean_repo_cache = |
| 138 | + [ |
| 139 | + ( "<null>" |
| 140 | + , `Quick |
| 141 | + , check |
| 142 | + ( !Xapi_globs.yum_cmd |
| 143 | + , ["--disablerepo=*"; "--enablerepo=test_repo"; "clean"; "all"] |
| 144 | + ) |
| 145 | + (Pkg_mgr.Yum_cmd.clean_cache ~repo_name:"test_repo") |
| 146 | + ) |
| 147 | + ] |
| 148 | + |
| 149 | +let test_yum_get_pkgs_from_updateinfo = |
| 150 | + let sub_command = "updates" in |
| 151 | + let repositories = ["testrepo1"; "testrepo2"] in |
| 152 | + [ |
| 153 | + ( "<null>" |
| 154 | + , `Quick |
| 155 | + , check |
| 156 | + ( !Xapi_globs.yum_cmd |
| 157 | + , [ |
| 158 | + "-q" |
| 159 | + ; "--disablerepo=*" |
| 160 | + ; "--enablerepo=testrepo1,testrepo2" |
| 161 | + ; "updateinfo" |
| 162 | + ; "list" |
| 163 | + ; "updates" |
| 164 | + ] |
| 165 | + ) |
| 166 | + (Pkg_mgr.Yum_cmd.get_pkgs_from_updateinfo ~sub_command ~repositories) |
| 167 | + ) |
| 168 | + ] |
| 169 | + |
| 170 | +let test_yum_config_repo = |
| 171 | + let config = ["--setopt=testrepo.accesstoken=file:///some/path"] in |
| 172 | + [ |
| 173 | + ( "<null>" |
| 174 | + , `Quick |
| 175 | + , check |
| 176 | + ( !Xapi_globs.yum_config_manager_cmd |
| 177 | + , ["--setopt=testrepo.accesstoken=file:///some/path"; "testrepo"] |
| 178 | + ) |
| 179 | + (Pkg_mgr.Yum_cmd.config_repo ~repo_name:"testrepo" ~config) |
| 180 | + ) |
| 181 | + ] |
| 182 | + |
| 183 | +let test_yum_sync_repo = |
| 184 | + [ |
| 185 | + ( "<null>" |
| 186 | + , `Quick |
| 187 | + , check |
| 188 | + ( !Xapi_globs.reposync_cmd |
| 189 | + , [ |
| 190 | + "-p" |
| 191 | + ; !Xapi_globs.local_pool_repo_dir |
| 192 | + ; "--downloadcomps" |
| 193 | + ; "--download-metadata" |
| 194 | + ; "--delete" |
| 195 | + ; "--newest-only" |
| 196 | + ; "--repoid=testrepo" |
| 197 | + ; "--plugins" |
| 198 | + ] |
| 199 | + ) |
| 200 | + (Pkg_mgr.Yum_cmd.sync_repo ~repo_name:"testrepo") |
| 201 | + ) |
| 202 | + ] |
| 203 | + |
| 204 | +let tests = |
| 205 | + [ |
| 206 | + ("test_dnf_repo_query_installed", test_dnf_repo_query_installed) |
| 207 | + ; ("test_dnf_clean_all_cache", test_dnf_clean_all_cache) |
| 208 | + ; ("test_dnf_clean_repo_cache", test_dnf_clean_repo_cache) |
| 209 | + ; ("test_dnf_get_pkgs_from_updateinfo", test_dnf_get_pkgs_from_updateinfo) |
| 210 | + ; ("test_dnf_cofig_repo", test_dnf_config_repo) |
| 211 | + ; ("test_dnf_sync_repo", test_dnf_sync_repo) |
| 212 | + ; ("test_yum_repo_query_installed", test_yum_repo_query_installed) |
| 213 | + ; ("test_yum_clean_all_cache", test_yum_clean_all_cache) |
| 214 | + ; ("test_yum_clean_repo_cache", test_yum_clean_repo_cache) |
| 215 | + ; ("test_yum_get_pkgs_from_updateinfo", test_yum_get_pkgs_from_updateinfo) |
| 216 | + ; ("test_yum_cofig_repo", test_yum_config_repo) |
| 217 | + ; ("test_yum_sync_repo", test_yum_sync_repo) |
| 218 | + ] |
0 commit comments