Skip to content

Commit

Permalink
daily
Browse files Browse the repository at this point in the history
  • Loading branch information
haunt98 committed Dec 14, 2024
1 parent e2681e1 commit 2f79894
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 109 deletions.
66 changes: 33 additions & 33 deletions docs/2022-07-10-bootstrap-go.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/2022-07-31-experiment-go.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ <h2 class="heading-element">
}

<span class="pl-c">// c is Client</span>
<span class="pl-s1">c</span>.<span class="pl-en">GetUser</span>()
<span class="pl-s1">c</span>.<span class="pl-en">RemoveAccount</span>()</pre>
<span class="pl-s1">c</span>.<span class="pl-c1">GetUser</span>()
<span class="pl-s1">c</span>.<span class="pl-c1">RemoveAccount</span>()</pre>
</div>
<p>Try:</p>
<div class="highlight highlight-source-go">
Expand All @@ -104,8 +104,8 @@ <h2 class="heading-element">
}

<span class="pl-c">// c is Client</span>
<span class="pl-s1">c</span>.<span class="pl-c1">User</span>.<span class="pl-en">Get</span>()
<span class="pl-s1">c</span>.<span class="pl-c1">Account</span>.<span class="pl-en">Remove</span>()</pre>
<span class="pl-s1">c</span>.<span class="pl-c1">User</span>.<span class="pl-c1">Get</span>()
<span class="pl-s1">c</span>.<span class="pl-c1">Account</span>.<span class="pl-c1">Remove</span>()</pre>
</div>
<p>
The difference is <code>c.GetUser()</code> -&gt;
Expand Down
9 changes: 9 additions & 0 deletions docs/2022-07-31-sql.html
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ <h2 class="heading-element">Thanks</h2>
>
</p>
</li>
<li>
<p>
<a
href="https://www.depesz.com/2024/12/01/sql-best-practices-dont-compare-count-with-0/"
rel="nofollow"
>SQL best practices – don’t compare count(*) with 0</a
>
</p>
</li>
</ul>

<div>
Expand Down
46 changes: 23 additions & 23 deletions docs/2022-12-25-go-test-asap.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,25 +141,25 @@ <h2 class="heading-element">Let the fun (writing test) begin</h2>
<span class="pl-c1">verifyService</span> <span class="pl-smi">VerifyService</span>
}

<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">service</span>) <span class="pl-en">Upload</span>(<span class="pl-s1">ctx</span> context.<span class="pl-smi">Context</span>, <span class="pl-s1">req</span> <span class="pl-smi">Request</span>) <span class="pl-smi">error</span> {
<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">service</span>) <span class="pl-c1">Upload</span>(<span class="pl-s1">ctx</span> context.<span class="pl-smi">Context</span>, <span class="pl-s1">req</span> <span class="pl-smi">Request</span>) <span class="pl-smi">error</span> {
<span class="pl-c">// I simplify by omitting the response, only care error for now</span>
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-en">Verify</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-c1">Verify</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">return</span> <span class="pl-s1">err</span>
}

<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">minio</span>.<span class="pl-en">Put</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">minio</span>.<span class="pl-c1">Put</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">return</span> <span class="pl-s1">err</span>
}

<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">redis</span>.<span class="pl-en">Set</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">redis</span>.<span class="pl-c1">Set</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">return</span> <span class="pl-s1">err</span>
}

<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">db</span>.<span class="pl-en">Save</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">db</span>.<span class="pl-c1">Save</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">return</span> <span class="pl-s1">err</span>
}

<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">logService</span>.<span class="pl-en">Save</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">if</span> <span class="pl-s1">err</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">logService</span>.<span class="pl-c1">Save</span>(<span class="pl-s1">req</span>); <span class="pl-s1">err</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-k">return</span> <span class="pl-s1">err</span>
}

Expand All @@ -184,12 +184,12 @@ <h2 class="heading-element">Let the fun (writing test) begin</h2>
<span class="pl-c1">s</span> <span class="pl-smi">service</span>
}

<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-en">SetupTest</span>() {
<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-c1">SetupTest</span>() {
<span class="pl-c">// Init mock</span>
<span class="pl-c">// Init service</span>
}

<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-en">TestUpload</span>() {
<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-c1">TestUpload</span>() {
<span class="pl-s1">tests</span> <span class="pl-c1">:=</span> []<span class="pl-k">struct</span>{
<span class="pl-c1">name</span> <span class="pl-smi">string</span>
<span class="pl-c1">req</span> <span class="pl-smi">Request</span>
Expand All @@ -206,15 +206,15 @@ <h2 class="heading-element">Let the fun (writing test) begin</h2>
}

<span class="pl-k">for</span> <span class="pl-s1">_</span>, <span class="pl-s1">tc</span> <span class="pl-c1">:=</span> <span class="pl-k">range</span> <span class="pl-s1">tests</span> {
<span class="pl-s1">s</span>.<span class="pl-en">Run</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">name</span>, <span class="pl-k">func</span>(){
<span class="pl-s1">s</span>.<span class="pl-c1">Run</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">name</span>, <span class="pl-k">func</span>(){
<span class="pl-c">// Mock all error depends on test case</span>
<span class="pl-k">if</span> <span class="pl-s1">tc</span>.<span class="pl-c1">verifyErr</span> <span class="pl-c1">!=</span> <span class="pl-c1">nil</span> {
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-en">MockVerify</span>().<span class="pl-en">Return</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">verifyErr</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-c1">MockVerify</span>().<span class="pl-c1">Return</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">verifyErr</span>)
}
<span class="pl-c">// ...</span>

<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-en">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-en">Equal</span>(<span class="pl-s1">wantErr</span>, <span class="pl-s1">gotErr</span>)
<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-c1">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">Equal</span>(<span class="pl-s1">wantErr</span>, <span class="pl-s1">gotErr</span>)
})
}
}</pre>
Expand Down Expand Up @@ -326,36 +326,36 @@ <h2 class="heading-element">Let the fun (writing test) begin</h2>
<div class="highlight highlight-source-go">
<pre><span class="pl-c">// Init ServiceSuite as above</span>

<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-en">TestUpload</span>() {
<span class="pl-k">func</span> (<span class="pl-s1">s</span> <span class="pl-c1">*</span><span class="pl-smi">ServiceSuite</span>) <span class="pl-c1">TestUpload</span>() {
<span class="pl-c">// Init success request</span>
<span class="pl-s1">req</span> <span class="pl-c1">:=</span> <span class="pl-smi">Request</span>{
<span class="pl-c">// ...</span>
}

<span class="pl-c">// Init success action</span>
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-en">MockVerify</span>().<span class="pl-en">Return</span>(<span class="pl-c1">nil</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-c1">MockVerify</span>().<span class="pl-c1">Return</span>(<span class="pl-c1">nil</span>)
<span class="pl-c">// ...</span>

<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-en">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-en">NoError</span>(<span class="pl-s1">gotErr</span>)
<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-c1">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">NoError</span>(<span class="pl-s1">gotErr</span>)

<span class="pl-s1">s</span>.<span class="pl-en">Run</span>(<span class="pl-s">"failed"</span>, <span class="pl-k">func</span>(){
<span class="pl-s1">s</span>.<span class="pl-c1">Run</span>(<span class="pl-s">"failed"</span>, <span class="pl-k">func</span>(){
<span class="pl-c">// Alter failed request from default</span>
<span class="pl-s1">req</span> <span class="pl-c1">:=</span> <span class="pl-smi">Request</span>{
<span class="pl-c">// ...</span>
}

<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-en">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-en">Error</span>(<span class="pl-s1">gotErr</span>)
<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-c1">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">Error</span>(<span class="pl-s1">gotErr</span>)
})

<span class="pl-s1">s</span>.<span class="pl-en">Run</span>(<span class="pl-s">"another failed"</span>, <span class="pl-k">func</span>(){
<span class="pl-s1">s</span>.<span class="pl-c1">Run</span>(<span class="pl-s">"another failed"</span>, <span class="pl-k">func</span>(){
<span class="pl-c">// Alter verify return</span>
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-en">MockVerify</span>().<span class="pl-en">Return</span>(<span class="pl-s1">someErr</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">verifyService</span>.<span class="pl-c1">MockVerify</span>().<span class="pl-c1">Return</span>(<span class="pl-s1">someErr</span>)


<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-en">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-en">Error</span>(<span class="pl-s1">gotErr</span>)
<span class="pl-s1">gotErr</span> <span class="pl-c1">:=</span> <span class="pl-s1">s</span>.<span class="pl-c1">service</span>.<span class="pl-c1">Upload</span>(<span class="pl-s1">tc</span>.<span class="pl-c1">req</span>)
<span class="pl-s1">s</span>.<span class="pl-c1">Error</span>(<span class="pl-s1">gotErr</span>)
})

<span class="pl-c">// ...</span>
Expand Down
Loading

0 comments on commit 2f79894

Please sign in to comment.