Compare commits
3 Commits
515b1fbb46
...
c867d3a695
Author | SHA1 | Date |
---|---|---|
Maxim Lebedev | c867d3a695 | |
Maxim Lebedev | 156bf5fef1 | |
Maxim Lebedev | 4bfa9492a2 |
|
@ -0,0 +1,13 @@
|
|||
package path_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"source.toby3d.me/toby3d/hacks/path"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
head, tail := path.Shift("/foo/bar/index.html")
|
||||
fmt.Println(head, tail)
|
||||
// Output: foo /bar/index.html
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package pointer_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"source.toby3d.me/toby3d/hacks/pointer"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
val := struct {
|
||||
Text string
|
||||
}{Text: "Hello, World!"}
|
||||
fmt.Printf("Value: %v\n", val)
|
||||
|
||||
point := pointer.Of(val)
|
||||
point.Text = "Hello, Go!"
|
||||
fmt.Printf("Pointer: %v\n", point)
|
||||
|
||||
// Output:
|
||||
// Value: {Hello, World!}
|
||||
// Pointer: &{Hello, Go!}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, World!</h1>
|
||||
<p>This is a testing HTML page of example.com website.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -22,6 +22,9 @@ var update = flag.Bool("update", false, "save current tests results as golden fi
|
|||
// be overwritten with the provided contents of output, creating the testdata/
|
||||
// directory if it does not exist.
|
||||
//
|
||||
// Check TestGoldenEqual in testing_test.go and testdata/TestGoldenEqual.golden
|
||||
// for example usage.
|
||||
//
|
||||
// See: https://youtu.be/8hQG7QlcLBk?t=749
|
||||
//
|
||||
//nolint:cyclop // no need for splitting
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package testing_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
hacktesting "source.toby3d.me/toby3d/hacks/testing"
|
||||
)
|
||||
|
||||
func TestGoldenEqual(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "https://example.com/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
testHandler := func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, `<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Testing</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, World!</h1>
|
||||
<p>This is a testing HTML page of %s website.</p>
|
||||
</body>
|
||||
</html>`, r.Host) // NOTE(toby3d): Host must be 'example.com'
|
||||
}
|
||||
|
||||
testHandler(w, req)
|
||||
|
||||
// NOTE(toby3d): compare recorded response body against saved golden file
|
||||
hacktesting.GoldenEqual(t, w.Result().Body)
|
||||
}
|
Loading…
Reference in New Issue