From eaf86f3f4dc8a7190abf09fe840e20bcf83709d8 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 13 Feb 2025 13:59:19 +0100 Subject: syz-cluster/controller: move the API server to pkg/controller This will facilitate its reuse in tests. --- syz-cluster/pkg/controller/testutil.go | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 syz-cluster/pkg/controller/testutil.go (limited to 'syz-cluster/pkg/controller/testutil.go') diff --git a/syz-cluster/pkg/controller/testutil.go b/syz-cluster/pkg/controller/testutil.go new file mode 100644 index 000000000..0c33df139 --- /dev/null +++ b/syz-cluster/pkg/controller/testutil.go @@ -0,0 +1,43 @@ +// Copyright 2025 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package controller + +import ( + "context" + "net/http/httptest" + "testing" + + "github.com/google/syzkaller/syz-cluster/pkg/api" + "github.com/google/syzkaller/syz-cluster/pkg/app" + "github.com/stretchr/testify/assert" +) + +// UploadTestSeries returns a (session ID, series ID) tuple. +func UploadTestSeries(t *testing.T, ctx context.Context, + client *api.Client, series *api.Series) (string, string) { + retSeries, err := client.UploadSeries(ctx, series) + assert.NoError(t, err) + retSession, err := client.UploadSession(ctx, &api.NewSession{ + ExtID: series.ExtID, + }) + assert.NoError(t, err) + return retSeries.ID, retSession.ID +} + +func UploadTestBuild(t *testing.T, ctx context.Context, client *api.Client, + build *api.Build) *api.UploadBuildResp { + ret, err := client.UploadBuild(ctx, &api.UploadBuildReq{ + Build: *build, + }) + assert.NoError(t, err) + assert.NotEmpty(t, ret.ID) + return ret +} + +func TestServer(t *testing.T, env *app.AppEnvironment) *api.Client { + apiServer := NewAPIServer(env) + server := httptest.NewServer(apiServer.Mux()) + t.Cleanup(server.Close) + return api.NewClient(server.URL) +} -- cgit mrf-deployment