Skip to content

Commit ad7679b

Browse files
authored
Merge pull request #3 from madflojo/tempfiles
Fixing code examples
2 parents f53d6d8 + 7a2bd7a commit ad7679b

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

README.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ Overall, testcerts simplifies the process of generating and managing test certif
1717
The `GenerateCertsToFile` function generates an X.509 certificate and key and writes them to the file paths provided.
1818

1919
```go
20-
package main
21-
22-
import (
23-
"github.com/madflojo/testcerts"
24-
)
25-
26-
func main() {
27-
err := testcerts.GenerateCertsToFile("/tmp/cert.pem", "/tmp/key.pem")
20+
func TestSomething(t *testing.T) {
21+
err := testcerts.GenerateCertsToFile("/tmp/cert", "/tmp/key")
2822
if err != nil {
29-
// handle error
23+
// do stuff
3024
}
25+
26+
_ = something.Run("/tmp/cert", "/tmp/key")
27+
// do more testing
3128
}
3229
```
3330

@@ -36,17 +33,14 @@ func main() {
3633
The `GenerateCertsToTempFile` function generates an X.509 certificate and key and writes them to randomly generated files in the directory provided or the system's temporary directory if none is provided. The function returns the file paths of the generated files.
3734

3835
```go
39-
package main
40-
41-
import (
42-
"github.com/madflojo/testcerts"
43-
)
44-
45-
func main() {
36+
func TestSomething(t *testing.T) {
4637
certFile, keyFile, err := testcerts.GenerateCertsToTempFile("/tmp/")
4738
if err != nil {
48-
// handle error
39+
// do stuff
4940
}
41+
42+
_ = something.Run(certFile, keyFile)
43+
// do more testing
5044
}
5145
```
5246

@@ -55,21 +49,14 @@ func main() {
5549
The `GenerateCerts` function generates an X.509 certificate and key and returns them as byte slices.
5650

5751
```go
58-
package main
59-
60-
import (
61-
"fmt"
62-
63-
"github.com/madflojo/testcerts"
64-
)
65-
66-
func main() {
52+
func TestSomething(t *testing.T) {
6753
cert, key, err := testcerts.GenerateCerts()
6854
if err != nil {
69-
// handle error
55+
// do stuff
7056
}
71-
fmt.Printf("Certificate: %s\n", cert)
72-
fmt.Printf("Key: %s\n", key)
57+
58+
_ = something.Run(cert, key)
59+
// do more testing
7360
}
7461
```
7562

testcerts.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,14 @@ named file in a specified or temporary directory.
77
88
For example, to generate and save a certificate and key to a temporary directory:
99
10-
package main
11-
12-
import (
13-
"fmt"
14-
"log"
15-
16-
"testcerts"
17-
)
18-
19-
func main() {
20-
certPath, keyPath, err := testcerts.GenerateCertsToTempFile("")
10+
func TestSomething(t *testing.T) {
11+
certFile, keyFile, err := testcerts.GenerateCertsToTempFile("/tmp/")
2112
if err != nil {
22-
log.Fatal(err)
13+
// do stuff
2314
}
24-
fmt.Println("Certificate written to:", certPath)
25-
fmt.Println("Key written to:", keyPath)
15+
16+
_ = something.Run(certFile, keyFile)
17+
// do more testing
2618
}
2719
2820
This will create a temporary certificate and key and print the paths to where the files were written.

0 commit comments

Comments
 (0)