From 8619f1c4135fb0f4bfde9eb75c67a70c6df3dfa4 Mon Sep 17 00:00:00 2001 From: howieyuen Date: Tue, 28 Mar 2023 13:50:00 +0800 Subject: [PATCH] Fix: vela top cannot switch the theme (#5745) Signed-off-by: howieyuen --- references/cli/top/config/color.go | 2 +- references/cli/top/config/color_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/references/cli/top/config/color.go b/references/cli/top/config/color.go index 6f331fd1c..a80a347ad 100644 --- a/references/cli/top/config/color.go +++ b/references/cli/top/config/color.go @@ -291,7 +291,7 @@ func makeThemeConfigFileIfNotExist() bool { if _, err := os.Open(filepath.Clean(themeConfigFilePath)); err != nil { if os.IsNotExist(err) { // make file if not exist - _ = os.MkdirAll(filepath.Clean(velaThemeHome), 0600) + _ = os.MkdirAll(filepath.Clean(velaThemeHome), 0700) _ = os.WriteFile(filepath.Clean(themeConfigFilePath), []byte("name : "+DefaultTheme), 0600) } return false diff --git a/references/cli/top/config/color_test.go b/references/cli/top/config/color_test.go index ff176ce30..0c69b3e07 100644 --- a/references/cli/top/config/color_test.go +++ b/references/cli/top/config/color_test.go @@ -17,6 +17,8 @@ limitations under the License. package config import ( + "os" + "strings" "testing" "github.com/gdamore/tcell/v2" @@ -35,3 +37,11 @@ func TestColor(t *testing.T) { c2 := Color("red") assert.Equal(t, c2.Color(), tcell.GetColor("red").TrueColor()) } + +func TestPersistentThemeConfig(t *testing.T) { + defer PersistentThemeConfig(DefaultTheme) + PersistentThemeConfig("foo") + bytes, err := os.ReadFile(themeConfigFilePath) + assert.Nil(t, err) + assert.True(t, strings.Contains(string(bytes), "foo")) +}