-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnextcloud_test.go
More file actions
92 lines (72 loc) · 1.92 KB
/
nextcloud_test.go
File metadata and controls
92 lines (72 loc) · 1.92 KB
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
package main
import (
"testing"
"github.com/h2non/gock"
"github.com/stretchr/testify/suite"
)
type NextcloudSuite struct {
suite.Suite
nextcloud *Nextcloud
}
func (s *NextcloudSuite) SetupTest() {
gock.DisableNetworking()
defer gock.Off()
config := &NextcloudConfig{
ApiUrl: "https://example.com/ocs/v2.php/apps/user_oidc/api/v1/user",
Username: "admin",
Password: "password",
ProviderID: "provider-id",
Domain: "example.com",
}
s.nextcloud = NewNextcloud(config)
}
func (s *NextcloudSuite) TestProvisionUser() {
s.Run("happy path", func() {
gock.New("https://example.com").
Post("/ocs/v2.php/apps/user_oidc/api/v1/user").
Reply(200)
err := s.nextcloud.ProvisionUser("user@example.com")
s.NoError(err)
})
s.Run("wrong domain", func() {
err := s.nextcloud.ProvisionUser("user@example.org")
s.Error(err)
})
s.Run("error path", func() {
gock.New("https://example.com").
Post("/ocs/v2.php/apps/user_oidc/api/v1/user").
Reply(500)
err := s.nextcloud.ProvisionUser("user@example.com")
s.Error(err)
})
}
func (s *NextcloudSuite) TestDeprovisionUser() {
s.Run("happy path", func() {
gock.New("https://example.com").
Delete("/ocs/v2.php/apps/user_oidc/api/v1/user/user").
Reply(200)
err := s.nextcloud.DeprovisionUser("user@example.com")
s.NoError(err)
})
s.Run("wrong domain", func() {
err := s.nextcloud.DeprovisionUser("user@example.org")
s.Error(err)
})
s.Run("user not found", func() {
gock.New("https://example.com").
Delete("/ocs/v2.php/apps/user_oidc/api/v1/user/user").
Reply(404)
err := s.nextcloud.DeprovisionUser("user@example.com")
s.NoError(err)
})
s.Run("error path", func() {
gock.New("https://example.com").
Delete("/ocs/v2.php/apps/user_oidc/api/v1/user/user").
Reply(500)
err := s.nextcloud.DeprovisionUser("user@example.com")
s.Error(err)
})
}
func TestNextcloudSuite(t *testing.T) {
suite.Run(t, new(NextcloudSuite))
}