From 11656808e355bf17acfb9848e80db2a3add07c1a Mon Sep 17 00:00:00 2001 From: shiron Date: Wed, 18 Dec 2024 10:32:42 +0900 Subject: [PATCH] test: add `gen vscode` --- Makefile | 4 +++ cmd/gen/export_test.go | 3 ++ cmd/gen/init_test.go | 11 ++++++++ cmd/gen/vscode_test.go | 62 ++++++++++++++++++++++++++++++++++++++++++ data/config.yaml | 40 +++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 cmd/gen/export_test.go create mode 100644 cmd/gen/init_test.go create mode 100644 cmd/gen/vscode_test.go create mode 100644 data/config.yaml diff --git a/Makefile b/Makefile index 8dc4144..882ea53 100644 --- a/Makefile +++ b/Makefile @@ -36,3 +36,7 @@ gen: .PHONY: release release: @goreleaser release --snapshot --clean + +.PHONY: test +test: + @go test -v ./... diff --git a/cmd/gen/export_test.go b/cmd/gen/export_test.go new file mode 100644 index 0000000..d481085 --- /dev/null +++ b/cmd/gen/export_test.go @@ -0,0 +1,3 @@ +package gen + +var VSCodeCmd = vscodeCmd diff --git a/cmd/gen/init_test.go b/cmd/gen/init_test.go new file mode 100644 index 0000000..48d8bfe --- /dev/null +++ b/cmd/gen/init_test.go @@ -0,0 +1,11 @@ +package gen_test + +import ( + "os" + "testing" +) + +func TestMain(m *testing.M) { + code := m.Run() + os.Exit(code) +} diff --git a/cmd/gen/vscode_test.go b/cmd/gen/vscode_test.go new file mode 100644 index 0000000..00ef495 --- /dev/null +++ b/cmd/gen/vscode_test.go @@ -0,0 +1,62 @@ +package gen_test + +import ( + "io" + "os" + "path" + "testing" + + "github.com/shiron-dev/arcanum-hue/cmd/gen" +) + +var originalArgs = os.Args + +func setArgs(arg string) { + //nolint:gocritic + os.Args = append(originalArgs, arg) +} + +func resetArgs() { + os.Args = originalArgs +} + +func Test_vscodeCmd(t *testing.T) { + t.Parallel() + + setArgs("sub") + + defer resetArgs() + + tempDir := t.TempDir() + + configFilePath := path.Join(tempDir, "config.yaml") + + cwDir, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + + testConfig, err := os.Open(path.Join(cwDir, "../../data/config.yaml")) + if err != nil { + t.Fatal(err) + } + defer testConfig.Close() + + configFile, err := os.Create(configFilePath) + if err != nil { + t.Fatal(err) + } + defer configFile.Close() + + _, err = io.Copy(configFile, testConfig) + if err != nil { + t.Fatal(err) + } + + err = os.WriteFile(configFilePath, []byte("name: test"), 0o600) + if err != nil { + t.Fatal(err) + } + + gen.VSCodeCmd.Run(gen.VSCodeCmd, []string{configFilePath, tempDir}) +} diff --git a/data/config.yaml b/data/config.yaml new file mode 100644 index 0000000..74164a8 --- /dev/null +++ b/data/config.yaml @@ -0,0 +1,40 @@ +# yaml-language-server: $schema=../schema.json +name: Test Config +description: This is a test config file +colorThemes: + - name: Dark + vscodeUiTheme: vs-dark + type: dark + colors: + foreground: "#CCCCCC" + hiForeground: "#F8F8F8" + secondaryForeground: "#6E7681" + foregroundAccent: "#4daafc" + warningForeground: "#F85149" + + background: "#181818" + editorBackground: "#1F1F1F" + secondaryBackground: "#313131" + backgroundAccent: "#026EC1" + hiBackgroundAccent: "#026EC1" + matchBackground: "#9E6A03" + + border: "#2B2B2B" + + terminalAnsi: + black: "#" + brightBlack: "#" + blue: "#" + cyan: "#" + green: "#" + brightBlue: "#" + brightCyan: "#" + brightGreen: "#" + white: "#" + brightWhite: "#" + magenta: "#" + yellow: "#" + red: "#" + brightYellow: "#" + brightMagenta: "#" + brightRed: "#"