Daily Archives: 22.04.2019
How go code is being compiled to assembler code
https://go.godbolt.org/z/31FyJ3 I was interested in comparing line 15 vs line 17 of the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
package main import "fmt" type kv struct { key []byte value []byte } type sliceMap []kv func (sm *sliceMap) Add(k, v []byte) { kvs := *sm if cap(kvs) > len(kvs) { kvs = kvs[:len(kvs)+1] } else { kvs = append(kvs, kv{}) } kv := &kvs[len(kvs)-1] kv.key = append(kv.key[:0], k...) kv.value = append(kv.value[:0], v...) *sm = kvs } func main() { sm := sliceMap{} sm.Add([]byte("foo"), []byte("bar")) fmt.Println(sm) } |
E2E tests in go
I tried it via ginkgo and gomega. It has Agouti with WebDriver support out of the box, but I didn’t use it as we have grpc API. That’s the example (table tests):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
var _ = Describe("GetRoute", func() { var ( srClient sr.Client srErr error ) JustBeforeEach(func() { srClient, srErr = GetClient() }) DescribeTable("positive cases", func(fromGeoPointID, toGeoPointID int, expectedUID string, expectedCostGreaterThan float64) { Expect(srErr).NotTo(HaveOccurred()) Expect(srClient).NotTo(BeNil()) response, err := srClient.GetRoute(context.TODO(), &sr.GetRouteRequest{ FromGeoPointId: int64(fromGeoPointID), ToGeoPointId: int64(toGeoPointID), Quantity: 1, Volume: 1, Weight: 1, }) Expect(err).To(Succeed()) Expect(response).NotTo(BeNil()) Expect(response.RouteCost).NotTo(BeNil()) Expect(response.RouteCost.RouteUid).To(HaveSuffix(expectedUID)) Expect(response.RouteCost.GetCost()).To(BeNumerically(">", expectedCostGreaterThan)) }, Entry("from(geo=3)->to(geo=2)", 3, 2, "-3-2", float64(10)), ) |
What is teamlead’s first duty
Sarah Mei «We think awful code is written by awful devs. But in reality, it’s written by reasonable devs in awful circumstances.» (source) So, teamlead is there to improve circumstances.