@@ -665,6 +665,34 @@ func TestRenameCluster(t *testing.T) {
665
665
}
666
666
}
667
667
668
+ func TestRemoveContextFromDefaultKubeConfig (t * testing.T ) {
669
+ // 1) Create a temp directory for our test kubeconfig
670
+ tmpDir := t .TempDir ()
671
+ mockConfigFile := filepath .Join (tmpDir , "config" )
672
+
673
+ // 2) Copy "kubeconfig_remove" (which includes 'kubedelta') into that file
674
+ testDataPath := filepath .Join ("headlamp_testdata" , "kubeconfig_remove" )
675
+ testData , err := os .ReadFile (testDataPath )
676
+ require .NoError (t , err , "failed to read test data for 'kubeconfig_remove'" )
677
+
678
+ err = os .WriteFile (mockConfigFile , testData , 0o600 )
679
+ require .NoError (t , err , "failed to write test kubeconfig" )
680
+
681
+ // 3) We need a fake http.ResponseWriter
682
+ w := httptest .NewRecorder ()
683
+
684
+ // 4) Call removeContextFromDefaultKubeConfig with our mock path as the third param
685
+ err = removeContextFromDefaultKubeConfig (w , "kubedelta" , mockConfigFile )
686
+ require .NoError (t , err , "removeContextFromDefaultKubeConfig should succeed" )
687
+
688
+ // 5) Verify 'kubedelta' is removed from the file
689
+ updatedData , err := os .ReadFile (mockConfigFile )
690
+ require .NoError (t , err , "failed to read updated kubeconfig" )
691
+
692
+ require .NotContains (t , string (updatedData ), "kubedelta" ,
693
+ "Expected 'kubedelta' context to be removed from kubeconfig" )
694
+ }
695
+
668
696
func TestFileExists (t * testing.T ) {
669
697
// Test for existing file
670
698
assert .True (t , fileExists ("./headlamp_testdata/kubeconfig" ),
0 commit comments