Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
- Adding test helpers ✨
Browse files Browse the repository at this point in the history
- Adding tests ✅
  • Loading branch information
fairyhunter13 committed Oct 27, 2020
1 parent b0b188b commit 2e02233
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pkg/matchers/config_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package matchers

import "testing"
import (
"os"
"os/exec"
"testing"
)

func TestIsLogformat(t *testing.T) {
type args struct {
s string
fnName := "TestIsLogformat"
if IsEnvSet(fnName) {
IsLogformat(GetTestArgEnv(fnName))
return
}
tests := []struct {
name string
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
IsLogformat(tt.args.s)
})

cmd := exec.Command(os.Args[0], "-test.run=TestIsLogformat")
cmd.Env = append(os.Environ(), "TEST_TestIsLogformat=1")
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
}
27 changes: 27 additions & 0 deletions pkg/matchers/helper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package matchers

import "os"

func getTestEnvName(fnName string) string {
return "TEST_" + fnName
}

func IsEnvSet(fnName string) bool {
return os.Getenv(getTestEnvName(fnName)) == "1"
}

func SetTestEnv(fnName string) string {
return "TEST_" + fnName + "=1"
}

func SetTestArgEnv(fnName string, arg string) string {
return "TEST_ARG_" + fnName + "=" + arg
}

func GetTestArgEnv(fnName string) string {
return os.Getenv("TEST_ARG_" + fnName)
}

func GetArgCmd(fnName string) string {
return "-test.run=" + fnName
}

0 comments on commit 2e02233

Please sign in to comment.