11defmodule OCI.RegistryTest do
22 use ExUnit.Case , async: true
3- doctest OCI.Registry
3+ # doctest OCI.Registry
44
55 defp tmp_storage ( ) do
66 OCI.Storage.Local . init ( % { path: "./tmp/" } )
@@ -17,6 +17,80 @@ defmodule OCI.RegistryTest do
1717 registry
1818 end
1919
20+ defmodule NoAuth do
21+ defstruct [ :none ]
22+
23+ def init ( map ) do
24+ { :ok , struct ( __MODULE__ , map ) }
25+ end
26+ end
27+
28+ defmodule VoidStorage do
29+ defstruct [ :where ]
30+ def init ( map ) , do: { :ok , struct ( __MODULE__ , map ) }
31+ end
32+
33+ describe "load_from_keywordlist/1" do
34+ test "defaults if not present" do
35+ config = [
36+ auth: % {
37+ adapter: NoAuth ,
38+ config: % { none: "nope" }
39+ } ,
40+ storage: % {
41+ adapter: VoidStorage ,
42+ config: % { where: "nowhere" }
43+ }
44+ ]
45+
46+ registry = OCI.Registry . load_from_keywordlist ( config )
47+
48+ assert % OCI.Registry {
49+ enable_blob_deletion: true ,
50+ enable_manifest_deletion: true ,
51+ max_blob_upload_chunk_size: 10_485_760 ,
52+ max_manifest_size: 4_194_304 ,
53+ realm: "Registry" ,
54+ repo_name_pattern:
55+ ~r/ ^([a-z0-9]+(?:[._-][a-z0-9]+)*)(\/ [a-z0-9]+(?:[._-][a-z0-9]+)*)*$/ ,
56+ auth: % OCI.RegistryTest.NoAuth { none: "nope" } ,
57+ storage: % OCI.RegistryTest.VoidStorage { where: "nowhere" }
58+ } = registry
59+ end
60+
61+ test "should include the settings" do
62+ config = [
63+ realm: "My Registry" ,
64+ max_manifest_size: 1 ,
65+ max_blob_upload_chunk_size: 2 ,
66+ enable_blob_deletion: false ,
67+ enable_manifest_deletion: false ,
68+ repo_name_pattern: ~r/ ^[a-z0-9]+\/ [a-z0-9]+$/ ,
69+ auth: % {
70+ adapter: NoAuth ,
71+ config: % { none: "nope" }
72+ } ,
73+ storage: % {
74+ adapter: VoidStorage ,
75+ config: % { where: "nowhere" }
76+ }
77+ ]
78+
79+ registry = OCI.Registry . load_from_keywordlist ( config )
80+
81+ assert % OCI.Registry {
82+ realm: "My Registry" ,
83+ enable_blob_deletion: false ,
84+ enable_manifest_deletion: false ,
85+ repo_name_pattern: ~r/ ^[a-z0-9]+\/ [a-z0-9]+$/ ,
86+ max_manifest_size: 1 ,
87+ max_blob_upload_chunk_size: 2 ,
88+ auth: % OCI.RegistryTest.NoAuth { none: "nope" } ,
89+ storage: % OCI.RegistryTest.VoidStorage { where: "nowhere" }
90+ } = registry
91+ end
92+ end
93+
2094 describe "authenticate" do
2195 test "returns {:ok, ctx} when authentication is successful" do
2296 registry = registry_with_user ( "myuser" , "mypass" )
0 commit comments