* bump gopkg.in/yaml.v3 * test: cannot remove local items with cscli * test dangling links * test: cannot install local item with cscli * pkg/cwhub: reorg (move) functions in files * allow hub upgrade with local items * data download: honor Last-Modified header * fatal -> warning when attempting to remove a local item (allows remove --all) * cscli...inspect -o yaml|human: rename remote_path -> path * Correct count of removed items Still no separate counter for the --purge option, but should be clear enough
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package cwhub
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestItemStatus(t *testing.T) {
|
|
hub := envSetup(t)
|
|
|
|
// get existing map
|
|
x := hub.GetItemMap(COLLECTIONS)
|
|
require.NotEmpty(t, x)
|
|
|
|
// Get item: good and bad
|
|
for k := range x {
|
|
item := hub.GetItem(COLLECTIONS, k)
|
|
require.NotNil(t, item)
|
|
|
|
item.State.Installed = true
|
|
item.State.UpToDate = false
|
|
item.State.Tainted = false
|
|
item.State.Downloaded = true
|
|
|
|
txt, _ := item.InstallStatus()
|
|
require.Equal(t, "enabled,update-available", txt)
|
|
|
|
item.State.Installed = true
|
|
item.State.UpToDate = false
|
|
item.State.Tainted = false
|
|
item.State.Downloaded = false
|
|
|
|
txt, _ = item.InstallStatus()
|
|
require.Equal(t, "enabled,local", txt)
|
|
}
|
|
|
|
stats := hub.ItemStats()
|
|
require.Equal(t, []string{
|
|
"Loaded: 2 parsers, 1 scenarios, 3 collections",
|
|
"Unmanaged items: 3 local, 0 tainted",
|
|
}, stats)
|
|
}
|
|
|
|
func TestGetters(t *testing.T) {
|
|
hub := envSetup(t)
|
|
|
|
// get non existing map
|
|
empty := hub.GetItemMap("ratata")
|
|
require.Nil(t, empty)
|
|
|
|
// get existing map
|
|
x := hub.GetItemMap(COLLECTIONS)
|
|
require.NotEmpty(t, x)
|
|
|
|
// Get item: good and bad
|
|
for k := range x {
|
|
empty := hub.GetItem(COLLECTIONS, k+"nope")
|
|
require.Nil(t, empty)
|
|
|
|
item := hub.GetItem(COLLECTIONS, k)
|
|
require.NotNil(t, item)
|
|
|
|
// Add item and get it
|
|
item.Name += "nope"
|
|
hub.Items[item.Type][item.Name] = item
|
|
|
|
newitem := hub.GetItem(COLLECTIONS, item.Name)
|
|
require.NotNil(t, newitem)
|
|
}
|
|
}
|