@@ -119,3 +119,68 @@ func TestPrefixList_UnmarshalJSON(t *testing.T) {
119119 }
120120 assert .Nil (t , prefixList .Deleted )
121121}
122+
123+ func TestPrefixLists_GetByName (t * testing.T ) {
124+ var base ClientBaseCase
125+ base .SetUp (t )
126+ defer base .TearDown (t )
127+
128+ response := map [string ]any {
129+ "data" : []map [string ]any {
130+ {
131+ "id" : 999 ,
132+ "name" : "pl:system:resolvers:us-iad:staging" ,
133+ "description" : "Resolver ACL" ,
134+ "visibility" : "restricted" ,
135+ "source_prefixlist_id" : nil ,
136+ "ipv4" : []string {"139.144.192.62" },
137+ "ipv6" : []string {"2600:3c05:e001:bc::1" },
138+ "version" : 7 ,
139+ "created" : "2021-01-01T00:00:00" ,
140+ "updated" : "2021-06-01T00:00:00" ,
141+ "deleted" : nil ,
142+ },
143+ },
144+ "page" : 1 ,
145+ "pages" : 1 ,
146+ "results" : 1 ,
147+ }
148+
149+ base .MockGet ("networking/prefixlists" , response )
150+
151+ pl , err := base .Client .GetPrefixListByName (context .Background (), "pl:system:resolvers:us-iad:staging" )
152+ assert .NoError (t , err )
153+ assert .NotNil (t , pl )
154+
155+ assert .Equal (t , 999 , pl .ID )
156+ assert .Equal (t , "pl:system:resolvers:us-iad:staging" , pl .Name )
157+ assert .Equal (t , "Resolver ACL" , pl .Description )
158+ assert .Equal (t , "restricted" , pl .Visibility )
159+ assert .Equal (t , 7 , pl .Version )
160+ if assert .NotNil (t , pl .IPv4 ) {
161+ assert .Equal (t , []string {"139.144.192.62" }, * pl .IPv4 )
162+ }
163+ if assert .NotNil (t , pl .IPv6 ) {
164+ assert .Equal (t , []string {"2600:3c05:e001:bc::1" }, * pl .IPv6 )
165+ }
166+ }
167+
168+ func TestPrefixLists_GetByName_NotFound (t * testing.T ) {
169+ var base ClientBaseCase
170+ base .SetUp (t )
171+ defer base .TearDown (t )
172+
173+ response := map [string ]any {
174+ "data" : []map [string ]any {},
175+ "page" : 1 ,
176+ "pages" : 1 ,
177+ "results" : 0 ,
178+ }
179+
180+ base .MockGet ("networking/prefixlists" , response )
181+
182+ pl , err := base .Client .GetPrefixListByName (context .Background (), "pl:nonexistent" )
183+ assert .Error (t , err )
184+ assert .Nil (t , pl )
185+ assert .Contains (t , err .Error (), "not found" )
186+ }
0 commit comments