@@ -16,6 +16,7 @@ package main
1616
1717import (
1818 "encoding/json"
19+ "io/fs"
1920 "net/http"
2021 "net/http/httptest"
2122 "net/url"
@@ -234,6 +235,58 @@ func (suite *SubcommandTestSuite) TestLogoutCmdSuccess() {
234235 suite .Nil (storedCred )
235236}
236237
238+ func (suite * SubcommandTestSuite ) TestLogoutCmdPurge () {
239+ // Setup temp credential path
240+ tmpDir := suite .T ().TempDir ()
241+ credPath := filepath .Join (tmpDir , "credentials.toml" )
242+ restore := auth .SetCredPathForTesting (credPath )
243+ defer restore ()
244+ auth .ResetCredentialsForTesting ()
245+
246+ // Add a credential
247+ u , _ := url .Parse ("https://example.com" )
248+ cred := auth.Credential {
249+ Type : auth .TypeApiKey ,
250+ RegistryURL : auth .Uri (* u ),
251+ ApiKey : "test-key" ,
252+ }
253+ err := auth .AddCredential (cred , false )
254+ suite .Require ().NoError (err )
255+
256+ // Verify credential exists
257+ storedCred , err := auth .GetCredentials (u )
258+ suite .Require ().NoError (err )
259+ suite .Require ().NotNil (storedCred )
260+
261+ // Test LogoutCmd with purge
262+ cmd := LogoutCmd {
263+ RegistryURL : "https://example.com" ,
264+ Purge : true ,
265+ }
266+ m := cmd .GetModelCustom (baseModel {
267+ getDriverRegistry : getTestDriverRegistry ,
268+ downloadPkg : downloadTestPkg ,
269+ })
270+
271+ licPath := filepath .Join (tmpDir , "columnar.lic" )
272+ f , err := os .Create (licPath )
273+ suite .Require ().NoError (err )
274+ f .Close ()
275+
276+ suite .runCmd (m )
277+
278+ // Ensure credentials dir is empty
279+ var filelist []string
280+ suite .NoError (fs .WalkDir (os .DirFS (tmpDir ), "." , func (path string , d fs.DirEntry , err error ) error {
281+ if d .IsDir () {
282+ return nil
283+ }
284+ filelist = append (filelist , path )
285+ return nil
286+ }))
287+ suite .Empty (filelist , "expected all credential files to be removed" )
288+ }
289+
237290func (suite * SubcommandTestSuite ) TestLogoutCmdNotFound () {
238291 // Setup temp credential path
239292 tmpDir := suite .T ().TempDir ()
0 commit comments