-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
acc_test.go
118 lines (99 loc) · 2.92 KB
/
acc_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
116
117
118
package sdk_test
import (
"fmt"
"os"
"reflect"
"testing"
"time"
sdk "github.com/kislerdm/neon-sdk-go"
)
func TestSmoke(t *testing.T) {
if os.Getenv("TF_ACC") != "1" {
t.Skip("TF_ACC must be set to 1")
}
cl, err := sdk.NewClient(sdk.Config{Key: os.Getenv("NEON_API_KEY")})
if err != nil {
t.Fatalf("cannot initialise SDK: %v", err)
}
// GIVEN
// Project name and autoscalling limit
var wantName = fmt.Sprintf("%d", time.Now().UnixMilli())
var wantAutoscallingLimit sdk.ComputeUnit = 1. / 4
// WHEN
o, err := cl.CreateProject(
sdk.ProjectCreateRequest{
Project: sdk.ProjectCreateRequestProject{
Name: &wantName,
DefaultEndpointSettings: &sdk.DefaultEndpointSettings{
AutoscalingLimitMinCu: &wantAutoscallingLimit,
AutoscalingLimitMaxCu: &wantAutoscallingLimit,
},
},
},
)
if err != nil {
t.Fatal(err)
}
project := o.ProjectResponse.Project
projectID := project.ID
t.Run(
"shall create a project", func(t *testing.T) {
// THEN
if project.Name != wantName {
t.Errorf("unexpected error, project name does not match expected %s", wantName)
}
gotAutoscallingLimit := project.DefaultEndpointSettings.AutoscalingLimitMaxCu
if *gotAutoscallingLimit != wantAutoscallingLimit {
t.Errorf(
"unexpected autoscalling limit, want: %v, got: %v", wantAutoscallingLimit,
gotAutoscallingLimit,
)
}
gotAutoscallingLimit = project.DefaultEndpointSettings.AutoscalingLimitMinCu
if *gotAutoscallingLimit != wantAutoscallingLimit {
t.Errorf(
"unexpected autoscalling limit, want: %v, got: %v", wantAutoscallingLimit,
gotAutoscallingLimit,
)
}
if !reflect.DeepEqual(*project.Settings.AllowedIps.Ips, []string{}) || *project.Settings.AllowedIps.ProtectedBranchesOnly {
t.Errorf("unexpected project's allowed IPs: %v", *project.Settings.AllowedIps.Ips)
}
},
)
t.Run("shall grant and revoke permissions successfully", func(t *testing.T) {
// disposable email on yopmail.com
const grantee = "[email protected]"
resp, err := cl.ListProjectPermissions(projectID)
if err != nil {
t.Fatal(err)
}
initGrants := len(resp.ProjectPermissions)
if initGrants > 0 {
t.Errorf("unexpected number of granted permissions: want = 0, got = %d", initGrants)
}
r, err := cl.GrantPermissionToProject(projectID, sdk.GrantPermissionToProjectRequest{
Email: grantee,
})
if err != nil {
t.Fatal(err)
}
if r.GrantedToEmail != grantee {
t.Fatalf("unexpected grantee email was set. want = %s, got = %s", grantee, r.GrantedToEmail)
}
r, err = cl.RevokePermissionFromProject(projectID, r.ID)
if err != nil {
t.Fatal(err)
}
if r.RevokedAt == nil || r.GrantedAt.After(*r.RevokedAt) {
t.Fatal("unexpected revokedAt, it must be not nil and not before the grantedAt")
}
})
t.Cleanup(
func() {
if _, err := cl.DeleteProject(projectID); err != nil {
t.Errorf("cannot deleted project %s", projectID)
}
},
)
}