Skip to content

Commit 3dca955

Browse files
committed
Add a simple test to the sdk
Signed-off-by: Jannik Hollenbach <jannik.hollenbach@iteratec.com>
1 parent 3d52d87 commit 3dca955

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎hook-sdk/golang/sdk_test.go‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,48 @@ func TestHookRequestDefersOperationsAndPassesContext(t *testing.T) {
9393
}
9494
}
9595
}
96+
97+
type recordingHandler struct {
98+
request HookRequest
99+
}
100+
101+
func (h *recordingHandler) Handle(_ context.Context, request HookRequest) error {
102+
h.request = request
103+
return nil
104+
}
105+
106+
func TestNewClientUsesInjectedK8sAndFileClients(t *testing.T) {
107+
t.Setenv("SCAN_NAME", "scan")
108+
t.Setenv("NAMESPACE", "default")
109+
110+
k8sClient := &stubK8sClient{}
111+
fileClient := &stubFileClient{}
112+
113+
client, err := NewClient(
114+
WithK8sClient(k8sClient),
115+
WithFileClient(fileClient),
116+
WithArgs([]string{"raw", "findings", "raw-upload", "findings-upload"}),
117+
)
118+
if err != nil {
119+
t.Fatal(err)
120+
}
121+
122+
handler := &recordingHandler{}
123+
if err := client.Run(context.Background(), handler); err != nil {
124+
t.Fatal(err)
125+
}
126+
127+
if _, err := handler.request.Scan(context.Background()); err != nil {
128+
t.Fatal(err)
129+
}
130+
if k8sClient.scanCtx == nil {
131+
t.Error("expected injected k8sClient to be used by Run, but GetScan was never called")
132+
}
133+
134+
if _, err := handler.request.GetRawResults(context.Background()); err != nil {
135+
t.Fatal(err)
136+
}
137+
if fileClient.downloadTextCtx == nil {
138+
t.Error("expected injected fileClient to be used by Run, but DownloadText was never called")
139+
}
140+
}

0 commit comments

Comments
 (0)