-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtester_test.go
66 lines (56 loc) · 1.74 KB
/
tester_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package tester_utils
import (
"encoding/json"
"errors"
"fmt"
"testing"
"github.com/codecrafters-io/tester-utils/test_case_harness"
"github.com/codecrafters-io/tester-utils/tester_definition"
"github.com/stretchr/testify/assert"
)
func passFunc(harness *test_case_harness.TestCaseHarness) error {
return nil
}
func failFunc(harness *test_case_harness.TestCaseHarness) error {
return errors.New("fail")
}
func buildTestCasesJson(slugs []string) string {
testCases := []map[string]string{}
for index, slug := range slugs {
testCases = append(testCases, map[string]string{
"slug": slug,
"tester_log_prefix": fmt.Sprintf("test-%d", index+1),
"title": fmt.Sprintf("Stage #%d: %s", index+1, slug),
})
}
testCasesJson, _ := json.Marshal(testCases)
return string(testCasesJson)
}
func TestAllStagesPass(t *testing.T) {
definition := tester_definition.TesterDefinition{
TestCases: []tester_definition.TestCase{
{Slug: "test-1", TestFunc: passFunc},
{Slug: "test-2", TestFunc: passFunc},
},
}
env := map[string]string{
"CODECRAFTERS_REPOSITORY_DIR": "./test_helpers/valid_app_dir",
"CODECRAFTERS_TEST_CASES_JSON": buildTestCasesJson([]string{"test-1", "test-2"}),
}
exitCode := RunCLI(env, definition)
assert.Equal(t, exitCode, 0)
}
func TestOneStageFails(t *testing.T) {
definition := tester_definition.TesterDefinition{
TestCases: []tester_definition.TestCase{
{Slug: "test-1", TestFunc: passFunc},
{Slug: "test-2", TestFunc: failFunc},
},
}
env := map[string]string{
"CODECRAFTERS_REPOSITORY_DIR": "./test_helpers/valid_app_dir",
"CODECRAFTERS_TEST_CASES_JSON": buildTestCasesJson([]string{"test-1", "test-2"}),
}
exitCode := RunCLI(env, definition)
assert.Equal(t, exitCode, 1)
}