Skip to content

Commit 6b53c05

Browse files
committed
Fix readme
1 parent e740409 commit 6b53c05

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

README.md

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ There's two common ways to use tester, either from `func TestMain` or from `func
4242

4343
```go
4444
func TestMain(m *testing.M) {
45-
tstr.RunMain(m, tstr.WithDeps(
45+
tstr.RunMain(m, tstr.WithDeps(
4646
// Pass test dependencies here.
4747
))
4848
}
@@ -61,20 +61,20 @@ Simplest way to use `tstr.Run` is with the `tstr.WithFn` option:
6161

6262
```go
6363
func TestMyFunc(t *testing.T) {
64-
err := tstr.Run(
65-
tstr.WithDeps(
66-
// Pass test dependencies here.
67-
),
68-
tstr.WithFn(func() {
69-
const (
70-
input = 1
71-
expected = 1
72-
)
73-
got := MyFunc(input)
74-
assert.Equal(t, expected, got)
75-
}),
76-
)
77-
require.NoError(t, err)
64+
err := tstr.Run(
65+
tstr.WithDeps(
66+
// Pass test dependencies here.
67+
),
68+
tstr.WithFn(func() {
69+
const (
70+
input = 1
71+
expected = 1
72+
)
73+
got := MyFunc(input)
74+
assert.Equal(t, expected, got)
75+
}),
76+
)
77+
require.NoError(t, err)
7878
}
7979
```
8080

@@ -84,28 +84,28 @@ For table driven tests you can use `tstr.WithTable` which loops over the given t
8484

8585
```go
8686
func TestMyFunc(t *testing.T) {
87-
type test struct {
88-
Name string
89-
input int
90-
expected int
91-
}
92-
93-
tests := []test{
94-
{Name: "test-1", input: 1, expected: 1},
95-
{Name: "test-2", input: 2, expected: 2},
96-
{Name: "test-3", input: 3, expected: 3},
97-
}
98-
99-
err := tstr.Run(
100-
tstr.WithDeps(
101-
// Add dependencies here.
102-
),
103-
tstr.WithTable(t, tests, func(t *testing.T, tt test) {
104-
got := MyFunc(tt.input)
105-
assert.Equal(t, tt.expected, got)
106-
}),
107-
)
108-
require.NoError(t, err)
87+
type test struct {
88+
Name string
89+
input int
90+
expected int
91+
}
92+
93+
tests := []test{
94+
{Name: "test-1", input: 1, expected: 1},
95+
{Name: "test-2", input: 2, expected: 2},
96+
{Name: "test-3", input: 3, expected: 3},
97+
}
98+
99+
err := tstr.Run(
100+
tstr.WithDeps(
101+
// Add dependencies here.
102+
),
103+
tstr.WithTable(t, tests, func(t *testing.T, tt test) {
104+
got := MyFunc(tt.input)
105+
assert.Equal(t, tt.expected, got)
106+
}),
107+
)
108+
require.NoError(t, err)
109109
}
110110
```
111111

@@ -119,15 +119,15 @@ Compose dependecy allows you to define and manage Docker Compose stacks as test
119119

120120
```go
121121
func TestMain(m *testing.M) {
122-
tstr.RunMain(m, tstr.WithDeps(
123-
compose.New(
124-
compose.WithFile("../docker-compose.yaml"),
125-
compose.WithUpOptions(tc.Wait(true)),
126-
compose.WithDownOptions(tc.RemoveVolumes(true)),
127-
compose.WithEnv(map[string]string{"DB_PORT": "5432"}),
128-
compose.WithWaitForService("postgres", wait.ForLog("ready to accept connections")),
129-
),
130-
))
122+
tstr.RunMain(m, tstr.WithDeps(
123+
compose.New(
124+
compose.WithFile("../docker-compose.yaml"),
125+
compose.WithUpOptions(tc.Wait(true)),
126+
compose.WithDownOptions(tc.RemoveVolumes(true)),
127+
compose.WithEnv(map[string]string{"DB_PORT": "5432"}),
128+
compose.WithWaitForService("postgres", wait.ForLog("ready to accept connections")),
129+
),
130+
))
131131
}
132132
```
133133

@@ -137,15 +137,15 @@ Container dependecy allows you to define and manage single containers as test de
137137

138138
```go
139139
func TestMain(m *testing.M) {
140-
tstr.RunMain(m, tstr.WithDeps(
141-
container.New(
142-
container.WithModule(postgres.Run, "postgres:16-alpine",
143-
postgres.WithDatabase("test"),
144-
postgres.WithUsername("user"),
145-
postgres.WithPassword("password"),
146-
),
147-
),
148-
))
140+
tstr.RunMain(m, tstr.WithDeps(
141+
container.New(
142+
container.WithModule(postgres.Run, "postgres:16-alpine",
143+
postgres.WithDatabase("test"),
144+
postgres.WithUsername("user"),
145+
postgres.WithPassword("password"),
146+
),
147+
),
148+
))
149149
}
150150
```
151151

@@ -157,13 +157,13 @@ This example compiles `my-app` Go application, instruments it for coverage colle
157157

158158
```go
159159
func TestMain(m *testing.M) {
160-
tstr.RunMain(m, tstr.WithDeps(
161-
cmd.New(
162-
cmd.WithGoCode("../", "./cmd/my-app"),
163-
cmd.WithReadyHTTP("http://localhost:8080/ready"),
164-
cmd.WithEnvAppend("GOCOVERDIR=./cover"),
165-
),
166-
))
160+
tstr.RunMain(m, tstr.WithDeps(
161+
cmd.New(
162+
cmd.WithGoCode("../", "./cmd/my-app"),
163+
cmd.WithReadyHTTP("http://localhost:8080/ready"),
164+
cmd.WithEnvAppend("GOCOVERDIR=./cover"),
165+
),
166+
))
167167
}
168168
```
169169

@@ -175,7 +175,7 @@ You can also create your own custom dependencies by implementing the `tstr.Depen
175175
type Custom struct{}
176176

177177
func New() *Custom {
178-
return &Custom{}
178+
return &Custom{}
179179
}
180180

181181
func (c *Custom) Start() error { return nil }

0 commit comments

Comments
 (0)