availability_test.go 1.33 KB
Newer Older
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
package integrationtest

import (
	"testing"

	as "git.autistici.org/ai3/accountserver"
)

func TestIntegration_CheckResourceAvailability(t *testing.T) {
	stop, _, c := startService(t)
	defer stop()

	testdata := []struct {
		rtype         string
		name          string
		expectedAvail bool
	}{
		{"email", "uno@investici.org", false},
		{"email", "due@investici.org", false},
		{"email", "tre@investici.org", false},
		{"email", "newsletter1@investici.org", false},
		{"email", "list4@investici.org", false},
		{"email", "new@investici.org", true},

		{"list", "newsletter1@investici.org", false},
		{"list", "list4@investici.org", false},

		{"newsletter", "newsletter1@investici.org", false},
		{"newsletter", "list4@investici.org", false},

		{"web", "due", false},
		{"web", "new", true},

		{"dav", "uno", false},
		{"dav", "new", true},
	}

	for _, td := range testdata {
		var resp as.CheckResourceAvailabilityResponse
		err := c.request("/api/resource/check_availability", &as.CheckResourceAvailabilityRequest{
			Type: td.rtype,
			Name: td.name,
		}, &resp)
		if err != nil {
			t.Errorf("CheckResourceAvailability(%s/%s) error: %v", td.rtype, td.name, err)
			continue
		}
		if resp.Available != td.expectedAvail {
			t.Errorf("CheckResourceAvailability(%s/%s) returned %v, expected %v", td.rtype, td.name, resp.Available, td.expectedAvail)
		}
	}
}