@@ -85,6 +85,39 @@ func TestListDatabase_recordsError(t *testing.T) {
85
85
assert .Nil (t , subject .Value ())
86
86
}
87
87
88
+ func TestGetCertificate_success (t * testing.T ) {
89
+ client := & mockHttpClient {}
90
+ api := NewAPI (client , nil , nil )
91
+
92
+ expected := & DatabaseCertificate {
93
+ PublicCertificatePEMString : "test-certificate" ,
94
+ }
95
+
96
+ client .On ("Get" , context .TODO (), "get TLS certificate for database 123 in subscription 456" , "/subscriptions/456/databases/123/certificate" , mock .AnythingOfType ("*databases.DatabaseCertificate" )).
97
+ Run (func (args mock.Arguments ) {
98
+ cert := args .Get (3 ).(* DatabaseCertificate )
99
+ cert .PublicCertificatePEMString = "test-certificate"
100
+ }).Return (nil )
101
+
102
+ result , err := api .GetCertificate (context .TODO (), 456 , 123 )
103
+ assert .NoError (t , err )
104
+ assert .Equal (t , expected , result )
105
+ }
106
+
107
+ func TestGetCertificate_error (t * testing.T ) {
108
+ client := & mockHttpClient {}
109
+ api := NewAPI (client , nil , nil )
110
+
111
+ expected := fmt .Errorf ("test error" )
112
+ client .On ("Get" , context .TODO (), "get TLS certificate for database 123 in subscription 456" , "/subscriptions/456/databases/123/certificate" , mock .AnythingOfType ("*databases.DatabaseCertificate" )).
113
+ Return (expected )
114
+
115
+ result , err := api .GetCertificate (context .TODO (), 456 , 123 )
116
+ assert .Error (t , err )
117
+ assert .Equal (t , expected , err )
118
+ assert .Nil (t , result )
119
+ }
120
+
88
121
type mockHttpClient struct {
89
122
mock.Mock
90
123
}
0 commit comments