File size: 636 Bytes
e48a2d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import (
	"errors"
	"testing"
)

// TestClassifyTrial 领取结果三态分类(纯函数,注释一直声称「供测试直接断言」,
// 此前没有这个测试)。
func TestClassifyTrial(t *testing.T) {
	if st, msg := classifyTrial(true, nil); st != trialOK || msg != "trial granted" {
		t.Errorf("claimed: %q %q", st, msg)
	}
	if st, _ := classifyTrial(false, nil); st != trialAlready {
		t.Errorf("idempotent: %q", st)
	}
	wrapped := errors.New("code=14051 already claimed")
	if st, msg := classifyTrial(false, wrapped); st != trialFailed || msg != wrapped.Error() {
		t.Errorf("error: %q %q", st, msg)
	}
}