aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/pkg/module/quota_test.go
blob: 5b70cf77126900d0d5eed4d881d367410c72718a (plain)
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
package module

import (
	"testing"

	"github.com/pkg/errors"
)

func TestCreateQuota(t *testing.T) {

	mData := QMetaDataList{
		QuotaName: "test_quota",
	}

	q := Quota{
		MetaData: mData,
	}
	data1 := [][]byte{}

	key := QuotaKey{
		Project:          "test_project",
		LogicalCloudName: "test_asdf",
		QuotaName:        "test_quota",
	}
	myMocks := new(mockValues)
	// just to get an error value
	err1 := errors.New("math: square root of negative number")

	myMocks.On("CheckProject", "test_project").Return(nil)
	myMocks.On("CheckLogicalCloud", "test_project", "test_asdf").Return(nil)
	myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", q).Return(nil)
	myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, err1)

	qClient := QuotaClient{"test_dcm", "test_meta", myMocks}
	_, err := qClient.CreateQuota("test_project", "test_asdf", q)
	if err != nil {
		t.Errorf("Some error occured!")
	}
}

func TestGetQuota(t *testing.T) {
	key := QuotaKey{
		Project:          "test_project",
		LogicalCloudName: "test_asdf",
		QuotaName:        "test_quota",
	}

	data1 := [][]byte{
		[]byte("abc"),
	}

	data2 := []byte("abc")

	myMocks := new(mockValues)

	myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
	myMocks.On("DBUnmarshal", data2).Return(nil)
	qClient := QuotaClient{"test_dcm", "test_meta", myMocks}
	_, err := qClient.GetQuota("test_project", "test_asdf", "test_quota")
	if err != nil {
		t.Errorf("Some error occured!")
	}
}

func TestDeleteQuota(t *testing.T) {

	key := QuotaKey{
		Project:          "test_project",
		LogicalCloudName: "test_asdf",
		QuotaName:        "test_quota",
	}

	myMocks := new(mockValues)

	myMocks.On("DBRemove", "test_dcm", key).Return(nil)

	qClient := QuotaClient{"test_dcm", "test_meta", myMocks}
	err := qClient.DeleteQuota("test_project", "test_asdf", "test_quota")
	if err != nil {
		t.Errorf("Some error occured!")
	}

}

func TestUpdateQuota(t *testing.T) {
	key := QuotaKey{
		Project:          "test_project",
		LogicalCloudName: "test_asdf",
		QuotaName:        "test_quota",
	}
	mData := QMetaDataList{
		QuotaName: "test_quota",
	}
	q := Quota{
		MetaData: mData,
	}
	data1 := [][]byte{
		[]byte("abc"),
	}
	data2 := []byte("abc")

	myMocks := new(mockValues)

	myMocks.On("DBInsert", "test_dcm", key, nil, "test_meta", q).Return(nil)
	myMocks.On("DBFind", "test_dcm", key, "test_meta").Return(data1, nil)
	myMocks.On("DBUnmarshal", data2).Return(nil)
	qClient := QuotaClient{"test_dcm", "test_meta", myMocks}
	_, err := qClient.UpdateQuota("test_project", "test_asdf", "test_quota", q)
	if err != nil {
		t.Errorf("Some error occured!")
	}
}