Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing code examples #3

Merged
merged 1 commit into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ Overall, testcerts simplifies the process of generating and managing test certif
The `GenerateCertsToFile` function generates an X.509 certificate and key and writes them to the file paths provided.

```go
package main

import (
"github.com/madflojo/testcerts"
)

func main() {
err := testcerts.GenerateCertsToFile("/tmp/cert.pem", "/tmp/key.pem")
func TestSomething(t *testing.T) {
err := testcerts.GenerateCertsToFile("/tmp/cert", "/tmp/key")
if err != nil {
// handle error
// do stuff
}

_ = something.Run("/tmp/cert", "/tmp/key")
// do more testing
}
```

Expand All @@ -36,17 +33,14 @@ func main() {
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.

```go
package main

import (
"github.com/madflojo/testcerts"
)

func main() {
func TestSomething(t *testing.T) {
certFile, keyFile, err := testcerts.GenerateCertsToTempFile("/tmp/")
if err != nil {
// handle error
// do stuff
}

_ = something.Run(certFile, keyFile)
// do more testing
}
```

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

```go
package main

import (
"fmt"

"github.com/madflojo/testcerts"
)

func main() {
func TestSomething(t *testing.T) {
cert, key, err := testcerts.GenerateCerts()
if err != nil {
// handle error
// do stuff
}
fmt.Printf("Certificate: %s\n", cert)
fmt.Printf("Key: %s\n", key)

_ = something.Run(cert, key)
// do more testing
}
```

Expand Down
20 changes: 6 additions & 14 deletions testcerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ named file in a specified or temporary directory.

For example, to generate and save a certificate and key to a temporary directory:

package main

import (
"fmt"
"log"

"testcerts"
)

func main() {
certPath, keyPath, err := testcerts.GenerateCertsToTempFile("")
func TestSomething(t *testing.T) {
certFile, keyFile, err := testcerts.GenerateCertsToTempFile("/tmp/")
if err != nil {
log.Fatal(err)
// do stuff
}
fmt.Println("Certificate written to:", certPath)
fmt.Println("Key written to:", keyPath)

_ = something.Run(certFile, keyFile)
// do more testing
}

This will create a temporary certificate and key and print the paths to where the files were written.
Expand Down