forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 114
/
client_project_policy_test.go
86 lines (79 loc) · 2 KB
/
client_project_policy_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
package sls
import (
"fmt"
"os"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
func TestProjectPolicy(t *testing.T) {
suite.Run(t, new(ProjectPolicyTestSuite))
}
type ProjectPolicyTestSuite struct {
suite.Suite
endpoint string
projectName string
accessKeyID string
accessKeySecret string
client Client
policy string
newPolicy string
}
func (s *ProjectPolicyTestSuite) SetupSuite() {
s.endpoint = os.Getenv("LOG_TEST_ENDPOINT")
s.projectName = fmt.Sprintf("test-go-project-policy-%d", time.Now().Unix())
s.accessKeyID = os.Getenv("LOG_TEST_ACCESS_KEY_ID")
s.accessKeySecret = os.Getenv("LOG_TEST_ACCESS_KEY_SECRET")
s.client.AccessKeyID = s.accessKeyID
s.client.AccessKeySecret = s.accessKeySecret
s.client.Endpoint = s.endpoint
_, err := s.client.CreateProject(s.projectName, "")
s.Nil(err)
s.policy = `
{
"Statement": [
{
"Action": [
"log:Post*"
],
"Effect": "Deny",
"Resource": "acs:log:*:*:project/test-project-policy/*"
}
],
"Version": "1"
}`
s.newPolicy = `
{
"Statement": [
{
"Action": [
"log:Post*"
],
"Effect": "Allow",
"Resource": "acs:log:*:*:project/test-project-policy/*"
}
],
"Version": "1"
}`
}
func (s *ProjectPolicyTestSuite) TearDownSuite() {
err := s.client.DeleteProject(s.projectName)
s.Nil(err)
}
func (s *ProjectPolicyTestSuite) TestClient_CURDProjectPolicy() {
err := s.client.UpdateProjectPolicy(s.projectName, s.policy)
s.Require().Nil(err)
policy, err := s.client.GetProjectPolicy(s.projectName)
s.Require().Nil(err)
s.Require().Equal(policy, s.policy)
err = s.client.UpdateProjectPolicy(s.projectName, s.newPolicy)
s.Require().Nil(err)
newPolicy, err := s.client.GetProjectPolicy(s.projectName)
s.Require().Nil(err)
s.Require().Equal(newPolicy, s.newPolicy)
err = s.client.DeleteProjectPolicy(s.projectName)
s.Require().Nil(err)
policy, err = s.client.GetProjectPolicy(s.projectName)
s.Require().Nil(err)
s.Require().Empty(policy)
}