forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 114
/
project_test.go
115 lines (96 loc) · 3.08 KB
/
project_test.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package sls
import (
"fmt"
"os"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
func TestProject(t *testing.T) {
suite.Run(t, new(ProjectTestSuite))
}
type ProjectTestSuite struct {
suite.Suite
endpoint string
accessKeyID string
accessKeySecret string
projectName string
client Client
}
func (s *ProjectTestSuite) SetupSuite() {
s.endpoint = os.Getenv("LOG_TEST_ENDPOINT")
s.accessKeyID = os.Getenv("LOG_TEST_ACCESS_KEY_ID")
s.accessKeySecret = os.Getenv("LOG_TEST_ACCESS_KEY_SECRET")
s.projectName = fmt.Sprintf("test-go-project-%d", time.Now().Unix())
s.client = Client{
Endpoint: s.endpoint,
AccessKeyID: s.accessKeyID,
AccessKeySecret: s.accessKeySecret,
SecurityToken: "",
}
ok, err := s.client.CheckProjectExist(s.projectName)
if err == nil && !ok {
_, err = s.client.CreateProject(s.projectName, "")
s.Nil(err)
time.Sleep(10 * time.Second)
}
}
func (s *ProjectTestSuite) TearDownSuite() {
err := s.client.DeleteProject(s.projectName)
s.Require().Nil(err)
}
func (s *ProjectTestSuite) TestCheckProjectExist() {
exist, err := s.client.CheckProjectExist(s.projectName)
s.Nil(err)
s.True(exist)
}
func (s *ProjectTestSuite) TestParseEndpoint() {
assert := s.Require()
projectName := "my-project"
prj, err := NewLogProject(projectName, "127.0.0.1", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.127.0.0.1", prj.baseURL)
prj, err = NewLogProject(projectName, "http://127.0.0.1", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.127.0.0.1", prj.baseURL)
prj, err = NewLogProject(projectName, "http://127.0.0.1:8080", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.127.0.0.1:8080", prj.baseURL)
prj, err = NewLogProject(projectName, "log.aliyun.com", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.log.aliyun.com", prj.baseURL)
prj, err = NewLogProject(projectName, "http://log.aliyun.com", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.log.aliyun.com", prj.baseURL)
prj, err = NewLogProject(projectName, "http://log.aliyun.com:8000", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("http://my-project.log.aliyun.com:8000", prj.baseURL)
prj, err = NewLogProject(projectName, "https://log.aliyun.com:8000", "id", "key")
assert.Nil(err)
assert.NotNil(prj)
assert.Equal("https://my-project.log.aliyun.com:8000", prj.baseURL)
}
func (s *ProjectTestSuite) TestUpdateProject() {
_, err := s.client.UpdateProject(s.projectName, "aliyun log go sdk test.")
s.Nil(err)
}
func (s *ProjectTestSuite) TestCreateProjectV2() {
_, _ = s.client.GetProject(s.projectName)
v2 := s.projectName + "v2"
_, err := s.client.CreateProjectV2(v2, "test-project-v2", PROJECT_DATA_REDUNDANCY_TYPE_ZRS)
s.NoError(err)
proj, err := s.client.GetProject(v2)
s.NoError(err)
s.NotEmpty(proj.Location)
fmt.Println(proj.Name)
fmt.Println(proj.Location)
s.Equal(proj.DataRedundancyType, PROJECT_DATA_REDUNDANCY_TYPE_ZRS)
err = s.client.DeleteProject(v2)
s.NoError(err)
}