Skip to content
gqlxj1987's Blog
Go back

Bulletproof code in go

Edit page

原文链接

The task: building a server that really isn’t allowed to fail, a project where the cost of error is extraordinarily high

TDD is a great methodology that works well for some, but by itself it still isn’t enough. Even worse, TDD instills false confidence in code and may make developers lazy when considering paranoid edge cases.

No part of our confidence in our code can result from a manual QA process. Humans make mistakes. Human attention to detail deteriorates after doing the same mind-numbing task a hundred times in a row.

Tests must be fast. Blazingly fast.

If a test suite takes more than a few seconds to run, developers are likely going to become lazy, pushing code without running it.

Dealing gracefully with errors in runtime is a cornerstone for bulletproof code.

Complexity is the worst enemy of bulletproof code. One of the best ways to deal with complexity is divide and conquer — split the problem into smaller problems and solve each one separately.

面向接口编程,protobuf部分

package spec

import ...

var _ = Describe("Sanity", func() {

	var (
		node services.Node
	)

	BeforeEach(func() {
		node = services.NewNode()
		node.Start()
	})

	AfterEach(func() {
		node.Stop()
	})

	It("should show balances with GET /api/balance", func() {
		resp, err := http.Get("http://localhost:8080/api/balance?from=user1")
		Expect(err).ToNot(HaveOccurred())
		Expect(resp.StatusCode).To(Equal(http.StatusOK))
		Expect(ResponseBodyAsString(resp)).To(Equal("0"))
	})
  
})

sync.Map

Scafford started project包含各种测试目录部分,利用它来新建相关的project


Edit page
Share this post on:

Previous Post
how did sidecar get there
Next Post
Future of distributed data systems