summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2022-05-20 16:11:45 -0600
committermo khan <mo@mokhan.ca>2022-05-20 16:11:45 -0600
commitfc897c425cfe258d8051785889ebe696fcdf21d7 (patch)
tree6cba4b4a39da3ba79d87003f4bef9efc447bab26
parent7115c4e45a7b04c4e823722b743b5bbcf43720bf (diff)
add notes on stub package
-rw-r--r--journal/2022-05-20.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/journal/2022-05-20.md b/journal/2022-05-20.md
index 437c3bb..0f195df 100644
--- a/journal/2022-05-20.md
+++ b/journal/2022-05-20.md
@@ -25,6 +25,29 @@ I learned:
I got the ok on building the API gateway as a reverse proxy using casbin, [Gatekeeper][11].
I also can't believe how easy it was to build a HTTP reverse proxy in golang.
+Oh, I almost forgot. I also made an attempt to write a small stubbing library.
+
+e.g.
+
+```golang
+type Greeting struct{}
+
+func (self *Greeting) Greet() string {
+ return "blah"
+}
+
+func TestStub(t *testing.T) {
+ t.Run("returns the stubbed value", func(t *testing.T) {
+ subject := &Greeting{}
+
+ Allow(&subject).ToReceive(subject.Greet).AndReturn("Hello")
+
+ assert.Equal(t, "Hello", subject.Greet())
+ })
+```
+
+It didn't work out because replacing methods at run time isn't [settable][13].
+
[1]: https://samnewman.io/books/building_microservices_2nd_edition/
[2]: https://www.packtpub.com/product/architects-of-intelligence/9781789954531
[3]: https://www.penguinrandomhouse.com/books/565698/genius-makers-by-cade-metz/
@@ -37,3 +60,4 @@ I also can't believe how easy it was to build a HTTP reverse proxy in golang.
[10]: https://caddyserver.com/docs/getting-started
[11]: https://github.com/zerocmd/gatekeeper
[12]: https://pkg.go.dev/net/http/httputil#example-ReverseProxy
+[13]: https://github.com/zerocmd/xlgmokha/blob/7115c4e45a7b04c4e823722b743b5bbcf43720bf/learn/golang/README.md#reflection