| 1 | package acm |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "log" |
| 6 | "os" |
| 7 | "fmt" |
| 8 | ) |
| 9 | |
| 10 | func getClient() *Client { |
| 11 | client, err := NewClient(func(c *Client) { |
| 12 | c.AccessKey = os.Getenv("AccessKeyId") |
| 13 | c.SecretKey = os.Getenv("AccessKeySecret") |
| 14 | c.EndPoint = "acm.aliyun.com" |
| 15 | c.NameSpace = "test" |
| 16 | }) |
| 17 | |
| 18 | if err != nil { |
| 19 | log.Fatal(err) |
| 20 | } |
| 21 | |
| 22 | return client |
| 23 | } |
| 24 | |
| 25 | func RunWithTest(t *testing.T, test func(client *Client, t *testing.T)) { |
| 26 | client := getClient() |
| 27 | defer client.Delete("test", "test") |
| 28 | |
| 29 | _, err := client.Publish("test", "test", "test") |
| 30 | |
| 31 | if err != nil { |
| 32 | t.Fatalf("pulish error:%s", err) |
| 33 | } |
| 34 | |
| 35 | test(client, t) |
| 36 | } |
| 37 | |
| 38 | func TestNewClient(t *testing.T) { |
| 39 | client := getClient() |
| 40 | servers := client.GetServers() |
| 41 | |
| 42 | if len(servers) == 0 { |
| 43 | t.Error("get server error") |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | func TestClient_GetConfig(t *testing.T) { |
| 48 | RunWithTest(t, func(client *Client, t *testing.T) { |
| 49 | ret, err := client.GetConfig("test", "test") |
| 50 | if err != nil { |
| 51 | t.Error(err) |
| 52 | } |
| 53 | fmt.Println(ret) |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | func TestClient_Subscribe(t *testing.T) { |
| 58 | RunWithTest(t, func(client *Client, t *testing.T) { |
| 59 | _, err := client.Subscribe("test", "test","") |
| 60 | if err != nil { |
| 61 | t.Error(err) |
| 62 | } |
| 63 | }) |
| 64 | } |