Skip to content

Commit 24a2c0f

Browse files
committed
test(kerberos): add TestMethod for testing defineOperation
1 parent c561655 commit 24a2c0f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/kerberos.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "kerberos.h"
2+
#include "kerberos_worker.h"
23

34
/// KerberosClient
45
Nan::Persistent<v8::Function> KerberosClient::constructor;
@@ -128,6 +129,25 @@ NAN_GETTER(KerberosServer::ContextCompleteGetter) {
128129
info.GetReturnValue().Set(Nan::New(server->_state->context_complete));
129130
}
130131

132+
NAN_METHOD(TestMethod) {
133+
std::string string(*Nan::Utf8String(info[0]));
134+
bool shouldError = info[1]->BooleanValue();
135+
Nan::Callback* callback = new Nan::Callback(Nan::To<v8::Function>(info[2]).ToLocalChecked());
136+
137+
KerberosWorker::Run(callback, "kerberos:TestMethod", [=](KerberosWorker::SetOnFinishedHandler onFinished) {
138+
return onFinished([=](KerberosWorker* worker) {
139+
Nan::HandleScope scope;
140+
if (shouldError) {
141+
v8::Local<v8::Value> argv[] = {Nan::Error("an error occurred"), Nan::Null()};
142+
worker->Call(2, argv);
143+
} else {
144+
v8::Local<v8::Value> argv[] = {Nan::Null(), Nan::Null()};
145+
worker->Call(2, argv);
146+
}
147+
});
148+
});
149+
}
150+
131151
NAN_MODULE_INIT(Init) {
132152
// Custom types
133153
KerberosClient::Init(target);
@@ -145,6 +165,9 @@ NAN_MODULE_INIT(Init) {
145165
Nan::Set(target,
146166
Nan::New("checkPassword").ToLocalChecked(),
147167
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(CheckPassword)).ToLocalChecked());
168+
Nan::Set(target,
169+
Nan::New("_testMethod").ToLocalChecked(),
170+
Nan::GetFunction(Nan::New<v8::FunctionTemplate>(TestMethod)).ToLocalChecked());
148171
}
149172

150173
NODE_MODULE(kerberos, Init)

src/kerberos.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ NAN_METHOD(InitializeClient);
5959
NAN_METHOD(InitializeServer);
6060
NAN_METHOD(CheckPassword);
6161

62+
// NOTE: explicitly used for unit testing `defineOperation`, not meant to be exported
63+
NAN_METHOD(TestMethod);
64+
6265
#endif // KERBEROS_NATIVE_EXTENSION_H

0 commit comments

Comments
 (0)