-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathroot_pdsc_rm_test.go
More file actions
143 lines (113 loc) · 4.39 KB
/
root_pdsc_rm_test.go
File metadata and controls
143 lines (113 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright Contributors to the cpackget project. */
package installer_test
import (
"path/filepath"
"testing"
errs "github.com/open-cmsis-pack/cpackget/cmd/errors"
"github.com/open-cmsis-pack/cpackget/cmd/installer"
"github.com/stretchr/testify/assert"
)
func TestRemovePdsc(t *testing.T) {
assert := assert.New(t)
t.Run("test remove pdsc with bad name", func(t *testing.T) {
localTestingDir := "test-remove-pdsc-with-bad-name"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
for i := 0; i < len(malformedPackNames); i++ {
err := installer.RemovePdsc(malformedPackNames[i])
assert.NotNil(err)
assert.Equal(errs.ErrBadPackName, err)
}
})
t.Run("test remove a pdsc", func(t *testing.T) {
localTestingDir := "test-remove-pdsc"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
// Add it first
err := installer.AddPdsc(pdscPack123)
assert.Nil(err)
tags := installer.Installation.LocalPidx.ListPdscTags()
assert.Equal(1, len(tags))
// Remove it
err = installer.RemovePdsc(shortenPackPath(pdscPack123, true))
assert.Nil(err)
// Make sure there is no tags in local_repository.pidx
tags = installer.Installation.LocalPidx.ListPdscTags()
assert.Equal(0, len(tags))
})
t.Run("test remove multiple pdscs using basename PDSC file name", func(t *testing.T) {
localTestingDir := "test-remove-multiple-pdscs-using-basename-pdsc-file-name"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
// Add it first
err := installer.AddPdsc(pdscPack123)
assert.Nil(err)
// Add a new version of the same pack
err = installer.AddPdsc(pdscPack124)
assert.Nil(err)
tags := installer.Installation.LocalPidx.ListPdscTags()
assert.Equal(2, len(tags))
// Remove it
err = installer.RemovePdsc(shortenPackPath(pdscPack123, true))
assert.Nil(err)
// Make sure there is no tags in local_repository.pidx
// tags = installer.Installation.LocalPidx.ListPdscTags()
// assert.Equal(0, len(tags))
})
t.Run("test remove a pdsc using full path", func(t *testing.T) {
localTestingDir := "test-remove-pdsc-using-full-path"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
// Add it first
err := installer.AddPdsc(pdscPack123)
assert.Nil(err)
tags := installer.Installation.LocalPidx.ListPdscTags()
assert.Equal(1, len(tags))
// Remove it
absPath, _ := filepath.Abs(pdscPack123)
err = installer.RemovePdsc(absPath)
assert.Nil(err)
// Make sure there is no tags in local_repository.pidx
tags = installer.Installation.LocalPidx.ListPdscTags()
assert.Equal(0, len(tags))
})
// TODO: this test does not work because multiple versions of the same pack are not supported in index.pidx
t.Run("test remove one pdsc using full path and leave others untouched", func(t *testing.T) {
localTestingDir := "test-remove-one-pdsc-using-full-path-and-leave-others-untouched"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
// Add it first
err := installer.AddPdsc(pdscPack123)
assert.Nil(err)
// Add a new version of the same pack
err = installer.AddPdsc(pdscPack124)
assert.Nil(err)
// Remove only the first one
// absPath, _ := filepath.Abs(pdscPack123)
// err = installer.RemovePdsc(absPath)
// assert.Nil(err)
// Make sure 1.2.4 is still present in local_repository.pidx
// tags := installer.Installation.LocalPidx.ListPdscTags()
// assert.Greater(len(tags), 0)
})
t.Run("test remove a pdsc that does not exist", func(t *testing.T) {
localTestingDir := "test-remove-pdsc-that-does-not-exist"
assert.Nil(installer.SetPackRoot(localTestingDir, CreatePackRoot))
installer.UnlockPackRoot()
assert.Nil(installer.ReadIndexFiles())
defer removePackRoot(localTestingDir)
err := installer.RemovePdsc(shortenPackPath(pdscPack123, true))
assert.Equal(errs.ErrPdscEntryNotFound, err)
})
}