Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error message if a pack cannot be found in current index.pidx #209

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/commands/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import (
errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
)

var (
packFilePath = filepath.Join(testingDir, "1.2.3", "TheVendor.PublicLocalPack.1.2.3.pack")
fileWithPacksListed = "file_with_listed_packs.txt"
fileWithNoPacksListed = "file_with_no_listed_packs.txt"
pdscFilePath = filepath.Join(testingDir, "1.2.3", "TheVendor.PackName.pdsc")
)

var addCmdTests = []TestCase{
{
name: "test help command",
Expand Down
41 changes: 0 additions & 41 deletions cmd/commands/index.go

This file was deleted.

160 changes: 0 additions & 160 deletions cmd/commands/index_test.go

This file was deleted.

13 changes: 0 additions & 13 deletions cmd/commands/index_windows_test.go

This file was deleted.

78 changes: 78 additions & 0 deletions cmd/commands/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the cpackget project. */

package commands_test

import (
"errors"
"os"
"path/filepath"
"testing"

errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
)

// Tests for init command are placed here because there was something wrong
// while putting them into a file init_test.go

var (
pidxFilePath = filepath.Join(testingDir, "SamplePublicIndex.pidx")
notFoundPidxFilePath = filepath.Join("path", "to", "index.pidx")
)

var initCmdTests = []TestCase{
{
name: "test no parameter given",
args: []string{"init"},
expectedErr: errors.New("accepts 1 arg(s), received 0"),
},
{
name: "test help command",
args: []string{"help", "init"},
expectedErr: nil,
},
{
name: "test create using an index.pidx",
args: []string{"init"},
setUpFunc: func(t *TestCase) {
server := NewServer()
t.args = append(t.args, server.URL()+"index.pidx")
server.AddRoute("index.pidx", []byte(`<?xml version="1.0" encoding="UTF-8" ?>
<index schemaVersion="1.1.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="https://www.w3.org/2001/XMLSchema-instance">
<vendor>TheVendor</vendor>
<url>https://the.vendor/</url>
<timestamp>2021-10-17T12:21:59.1747971+00:00</timestamp>
<pindex>
<pdsc url="https://the.vendor/" vendor="TheVendor" name="PackName" version="1.2.3" />
</pindex>
</index>`))
},
},
{
name: "test create using local index.pidx",
args: []string{"init", pidxFilePath},
createPackRoot: true,
},
{
name: "test create using local index.pidx that do not exist",
args: []string{"init", notFoundPidxFilePath},
createPackRoot: true,
expectedErr: errs.ErrFileNotFound,
},
{
name: "test create using directory as path",
args: []string{"init", "foo/"},
createPackRoot: true,
expectedErr: errs.ErrInvalidPublicIndexReference,
setUpFunc: func(t *TestCase) {
t.assert.Nil(os.Mkdir("foo/", 0777))
},
tearDownFunc: func() {
os.Remove("foo/")
},
},
}

func TestInitCmd(t *testing.T) {
runTests(t, initCmdTests)
}
Loading