From 0331d69d2f9b54b48807c4ffd21fb95564947d34 Mon Sep 17 00:00:00 2001 From: daisicheng Date: Tue, 20 Dec 2022 18:44:18 +0800 Subject: [PATCH] add some DT tests --- VERSION-vendor | 2 +- git-commit | 2 +- isula-build.spec | 8 +- ...go-for-import.go-and-add-TestCleanCo.patch | 248 ++++++++ ...related-unit-tests-in-package-common.patch | 51 ++ ...ror-coverage-of-unit-tests-in-import.patch | 93 +++ ...ogout_test-remove_test-and-import_te.patch | 572 ++++++++++++++++++ ...ase-test-for-runDaemon-and-before-fu.patch | 73 +++ ...face-manifest-health-status-in-daemo.patch | 322 ++++++++++ ...st-in-daemon-for-euleros-and-openeul.patch | 32 + series.conf | 7 + 11 files changed, 1407 insertions(+), 3 deletions(-) create mode 100644 patch/0129-add-import_test.go-for-import.go-and-add-TestCleanCo.patch create mode 100644 patch/0130-add-copy-related-unit-tests-in-package-common.patch create mode 100644 patch/0131-improve-some-error-coverage-of-unit-tests-in-import.patch create mode 100644 patch/0132-add-login_test-logout_test-remove_test-and-import_te.patch create mode 100644 patch/0133-cmd-daemon-add-base-test-for-runDaemon-and-before-fu.patch create mode 100644 patch/0134-add-dt-for-interface-manifest-health-status-in-daemo.patch create mode 100644 patch/0135-fix-the-login_test-in-daemon-for-euleros-and-openeul.patch diff --git a/VERSION-vendor b/VERSION-vendor index 1d41aa7..9054c53 100644 --- a/VERSION-vendor +++ b/VERSION-vendor @@ -1 +1 @@ -0.9.6-15 +0.9.6-16 diff --git a/git-commit b/git-commit index 5481fd8..6340b6a 100644 --- a/git-commit +++ b/git-commit @@ -1 +1 @@ -a5b09eac902299ff56b460324b6cb4db18a16a25 +ed2c2b8cd969185451dd4507c4581942b33d5cbe diff --git a/isula-build.spec b/isula-build.spec index 6965e67..549a981 100644 --- a/isula-build.spec +++ b/isula-build.spec @@ -2,7 +2,7 @@ Name: isula-build Version: 0.9.6 -Release: 15 +Release: 16 Summary: A tool to build container images License: Mulan PSL V2 URL: https://gitee.com/openeuler/isula-build @@ -85,6 +85,12 @@ fi /usr/share/bash-completion/completions/isula-build %changelog +* Thu Dec 22 2022 daisicheng - 0.9.6-16 +- Type:bugfix +- CVE:NA +- SUG:restart +- DESC:add some DT tests + * Wed Dec 07 2022 jingxiaolu - 0.9.6-15 - Type:bugfix - CVE:NA diff --git a/patch/0129-add-import_test.go-for-import.go-and-add-TestCleanCo.patch b/patch/0129-add-import_test.go-for-import.go-and-add-TestCleanCo.patch new file mode 100644 index 0000000..7d70532 --- /dev/null +++ b/patch/0129-add-import_test.go-for-import.go-and-add-TestCleanCo.patch @@ -0,0 +1,248 @@ +From 374c6ece3d911d8b5bc72f4e04c4483061624e5a Mon Sep 17 00:00:00 2001 +From: daisicheng +Date: Thu, 20 Oct 2022 14:51:49 +0800 +Subject: [PATCH] add import_test.go for import.go and add TestCleanContainers + function for store.go + +--- + cmd/cli/import_test.go | 134 +++++++++++++++++++++++++++++++++++++++++ + cmd/cli/mock.go | 19 +++++- + store/store_test.go | 27 +++++++++ + 3 files changed, 178 insertions(+), 2 deletions(-) + create mode 100644 cmd/cli/import_test.go + +diff --git a/cmd/cli/import_test.go b/cmd/cli/import_test.go +new file mode 100644 +index 0000000..057bf17 +--- /dev/null ++++ b/cmd/cli/import_test.go +@@ -0,0 +1,134 @@ ++// 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: daisicheng ++// Create: 2022-10-20 ++// Description: This file is for image import test. ++ ++// Description: This file is is used for testing import command. ++package main ++ ++import ( ++ "context" ++ "io/ioutil" ++ "os" ++ "path/filepath" ++ "testing" ++ ++ "gotest.tools/v3/assert" ++ "gotest.tools/v3/fs" ++ ++ constant "isula.org/isula-build" ++) ++ ++const ExceededImportFileSize = 2048 * 1024 * 1024 ++ ++func TestImportCommand(t *testing.T) { ++ tmpFile := fs.NewFile(t, t.Name()) ++ exceededFile := fs.NewFile(t, t.Name()) ++ err := ioutil.WriteFile(tmpFile.Path(), []byte("This is test file"), constant.DefaultSharedFileMode) ++ assert.NilError(t, err) ++ err = ioutil.WriteFile(exceededFile.Path(), []byte("This is exceeded test file"), constant.DefaultSharedFileMode) ++ assert.NilError(t, err) ++ err = os.Truncate(exceededFile.Path(), ExceededImportFileSize) ++ assert.NilError(t, err) ++ defer tmpFile.Remove() ++ defer exceededFile.Remove() ++ ++ type testcase struct { ++ name string ++ errString string ++ args []string ++ wantErr bool ++ } ++ var testcases = []testcase{ ++ { ++ name: "TC1 - abnormal case with no args", ++ errString: "requires at least one argument", ++ wantErr: true, ++ }, ++ { ++ name: "TC2 - abnormal case with exceeded limit input", ++ args: []string{exceededFile.Path()}, ++ errString: "exceeds limit 1073741824", ++ wantErr: true, ++ }, ++ { ++ name: "TC3 - normal case", ++ args: []string{tmpFile.Path()}, ++ errString: "isula_build.sock", ++ wantErr: true, ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ importCmd := NewImportCmd() ++ err = importCommand(importCmd, tc.args) ++ if tc.wantErr { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if !tc.wantErr { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} ++ ++func TestRunImport(t *testing.T) { ++ ctx := context.Background() ++ mockImport := newMockDaemon() ++ cli := newMockClient(&mockGrpcClient{importFunc: mockImport.importImage}) ++ fileEmpty := "empty.tar" ++ fileNormal := "test.tar" ++ exceededFile := fs.NewFile(t, t.Name()) ++ err := ioutil.WriteFile(exceededFile.Path(), []byte("This is exceeded test file"), constant.DefaultSharedFileMode) ++ assert.NilError(t, err) ++ err = os.Truncate(exceededFile.Path(), ExceededImportFileSize) ++ assert.NilError(t, err) ++ ctxDir := fs.NewDir(t, "import", fs.WithFile(fileEmpty, ""), fs.WithFile(fileNormal, "test")) ++ defer ctxDir.Remove() ++ defer exceededFile.Remove() ++ ++ type testcase struct { ++ name string ++ source string ++ wantErr bool ++ errString string ++ } ++ var testcases = []testcase{ ++ { ++ name: "TC1 - abnormal case with empty file", ++ source: filepath.Join(ctxDir.Path(), fileEmpty), ++ wantErr: true, ++ errString: "empty", ++ }, ++ { ++ name: "TC2 - abnormal case with exceeded limit file", ++ source: exceededFile.Path(), ++ wantErr: true, ++ errString: "limit", ++ }, ++ { ++ name: "TC3 - normal case", ++ source: filepath.Join(ctxDir.Path(), fileNormal), ++ wantErr: false, ++ }, ++ } ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ importOpts.source = tc.source ++ err := runImport(ctx, &cli) ++ assert.Equal(t, err != nil, tc.wantErr, "Failed at [%s], err: %v", tc.name, err) ++ if err != nil { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ }) ++ } ++} +diff --git a/cmd/cli/mock.go b/cmd/cli/mock.go +index 23a8a03..d201fe0 100644 +--- a/cmd/cli/mock.go ++++ b/cmd/cli/mock.go +@@ -17,12 +17,14 @@ import ( + "context" + "io" + "os" ++ "path/filepath" + "testing" + + "github.com/gogo/protobuf/types" + "github.com/pkg/errors" + "google.golang.org/grpc" + ++ constant "isula.org/isula-build" + pb "isula.org/isula-build/api/services" + ) + +@@ -261,7 +263,7 @@ func (icli *mockImportClient) Recv() (*pb.ImportResponse, error) { + resp := &pb.ImportResponse{ + Log: "Import success with image id: " + imageID, + } +- return resp, nil ++ return resp, io.EOF + } + + func (icli *mockImportClient) Send(*pb.ImportRequest) error { +@@ -313,7 +315,20 @@ func (cli *mockClient) Close() error { + return nil + } + +-func (f *mockDaemon) importImage(_ context.Context, opts ...grpc.CallOption) (pb.Control_ImportClient, error) { ++func (f *mockDaemon) importImage(_ context.Context, in *pb.ImportRequest, opts ...grpc.CallOption) (pb.Control_ImportClient, error) { ++ f.importReq = in ++ source := f.importReq.Source ++ file, err := os.Stat(filepath.Clean(source)) ++ if err != nil { ++ return &mockImportClient{}, err ++ } ++ if file.Size() == 0 { ++ return &mockImportClient{}, errors.Errorf("file %s is empty", file.Name()) ++ } ++ if file.Size() > constant.MaxImportFileSize { ++ return &mockImportClient{}, errors.Errorf("file %s size is: %d, exceeds limit", file.Name(), file.Size()) ++ } ++ + return &mockImportClient{}, nil + } + +diff --git a/store/store_test.go b/store/store_test.go +index d99d871..77a9353 100644 +--- a/store/store_test.go ++++ b/store/store_test.go +@@ -36,6 +36,11 @@ func TestGetDefaultStoreOptions(t *testing.T) { + assert.NilError(t, err) + } + ++func TestGetStorageConfigFileOptions(t *testing.T) { ++ _, err := GetStorageConfigFileOptions() ++ assert.NilError(t, err) ++} ++ + func TestGetStore(t *testing.T) { + dataDir := "/tmp/lib" + runDir := "/tmp/run" +@@ -53,3 +58,25 @@ func TestGetStore(t *testing.T) { + assert.Equal(t, s.RunRoot(), storeOpts.RunRoot) + assert.Equal(t, s.GraphRoot(), storeOpts.DataRoot) + } ++ ++func TestCleanContainers(t *testing.T) { ++ dataDir := "/tmp/lib" ++ runDir := "/tmp/run" ++ storeOpts.DataRoot = filepath.Join(dataDir, "containers/storage") ++ storeOpts.RunRoot = filepath.Join(runDir, "containers/storage") ++ ++ s, err := GetStore() ++ assert.NilError(t, err) ++ s.CreateContainer("", []string{""}, "", "", "", nil) ++ s.CleanContainers() ++ containers, _ := s.Containers() ++ if len(containers) > 0 { ++ t.Errorf("Failed to clean containers") ++ } ++ defer func() { ++ unix.Unmount(filepath.Join(storeOpts.DataRoot, "overlay"), 0) ++ unix.Unmount(filepath.Join(storeOpts.RunRoot, "overlay"), 0) ++ os.RemoveAll(dataDir) ++ os.RemoveAll(runDir) ++ }() ++} +-- +2.33.0 + diff --git a/patch/0130-add-copy-related-unit-tests-in-package-common.patch b/patch/0130-add-copy-related-unit-tests-in-package-common.patch new file mode 100644 index 0000000..76cc970 --- /dev/null +++ b/patch/0130-add-copy-related-unit-tests-in-package-common.patch @@ -0,0 +1,51 @@ +From bf4d9f5638ab63d5272ccfb2689cdafc7b0adaf5 Mon Sep 17 00:00:00 2001 +From: jingxiaolu +Date: Mon, 31 Oct 2022 19:01:17 +0800 +Subject: [PATCH] add copy related unit tests in package common + +Signed-off-by: jingxiaolu +--- + util/common_test.go | 27 +++++++++++++++++++++++++++ + 1 file changed, 27 insertions(+) + +diff --git a/util/common_test.go b/util/common_test.go +index 7d2444a..263eae2 100644 +--- a/util/common_test.go ++++ b/util/common_test.go +@@ -21,6 +21,33 @@ import ( + "gotest.tools/v3/fs" + ) + ++func TestCopyMapStringString(t *testing.T) { ++ src := map[string]string{"isula": "build"} ++ dst := CopyMapStringString(src) ++ ++ assert.Equal(t, dst != nil, true) ++ assert.Equal(t, dst == nil, false) ++ assert.Equal(t, dst["isula"] == "build", true) ++} ++ ++func TestCopyStrings(t *testing.T) { ++ src := []string{"isula", "build"} ++ dst := CopyStrings(src) ++ ++ assert.Equal(t, dst != nil, true) ++ const dstLen = 2 ++ assert.Equal(t, len(dst) == dstLen, true) ++} ++ ++func TestCopyStringsWithoutSpecificElem(t *testing.T) { ++ src := []string{"isula", "build", "gogogo"} ++ dst := CopyStringsWithoutSpecificElem(src, "go") ++ ++ assert.Equal(t, dst != nil, true) ++ const dstLen = 2 ++ assert.Equal(t, len(dst) == dstLen, true) ++} ++ + func TestCheckFileInfoAndSize(t *testing.T) { + content := ` + ARG testArg +-- +2.33.0 + diff --git a/patch/0131-improve-some-error-coverage-of-unit-tests-in-import.patch b/patch/0131-improve-some-error-coverage-of-unit-tests-in-import.patch new file mode 100644 index 0000000..2984890 --- /dev/null +++ b/patch/0131-improve-some-error-coverage-of-unit-tests-in-import.patch @@ -0,0 +1,93 @@ +From 0c1f841e13e4cb70ff07e18ddfb53e8927edbe95 Mon Sep 17 00:00:00 2001 +From: daisicheng +Date: Tue, 1 Nov 2022 17:11:19 +0800 +Subject: [PATCH] improve some error coverage of unit tests in import_test and + store_test + +--- + cmd/cli/import_test.go | 9 ++++----- + store/store_test.go | 29 ++++++++++++++++++++++++++++- + 2 files changed, 32 insertions(+), 6 deletions(-) + +diff --git a/cmd/cli/import_test.go b/cmd/cli/import_test.go +index 057bf17..82983b0 100644 +--- a/cmd/cli/import_test.go ++++ b/cmd/cli/import_test.go +@@ -85,14 +85,13 @@ func TestRunImport(t *testing.T) { + ctx := context.Background() + mockImport := newMockDaemon() + cli := newMockClient(&mockGrpcClient{importFunc: mockImport.importImage}) +- fileEmpty := "empty.tar" + fileNormal := "test.tar" + exceededFile := fs.NewFile(t, t.Name()) + err := ioutil.WriteFile(exceededFile.Path(), []byte("This is exceeded test file"), constant.DefaultSharedFileMode) + assert.NilError(t, err) + err = os.Truncate(exceededFile.Path(), ExceededImportFileSize) + assert.NilError(t, err) +- ctxDir := fs.NewDir(t, "import", fs.WithFile(fileEmpty, ""), fs.WithFile(fileNormal, "test")) ++ ctxDir := fs.NewDir(t, "import", fs.WithFile(fileNormal, "test")) + defer ctxDir.Remove() + defer exceededFile.Remove() + +@@ -104,10 +103,10 @@ func TestRunImport(t *testing.T) { + } + var testcases = []testcase{ + { +- name: "TC1 - abnormal case with empty file", +- source: filepath.Join(ctxDir.Path(), fileEmpty), ++ name: "TC1 - abnormal case with relative path", ++ source: filepath.Join("./", fileNormal), + wantErr: true, +- errString: "empty", ++ errString: "no such file or directory", + }, + { + name: "TC2 - abnormal case with exceeded limit file", +diff --git a/store/store_test.go b/store/store_test.go +index 77a9353..360e4dd 100644 +--- a/store/store_test.go ++++ b/store/store_test.go +@@ -67,12 +67,39 @@ func TestCleanContainers(t *testing.T) { + + s, err := GetStore() + assert.NilError(t, err) +- s.CreateContainer("", []string{""}, "", "", "", nil) ++ s.CreateContainer("", []string{""}, "", "TC1", "", nil) + s.CleanContainers() + containers, _ := s.Containers() + if len(containers) > 0 { + t.Errorf("Failed to clean containers") + } ++ s.CreateContainer("", []string{""}, "", "TC2", "", nil) ++ err = os.RemoveAll(filepath.Join(storeOpts.DataRoot, "overlay-layers")) ++ assert.NilError(t, err) ++ s.CleanContainers() ++ ++ defer func() { ++ unix.Unmount(filepath.Join(storeOpts.DataRoot, "overlay"), 0) ++ unix.Unmount(filepath.Join(storeOpts.RunRoot, "overlay"), 0) ++ os.RemoveAll(dataDir) ++ os.RemoveAll(runDir) ++ }() ++} ++ ++func TestCleanContainer(t *testing.T) { ++ dataDir := "/tmp/lib" ++ runDir := "/tmp/run" ++ storeOpts.DataRoot = filepath.Join(dataDir, "containers/storage") ++ storeOpts.RunRoot = filepath.Join(runDir, "containers/storage") ++ ++ s, err := GetStore() ++ assert.NilError(t, err) ++ s.CreateContainer("", []string{""}, "", "TC1", "", nil) ++ err = s.CleanContainer("TC1") ++ assert.NilError(t, err) ++ err = s.CleanContainer("TC2") ++ assert.ErrorContains(t, err, "not a container") ++ + defer func() { + unix.Unmount(filepath.Join(storeOpts.DataRoot, "overlay"), 0) + unix.Unmount(filepath.Join(storeOpts.RunRoot, "overlay"), 0) +-- +2.33.0 + diff --git a/patch/0132-add-login_test-logout_test-remove_test-and-import_te.patch b/patch/0132-add-login_test-logout_test-remove_test-and-import_te.patch new file mode 100644 index 0000000..34e9eee --- /dev/null +++ b/patch/0132-add-login_test-logout_test-remove_test-and-import_te.patch @@ -0,0 +1,572 @@ +From 11fbc841b5af5ff4dd5ac228c033a49cac742aad Mon Sep 17 00:00:00 2001 +From: daisicheng +Date: Fri, 25 Nov 2022 17:40:33 +0800 +Subject: [PATCH] add login_test, logout_test, remove_test and import_test in + daemon + +--- + cmd/cli/build_test.go | 40 ++++++++++++++++ + daemon/import_test.go | 87 +++++++++++++++++++++++++++++++++++ + daemon/login_test.go | 103 ++++++++++++++++++++++++++++++++++++++++++ + daemon/logout_test.go | 75 ++++++++++++++++++++++++++++++ + daemon/pull_test.go | 7 ++- + daemon/remove_test.go | 101 +++++++++++++++++++++++++++++++++++++++++ + daemon/tag_test.go | 73 ++++++++++++++++++++++++++++++ + 7 files changed, 485 insertions(+), 1 deletion(-) + create mode 100644 daemon/import_test.go + create mode 100644 daemon/login_test.go + create mode 100644 daemon/logout_test.go + create mode 100644 daemon/remove_test.go + create mode 100644 daemon/tag_test.go + +diff --git a/cmd/cli/build_test.go b/cmd/cli/build_test.go +index d446801..41cabbe 100644 +--- a/cmd/cli/build_test.go ++++ b/cmd/cli/build_test.go +@@ -29,6 +29,46 @@ import ( + "isula.org/isula-build/util" + ) + ++func TestBuildCommand(t *testing.T) { ++ dockerfile := `` ++ filename := "Dockerfile" ++ tmpDir := fs.NewDir(t, t.Name(), fs.WithFile(filename, dockerfile)) ++ defer tmpDir.Remove() ++ ++ type testcase struct { ++ name string ++ file string ++ args []string ++ wanterr bool ++ errString string ++ } ++ var testcases = []testcase{ ++ { ++ name: "TC1 - normal case", ++ file: tmpDir.Path(), ++ args: []string{tmpDir.Path()}, ++ wanterr: true, ++ errString: "isula_build.sock", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ buildCmd := NewBuildCmd() ++ err := buildCmd.Execute() ++ assert.Equal(t, err != nil, true) ++ ++ err = buildCommand(buildCmd, tc.args) ++ if tc.wanterr { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if !tc.wanterr { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} ++ + func TestRunBuildWithLocalDockerfile(t *testing.T) { + dockerfile := ` + FROM alpine:latest +diff --git a/daemon/import_test.go b/daemon/import_test.go +new file mode 100644 +index 0000000..1a24eb4 +--- /dev/null ++++ b/daemon/import_test.go +@@ -0,0 +1,87 @@ ++// 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: daisicheng ++// Create: 2022-12-01 ++// Description: This file tests import interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "io/ioutil" ++ "testing" ++ ++ "github.com/pkg/errors" ++ "google.golang.org/grpc" ++ "gotest.tools/v3/assert" ++ "gotest.tools/v3/fs" ++ ++ constant "isula.org/isula-build" ++ pb "isula.org/isula-build/api/services" ++ "isula.org/isula-build/util" ++) ++ ++type controlImportServer struct { ++ grpc.ServerStream ++} ++ ++func (c *controlImportServer) Send(response *pb.ImportResponse) error { ++ if response.Log == "error" { ++ return errors.New("error happened") ++ } ++ return nil ++} ++ ++func (c *controlImportServer) Context() context.Context { ++ return context.Background() ++} ++ ++func TestImport(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ tmpFile := fs.NewFile(t, t.Name()) ++ defer tmpFile.Remove() ++ err := ioutil.WriteFile(tmpFile.Path(), []byte("This is test file"), constant.DefaultSharedFileMode) ++ assert.NilError(t, err) ++ importID := util.GenerateNonCryptoID()[:constant.DefaultIDLen] ++ ++ testcases := []struct { ++ name string ++ req *pb.ImportRequest ++ wantErr bool ++ errString string ++ }{ ++ { ++ name: "TC1 - normal case", ++ req: &pb.ImportRequest{ ++ ImportID: importID, ++ Source: tmpFile.Path(), ++ Reference: "test:image", ++ }, ++ wantErr: true, ++ errString: "Error processing tar file", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ stream := &controlImportServer{} ++ err := d.Daemon.backend.Import(tc.req, stream) ++ if tc.wantErr == true { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if tc.wantErr == false { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++ ++} +diff --git a/daemon/login_test.go b/daemon/login_test.go +new file mode 100644 +index 0000000..b8ae002 +--- /dev/null ++++ b/daemon/login_test.go +@@ -0,0 +1,103 @@ ++// 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: daisicheng ++// Create: 2022-12-01 ++// Description: This file tests login interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "crypto/sha512" ++ "testing" ++ ++ "gotest.tools/v3/assert" ++ ++ pb "isula.org/isula-build/api/services" ++ "isula.org/isula-build/util" ++) ++ ++func TestLogin(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ encryptKey, err := util.EncryptRSA("testpassword", d.Daemon.backend.daemon.key.PublicKey, sha512.New()) ++ assert.NilError(t, err) ++ testcases := []struct { ++ name string ++ req *pb.LoginRequest ++ wantErr bool ++ errString string ++ }{ ++ { ++ name: "TC1 - normal case with abnormal password", ++ req: &pb.LoginRequest{ ++ Server: "testcase.org", ++ Username: "testuser", ++ Password: "decfabdc", ++ }, ++ wantErr: true, ++ errString: "decryption failed", ++ }, ++ { ++ name: "TC2 - normal case with abnormal registry", ++ req: &pb.LoginRequest{ ++ Server: "testcase.org", ++ Username: "testuser", ++ Password: encryptKey, ++ }, ++ wantErr: true, ++ errString: "no route to host", ++ }, ++ { ++ name: "TC3 - abnormal case with empty server", ++ req: &pb.LoginRequest{ ++ Server: "", ++ Username: "testuser", ++ Password: "testpassword", ++ }, ++ wantErr: true, ++ errString: "empty server address", ++ }, ++ { ++ name: "TC4 - abnormal case with empty password", ++ req: &pb.LoginRequest{ ++ Server: "test.org", ++ Username: "testuser", ++ Password: "", ++ }, ++ wantErr: true, ++ errString: "empty auth info", ++ }, ++ { ++ name: "TC5 - abnormal case with empty password and username", ++ req: &pb.LoginRequest{ ++ Server: "test.org", ++ Username: "", ++ Password: "", ++ }, ++ wantErr: true, ++ errString: "failed to read auth file", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ ctx := context.TODO() ++ _, err := d.Daemon.backend.Login(ctx, tc.req) ++ if tc.wantErr == true { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if tc.wantErr == false { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} +diff --git a/daemon/logout_test.go b/daemon/logout_test.go +new file mode 100644 +index 0000000..58f00b3 +--- /dev/null ++++ b/daemon/logout_test.go +@@ -0,0 +1,75 @@ ++// 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: daisicheng ++// Create: 2022-11-29 ++// Description: This file tests logout interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "testing" ++ ++ "gotest.tools/v3/assert" ++ ++ pb "isula.org/isula-build/api/services" ++) ++ ++func TestLogout(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ testcases := []struct { ++ name string ++ req *pb.LogoutRequest ++ wantErr bool ++ errString string ++ }{ ++ { ++ name: "TC1 - normal case", ++ req: &pb.LogoutRequest{ ++ Server: "test.org", ++ All: true, ++ }, ++ wantErr: false, ++ }, ++ { ++ name: "TC2 - abnormal case with empty server", ++ req: &pb.LogoutRequest{ ++ Server: "", ++ All: false, ++ }, ++ wantErr: true, ++ errString: "empty server address", ++ }, ++ { ++ name: "TC3 - abnormal case with no logined registry", ++ req: &pb.LogoutRequest{ ++ Server: "test.org", ++ All: false, ++ }, ++ wantErr: true, ++ errString: "not logged in", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ ctx := context.TODO() ++ _, err := d.Daemon.backend.Logout(ctx, tc.req) ++ if tc.wantErr == true { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if tc.wantErr == false { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} +diff --git a/daemon/pull_test.go b/daemon/pull_test.go +index 27a4d6e..b296bfd 100644 +--- a/daemon/pull_test.go ++++ b/daemon/pull_test.go +@@ -34,6 +34,7 @@ import ( + _ "isula.org/isula-build/exporter/docker" + "isula.org/isula-build/pkg/logger" + "isula.org/isula-build/store" ++ "isula.org/isula-build/util" + ) + + type daemonTestOptions struct { +@@ -75,10 +76,14 @@ func prepare(t *testing.T) daemonTestOptions { + DataRoot: dOpt.RootDir + "/data", + RunRoot: dOpt.RootDir + "/run", + }) +- localStore, _ := store.GetStore() ++ localStore, err := store.GetStore() ++ assert.NilError(t, err) ++ localKey, err := util.GenerateRSAKey(util.DefaultRSAKeySize) ++ assert.NilError(t, err) + dOpt.Daemon = &Daemon{ + opts: opt, + localStore: &localStore, ++ key: localKey, + } + dOpt.Daemon.NewBackend() + return dOpt +diff --git a/daemon/remove_test.go b/daemon/remove_test.go +new file mode 100644 +index 0000000..fc0f007 +--- /dev/null ++++ b/daemon/remove_test.go +@@ -0,0 +1,101 @@ ++// 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: daisicheng ++// Create: 2022-12-02 ++// Description: This file tests remove interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "testing" ++ ++ "github.com/containers/storage" ++ "github.com/containers/storage/pkg/stringid" ++ "github.com/pkg/errors" ++ "google.golang.org/grpc" ++ "gotest.tools/v3/assert" ++ ++ pb "isula.org/isula-build/api/services" ++) ++ ++type controlRemoveServer struct { ++ grpc.ServerStream ++} ++ ++func (c *controlRemoveServer) Send(response *pb.RemoveResponse) error { ++ if response.LayerMessage == "error" { ++ return errors.New("error happened") ++ } ++ return nil ++} ++ ++func (c *controlRemoveServer) Context() context.Context { ++ return context.Background() ++} ++ ++func TestRemove(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ options := &storage.ImageOptions{} ++ testImg := make([]string, 0) ++ testImg1, err := d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"test:image1"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ d.Daemon.localStore.SetNames(testImg1.ID, append(testImg1.Names, "test:image1-backup")) ++ testImg = append(testImg, testImg1.ID) ++ testImg2, err := d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"test:image2"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ testImg = append(testImg, testImg2.ID) ++ ++ testcases := []struct { ++ name string ++ req *pb.RemoveRequest ++ wantErr bool ++ errString string ++ }{ ++ { ++ name: "TC1 - normal case", ++ req: &pb.RemoveRequest{ ++ ImageID: testImg, ++ All: true, ++ Prune: false, ++ }, ++ wantErr: false, ++ }, ++ { ++ name: "TC2 - abnormal case with no images", ++ req: &pb.RemoveRequest{ ++ ImageID: []string{""}, ++ All: false, ++ Prune: false, ++ }, ++ wantErr: true, ++ errString: "remove one or more images failed", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ stream := &controlRemoveServer{} ++ err := d.Daemon.backend.Remove(tc.req, stream) ++ if tc.wantErr == true { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if tc.wantErr == false { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} +diff --git a/daemon/tag_test.go b/daemon/tag_test.go +new file mode 100644 +index 0000000..07ad9ee +--- /dev/null ++++ b/daemon/tag_test.go +@@ -0,0 +1,73 @@ ++// 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: daisicheng ++// Create: 2022-12-04 ++// Description: This file tests tag interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "testing" ++ ++ "github.com/containers/storage" ++ "github.com/containers/storage/pkg/stringid" ++ "gotest.tools/v3/assert" ++ ++ pb "isula.org/isula-build/api/services" ++) ++ ++func TestTag(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ options := &storage.ImageOptions{} ++ _, err := d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"test:image"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ testcases := []struct { ++ name string ++ req *pb.TagRequest ++ wantErr bool ++ errString string ++ }{ ++ { ++ name: "TC1 - normal case", ++ req: &pb.TagRequest{ ++ Image: "test:image", ++ Tag: "image-backup", ++ }, ++ wantErr: false, ++ }, ++ { ++ name: "TC2 - abnormal case with no existed images", ++ req: &pb.TagRequest{ ++ Image: "", ++ Tag: "image-backup", ++ }, ++ wantErr: true, ++ errString: "repository name must have at least one component", ++ }, ++ } ++ ++ for _, tc := range testcases { ++ t.Run(tc.name, func(t *testing.T) { ++ ctx := context.TODO() ++ _, err := d.Daemon.backend.Tag(ctx, tc.req) ++ if tc.wantErr == true { ++ assert.ErrorContains(t, err, tc.errString) ++ } ++ if tc.wantErr == false { ++ assert.NilError(t, err) ++ } ++ }) ++ } ++} +-- +2.33.0 + diff --git a/patch/0133-cmd-daemon-add-base-test-for-runDaemon-and-before-fu.patch b/patch/0133-cmd-daemon-add-base-test-for-runDaemon-and-before-fu.patch new file mode 100644 index 0000000..1e629d7 --- /dev/null +++ b/patch/0133-cmd-daemon-add-base-test-for-runDaemon-and-before-fu.patch @@ -0,0 +1,73 @@ +From 5edff01f9bdc001980a1a5423ba4b37a1adce756 Mon Sep 17 00:00:00 2001 +From: xingweizheng +Date: Fri, 9 Dec 2022 11:03:12 +0800 +Subject: [PATCH] cmd/daemon: add base test for runDaemon and before function + +--- + cmd/daemon/before_test.go | 8 +++++++- + cmd/daemon/main_test.go | 27 +++++++++++++++++++++++++++ + 2 files changed, 34 insertions(+), 1 deletion(-) + create mode 100644 cmd/daemon/main_test.go + +diff --git a/cmd/daemon/before_test.go b/cmd/daemon/before_test.go +index 19b1bc0..d2a8f41 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 0000000..85e7b94 +--- /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") ++} +-- +2.33.0 + diff --git a/patch/0134-add-dt-for-interface-manifest-health-status-in-daemo.patch b/patch/0134-add-dt-for-interface-manifest-health-status-in-daemo.patch new file mode 100644 index 0000000..3fc12c9 --- /dev/null +++ b/patch/0134-add-dt-for-interface-manifest-health-status-in-daemo.patch @@ -0,0 +1,322 @@ +From 1f5593086dea78c3300b23877db5ebcc7e272127 Mon Sep 17 00:00:00 2001 +From: daisicheng +Date: Fri, 16 Dec 2022 17:42:56 +0800 +Subject: [PATCH] add dt for interface manifest, health, status in daemon and + main in cli + +--- + cmd/cli/main_test.go | 26 +++++++ + daemon/heath_test.go | 28 +++++++ + daemon/manifest_test.go | 169 ++++++++++++++++++++++++++++++++++++++++ + daemon/status_test.go | 55 +++++++++++++ + 4 files changed, 278 insertions(+) + create mode 100644 cmd/cli/main_test.go + create mode 100644 daemon/heath_test.go + create mode 100644 daemon/manifest_test.go + create mode 100644 daemon/status_test.go + +diff --git a/cmd/cli/main_test.go b/cmd/cli/main_test.go +new file mode 100644 +index 0000000..145d396 +--- /dev/null ++++ b/cmd/cli/main_test.go +@@ -0,0 +1,26 @@ ++// 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: daisicheng ++// Create: 2022-12-19 ++// Description: This file is used for isula-build cmd/cli testing ++ ++package main ++ ++import ( ++ "testing" ++ ++ "gotest.tools/v3/assert" ++) ++ ++func TestRuncli(t *testing.T) { ++ cmd := newCliCommand() ++ err := before(cmd) ++ assert.NilError(t, err) ++} +diff --git a/daemon/heath_test.go b/daemon/heath_test.go +new file mode 100644 +index 0000000..c9c6af1 +--- /dev/null ++++ b/daemon/heath_test.go +@@ -0,0 +1,28 @@ ++// 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: sicheng Dai ++// Create: 2020-01-20 ++// Description: This is test file for health ++ ++package daemon ++ ++import ( ++ "context" ++ "testing" ++ ++ gogotypes "github.com/gogo/protobuf/types" ++ "gotest.tools/v3/assert" ++) ++ ++func TestHealthCheck(t *testing.T) { ++ backend := Backend{} ++ _, err := backend.HealthCheck(context.Background(), &gogotypes.Empty{}) ++ assert.NilError(t, err) ++} +diff --git a/daemon/manifest_test.go b/daemon/manifest_test.go +new file mode 100644 +index 0000000..9c54045 +--- /dev/null ++++ b/daemon/manifest_test.go +@@ -0,0 +1,169 @@ ++// 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: daisicheng ++// Create: 2022-12-15 ++// Description: This file tests manifest interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "fmt" ++ "testing" ++ ++ "github.com/containers/storage" ++ "github.com/containers/storage/pkg/stringid" ++ "github.com/pkg/errors" ++ "golang.org/x/sync/errgroup" ++ "google.golang.org/grpc" ++ "gotest.tools/v3/assert" ++ ++ constant "isula.org/isula-build" ++ pb "isula.org/isula-build/api/services" ++ "isula.org/isula-build/pkg/logger" ++) ++ ++type controlManifestPushServer struct { ++ grpc.ServerStream ++} ++ ++func (c *controlManifestPushServer) Context() context.Context { ++ return context.Background() ++} ++ ++func (c *controlManifestPushServer) Send(response *pb.ManifestPushResponse) error { ++ if response.Result == "error" { ++ return errors.New("error happened") ++ } ++ return nil ++} ++ ++func TestManifestCreate(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ ctx := context.TODO() ++ req := &pb.ManifestCreateRequest{ManifestList: "openeuler", ++ Manifests: []string{"openeuler_arrch64"}} ++ _, err := d.Daemon.backend.ManifestCreate(ctx, req) ++ assert.ErrorContains(t, err, "enable experimental to use manifest feature") ++ ++ d.Daemon.opts.Experimental = true ++ req = &pb.ManifestCreateRequest{ManifestList: "euleros", ++ Manifests: []string{"euleros_x86"}} ++ _, err = d.Daemon.backend.ManifestCreate(ctx, req) ++ assert.ErrorContains(t, err, "failed to get the image") ++ ++} ++ ++func TestManifestAnnotate(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ ctx := context.TODO() ++ req := &pb.ManifestAnnotateRequest{ManifestList: "openeuler", ++ Manifest: "openeuler_arrch64"} ++ _, err := d.Daemon.backend.ManifestAnnotate(ctx, req) ++ assert.ErrorContains(t, err, "enable experimental to use manifest feature") ++ ++ d.Daemon.opts.Experimental = true ++ req = &pb.ManifestAnnotateRequest{ManifestList: "euleros", ++ Manifest: "euleros_x86"} ++ _, err = d.Daemon.backend.ManifestAnnotate(ctx, req) ++ assert.ErrorContains(t, err, "not found in local store") ++ ++ options := &storage.ImageOptions{} ++ _, err = d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"image"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ req = &pb.ManifestAnnotateRequest{ManifestList: "image", ++ Manifest: "euleros_x86"} ++ _, err = d.Daemon.backend.ManifestAnnotate(ctx, req) ++ fmt.Println(err) ++ assert.ErrorContains(t, err, "file does not exist") ++} ++ ++func TestManifestInspect(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ ctx := context.TODO() ++ _, err := d.Daemon.backend.ManifestInspect(ctx, &pb.ManifestInspectRequest{ManifestList: "openeuler"}) ++ assert.ErrorContains(t, err, "enable experimental to use manifest feature") ++ ++ d.Daemon.opts.Experimental = true ++ _, err = d.Daemon.backend.ManifestInspect(ctx, &pb.ManifestInspectRequest{ManifestList: "euleros"}) ++ assert.ErrorContains(t, err, "not found in local store") ++ ++ options := &storage.ImageOptions{} ++ _, err = d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"image"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ _, err = d.Daemon.backend.ManifestInspect(ctx, &pb.ManifestInspectRequest{ManifestList: "image"}) ++ assert.ErrorContains(t, err, "file does not exist") ++} ++ ++func TestManifestPush(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ stream := &controlManifestPushServer{} ++ req := &pb.ManifestPushRequest{ManifestList: "openeuler", Dest: "127.0.0.1/no-repository"} ++ err := d.Daemon.backend.ManifestPush(req, stream) ++ assert.ErrorContains(t, err, "enable experimental to use manifest feature") ++ ++ d.Daemon.opts.Experimental = true ++ req = &pb.ManifestPushRequest{ManifestList: "euleros", Dest: "127.0.0.1/no-repository"} ++ err = d.Daemon.backend.ManifestPush(req, stream) ++ assert.ErrorContains(t, err, "not found in local store") ++ ++ options := &storage.ImageOptions{} ++ _, err = d.Daemon.localStore.CreateImage(stringid.GenerateRandomID(), []string{"image"}, "", "", options) ++ if err != nil { ++ t.Fatalf("create image with error: %v", err) ++ } ++ req = &pb.ManifestPushRequest{ManifestList: "image", Dest: "127.0.0.1/no-repository"} ++ err = d.Daemon.backend.ManifestPush(req, stream) ++ assert.ErrorContains(t, err, "file does not exist") ++} ++ ++func TestManifestPushHandler(t *testing.T) { ++ ctx := context.TODO() ++ eg, _ := errgroup.WithContext(ctx) ++ ++ eg.Go(manifestPushHandlerPrint("Push Response")) ++ eg.Go(manifestPushHandlerPrint("")) ++ eg.Go(manifestPushHandlerPrint("error")) ++ ++ eg.Wait() ++} ++ ++func manifestPushHandlerPrint(message string) func() error { ++ return func() error { ++ stream := &controlManifestPushServer{} ++ cliLogger := logger.NewCliLogger(constant.CliLogBufferLen) ++ ++ ctx := context.TODO() ++ eg, _ := errgroup.WithContext(ctx) ++ ++ eg.Go(manifestPushMessageHandler(stream, cliLogger)) ++ eg.Go(func() error { ++ cliLogger.Print(message) ++ cliLogger.CloseContent() ++ return nil ++ }) ++ ++ eg.Wait() ++ ++ return nil ++ } ++} +diff --git a/daemon/status_test.go b/daemon/status_test.go +new file mode 100644 +index 0000000..f235959 +--- /dev/null ++++ b/daemon/status_test.go +@@ -0,0 +1,55 @@ ++// 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: daisicheng ++// Create: 2022-12-09 ++// Description: This file tests status interface. ++ ++package daemon ++ ++import ( ++ "context" ++ "testing" ++ ++ "github.com/pkg/errors" ++ "google.golang.org/grpc" ++ "gotest.tools/v3/assert" ++ ++ constant "isula.org/isula-build" ++ pb "isula.org/isula-build/api/services" ++ "isula.org/isula-build/util" ++) ++ ++type controlStatusServer struct { ++ grpc.ServerStream ++} ++ ++func (c *controlStatusServer) Send(response *pb.StatusResponse) error { ++ if response.Content == "error" { ++ return errors.New("error happened") ++ } ++ return nil ++} ++ ++func (c *controlStatusServer) Context() context.Context { ++ ctx := context.Background() ++ ctx, cancel := context.WithCancel(ctx) ++ cancel() ++ return ctx ++} ++ ++func TestStatus(t *testing.T) { ++ d := prepare(t) ++ defer tmpClean(d) ++ ++ buildID := util.GenerateNonCryptoID()[:constant.DefaultIDLen] ++ stream := &controlStatusServer{} ++ err := d.Daemon.backend.Status(&pb.StatusRequest{BuildID: buildID}, stream) ++ assert.NilError(t, err) ++} +-- +2.33.0 + diff --git a/patch/0135-fix-the-login_test-in-daemon-for-euleros-and-openeul.patch b/patch/0135-fix-the-login_test-in-daemon-for-euleros-and-openeul.patch new file mode 100644 index 0000000..4f4aeb0 --- /dev/null +++ b/patch/0135-fix-the-login_test-in-daemon-for-euleros-and-openeul.patch @@ -0,0 +1,32 @@ +From 72136fa6d5e08936a5ebced9a69044efa84b1fb3 Mon Sep 17 00:00:00 2001 +From: daisicheng +Date: Wed, 21 Dec 2022 17:12:36 +0800 +Subject: [PATCH] fix the login_test in daemon for euleros and openeuler + consistency + +--- + daemon/login_test.go | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/daemon/login_test.go b/daemon/login_test.go +index b8ae002..03cbb62 100644 +--- a/daemon/login_test.go ++++ b/daemon/login_test.go +@@ -49,12 +49,11 @@ func TestLogin(t *testing.T) { + { + name: "TC2 - normal case with abnormal registry", + req: &pb.LoginRequest{ +- Server: "testcase.org", ++ Server: "localhost://8080", + Username: "testuser", + Password: encryptKey, + }, +- wantErr: true, +- errString: "no route to host", ++ wantErr: true, + }, + { + name: "TC3 - abnormal case with empty server", +-- +2.33.0 + diff --git a/series.conf b/series.conf index 3000d90..ef1fb98 100644 --- a/series.conf +++ b/series.conf @@ -37,3 +37,10 @@ patch/0125-fix-the-possible-file-leakage-problem-in-util-cipher.patch patch/0126-improve-security-compile-option-of-isula-build-binar.patch patch/0127-Fix-the-problem-that-the-var-lib-isula-build-storage.patch patch/0128-add-read-lock-in-load-import-and-pull-to-fix-the-pro.patch +patch/0129-add-import_test.go-for-import.go-and-add-TestCleanCo.patch +patch/0130-add-copy-related-unit-tests-in-package-common.patch +patch/0131-improve-some-error-coverage-of-unit-tests-in-import.patch +patch/0132-add-login_test-logout_test-remove_test-and-import_te.patch +patch/0133-cmd-daemon-add-base-test-for-runDaemon-and-before-fu.patch +patch/0134-add-dt-for-interface-manifest-health-status-in-daemo.patch +patch/0135-fix-the-login_test-in-daemon-for-euleros-and-openeul.patch \ No newline at end of file