-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #468 from noborus/add-config-test
Fixed action name in config
- Loading branch information
Showing
3 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test_initConfig(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
cfgFile string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "test-ov.yaml", | ||
cfgFile: "ov.yaml", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "test-ov-less.yaml", | ||
cfgFile: "ov-less.yaml", | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "no-file.yaml", | ||
cfgFile: "no-file.yaml", | ||
wantErr: true, | ||
}, | ||
} | ||
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 | ||
got := len(capturedStderr) > 0 | ||
if got != tt.wantErr { | ||
t.Errorf("initConfig() error = %v, wantErr %v", capturedStderr, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters