Skip to content

Commit

Permalink
Fixed action name in config
Browse files Browse the repository at this point in the history
Fixed the keybind action name to section_header_num.
Added configuration yaml test.
Added test for names in config.
  • Loading branch information
noborus committed Dec 27, 2023
1 parent 81f4de1 commit cd37bcd
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"bytes"
"io"
"os"
"strings"
"testing"
)

func Test_initConfig(t *testing.T) {
t.Parallel()
tests := []struct {
name string
cfgFile string
errStr string
}{
{
name: "test-ov.yaml",
cfgFile: "ov.yaml",
errStr: "",
},
{
name: "test-ov-less.yaml",
cfgFile: "ov-less.yaml",
errStr: "",
},
{
name: "no-file.yaml",
cfgFile: "no-file.yaml",
errStr: "no such file or directory",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfgFile = tt.cfgFile
// Backup original stderr
origStderr := os.Stderr

// Create a buffer to capture stderr output
r, w, _ := os.Pipe()
os.Stderr = w

initConfig()
w.Close()
// Restore original stderr
os.Stderr = origStderr

// Read captured stderr output
var buf bytes.Buffer
io.Copy(&buf, r)
capturedStderr := buf.String()

// Now you can assert capturedStderr
// For example, check if it contains a specific error message
if !strings.Contains(capturedStderr, tt.errStr) {
t.Errorf("initConfig() error = %v, wantErr %v", capturedStderr, tt.errStr)
}
//keyBind := oviewer.GetKeyBinds(config)
//log.Println(oviewer.KeyBindString(keyBind))
})
}
}

0 comments on commit cd37bcd

Please sign in to comment.