diff --git a/cmd/daemon/before_test.go b/cmd/daemon/before_test.go index 19b1bc0aae97faf9ea13a5b6870cb490c5c5146b..d2a8f4168445ee6bc16b02623b99d3ddf2c1125d 100644 --- a/cmd/daemon/before_test.go +++ b/cmd/daemon/before_test.go @@ -9,7 +9,7 @@ // See the Mulan PSL v2 for more details. // Author: Xiang Li // Create: 2020-01-20 -// Description: This file is used for isula-build daemon testing +// Description: This file is used for isula-build cmd/daemon testing package main @@ -27,6 +27,12 @@ import ( "isula.org/isula-build/store" ) +func TestBefor(t *testing.T) { + cmd := newDaemonCommand() + err := before(cmd) + assert.NilError(t, err) +} + func TestSetupWorkingDirectories(t *testing.T) { var testDir *fs.Dir var testcases = []struct { diff --git a/cmd/daemon/main_test.go b/cmd/daemon/main_test.go new file mode 100644 index 0000000000000000000000000000000000000000..85e7b94919b3b62f17ad8e98584dc02a99b05136 --- /dev/null +++ b/cmd/daemon/main_test.go @@ -0,0 +1,27 @@ +// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +// isula-build licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +// PURPOSE. +// See the Mulan PSL v2 for more details. +// Author: Weizheng Xing +// Create: 2022-12-08 +// Description: This file is used for isula-build cmd/daemon testing + +package main + +import ( + "testing" + + "gotest.tools/v3/assert" +) + +func TestRunDaemon(t *testing.T) { + cmd := newDaemonCommand() + daemonOpts.Group = "none" + err := runDaemon(cmd, []string{}) + assert.ErrorContains(t, err, "create new GRPC socket failed") +} diff --git a/daemon/build_test.go b/daemon/build_test.go new file mode 100644 index 0000000000000000000000000000000000000000..aef31b43ee6aae139c0034cba22f5d7ad512b293 --- /dev/null +++ b/daemon/build_test.go @@ -0,0 +1,44 @@ +// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +// isula-build licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +// PURPOSE. +// See the Mulan PSL v2 for more details. +// Author: Weizheng Xing +// Create: 2022-11-29 +// Description: This file is for build test. + +package daemon + +import ( + "context" + "testing" + + "gotest.tools/v3/assert" + + constant "isula.org/isula-build" + pb "isula.org/isula-build/api/services" + "isula.org/isula-build/util" +) + +func TestBuild(t *testing.T) { + d := prepare(t) + defer tmpClean(d) + + _, err := d.Daemon.backend.Build(context.Background(), &pb.BuildRequest{}) + assert.ErrorContains(t, err, "is not supported") + + _, err = d.Daemon.backend.Build(context.Background(), &pb.BuildRequest{BuildType: "ctr-img"}) + assert.ErrorContains(t, err, "wrong image format provided") + + buildID := util.GenerateNonCryptoID()[:constant.DefaultIDLen] + go func() { + <-d.Daemon.backend.syncBuildStatus(buildID) + }() + _, err = d.Daemon.backend.Build(context.Background(), + &pb.BuildRequest{BuildType: "ctr-img", Format: "oci", BuildID: buildID}) + assert.ErrorContains(t, err, "parse dockerfile failed") +} diff --git a/daemon/daemon_test.go b/daemon/daemon_test.go new file mode 100644 index 0000000000000000000000000000000000000000..9180cae5d382c5cc412806b5196920cfc2e9efdc --- /dev/null +++ b/daemon/daemon_test.go @@ -0,0 +1,45 @@ +// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +// isula-build licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +// PURPOSE. +// See the Mulan PSL v2 for more details. +// Author: Weizheng Xing +// Create: 2022-11-29 +// Description: This file is for build test. + +package daemon + +import ( + "context" + "testing" + + "gotest.tools/v3/assert" + + pb "isula.org/isula-build/api/services" +) + +func TestNewDaemon(t *testing.T) { + _, err := NewDaemon(Options{}, nil) + assert.NilError(t, err) +} + +func TestRun(t *testing.T) { + d := prepare(t) + defer tmpClean(d) + + err := d.Daemon.Run() + assert.ErrorContains(t, err, "create new GRPC socket failed") + d.Daemon.Cleanup() +} + +func TestNewBuilder(t *testing.T) { + d := prepare(t) + defer tmpClean(d) + + _, err := d.Daemon.NewBuilder(context.Background(), &pb.BuildRequest{BuildType: "ctr-img", Format: "oci"}) + assert.NilError(t, err) +} diff --git a/daemon/grpc_server_test.go b/daemon/grpc_server_test.go new file mode 100644 index 0000000000000000000000000000000000000000..3b42f7c8f1022a99210fa25990f2fa404a632aa2 --- /dev/null +++ b/daemon/grpc_server_test.go @@ -0,0 +1,38 @@ +// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +// isula-build licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +// PURPOSE. +// See the Mulan PSL v2 for more details. +// Author: Weizheng Xing +// Create: 2022-11-29 +// Description: This file is for grpc server test. + +package daemon + +import ( + "context" + "testing" + + "gotest.tools/v3/assert" +) + +func TestRunGrpc(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + d := prepare(t) + defer tmpClean(d) + + d.Daemon.opts.Group = "isula" + err := d.Daemon.NewGrpcServer() + assert.NilError(t, err) + + errCh := make(chan error) + err = d.Daemon.grpc.Run(ctx, errCh, cancel) + assert.NilError(t, err) + +} diff --git a/daemon/info_test.go b/daemon/info_test.go new file mode 100644 index 0000000000000000000000000000000000000000..932d04f02f5f12a3536f973a4a70971c3dc29d40 --- /dev/null +++ b/daemon/info_test.go @@ -0,0 +1,38 @@ +// Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved. +// isula-build licensed under the Mulan PSL v2. +// You can use this software according to the terms and conditions of the Mulan PSL v2. +// You may obtain a copy of Mulan PSL v2 at: +// http://license.coscl.org.cn/MulanPSL2 +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR +// PURPOSE. +// See the Mulan PSL v2 for more details. +// Author: Weizheng Xing +// Create: 2022-11-29 +// Description: This file is for info test. + +package daemon + +import ( + "context" + "testing" + + "gotest.tools/v3/assert" + + pb "isula.org/isula-build/api/services" +) + +func TestInfo(t *testing.T) { + d := prepare(t) + defer tmpClean(d) + + _, err := d.Daemon.backend.Info(context.Background(), &pb.InfoRequest{}) + assert.NilError(t, err) + _, err = d.Daemon.backend.Info(context.Background(), &pb.InfoRequest{Verbose: true}) + assert.NilError(t, err) +} + +func TestGetRegistryInfo(t *testing.T) { + _, _, _, err := getRegistryInfo() + assert.NilError(t, err) +} diff --git a/daemon/pull_test.go b/daemon/pull_test.go index b296bfd06d5613f79e7d8b9bae0448d9f11ca943..a758de919d9b4859704adc260cb555d6bb885179 100644 --- a/daemon/pull_test.go +++ b/daemon/pull_test.go @@ -31,6 +31,7 @@ import ( constant "isula.org/isula-build" pb "isula.org/isula-build/api/services" + "isula.org/isula-build/builder" _ "isula.org/isula-build/exporter/docker" "isula.org/isula-build/pkg/logger" "isula.org/isula-build/store" @@ -84,6 +85,8 @@ func prepare(t *testing.T) daemonTestOptions { opts: opt, localStore: &localStore, key: localKey, + builders: make(map[string]builder.Builder), + entities: make(map[string]string), } dOpt.Daemon.NewBackend() return dOpt