Unit tests: remove leftover files (#2134)

This commit is contained in:
mmetc 2023-03-22 13:51:37 +01:00 committed by GitHub
parent 80de87ac34
commit 3884c5f47d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 19 deletions

View file

@ -25,7 +25,8 @@ import (
var responseByPath map[string]string
func TestItemStatus(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
err := UpdateHubIdx(cfg.Hub)
//DownloadHubIdx()
@ -54,7 +55,7 @@ func TestItemStatus(t *testing.T) {
item.Tainted = false
txt, _, _, _ := ItemStatus(*item)
if txt != "enabled,update-available" {
log.Fatalf("got '%s'", txt)
t.Fatalf("got '%s'", txt)
}
item.Installed = false
@ -63,7 +64,7 @@ func TestItemStatus(t *testing.T) {
item.Tainted = false
txt, _, _, _ = ItemStatus(*item)
if txt != "disabled,local" {
log.Fatalf("got '%s'", txt)
t.Fatalf("got '%s'", txt)
}
break
@ -72,7 +73,8 @@ func TestItemStatus(t *testing.T) {
}
func TestGetters(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
err := UpdateHubIdx(cfg.Hub)
//DownloadHubIdx()
@ -132,7 +134,8 @@ func TestGetters(t *testing.T) {
}
func TestIndexDownload(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
err := UpdateHubIdx(cfg.Hub)
//DownloadHubIdx()
@ -152,24 +155,17 @@ func getTestCfg() (cfg *csconfig.Config) {
return
}
func test_prepenv() *csconfig.Config {
func envSetup() *csconfig.Config {
resetResponseByPath()
log.SetLevel(log.DebugLevel)
cfg := getTestCfg()
//Mock the http client
http.DefaultClient.Transport = newMockTransport()
if err := os.RemoveAll(cfg.Hub.ConfigDir); err != nil {
log.Fatalf("failed to remove %s : %s", cfg.Hub.ConfigDir, err)
}
if err := os.MkdirAll(cfg.Hub.ConfigDir, 0700); err != nil {
log.Fatalf("mkdir : %s", err)
}
if err := os.RemoveAll(cfg.Hub.HubDir); err != nil {
log.Fatalf("failed to remove %s : %s", cfg.Hub.HubDir, err)
}
if err := os.MkdirAll(cfg.Hub.HubDir, 0700); err != nil {
log.Fatalf("failed to mkdir %s : %s", cfg.Hub.HubDir, err)
}
@ -185,9 +181,20 @@ func test_prepenv() *csconfig.Config {
// log.Fatalf("failed to mkdir %s : %s", cfg.Hub.InstallDir, err)
// }
return cfg
}
func envTearDown(cfg *csconfig.Config) {
if err := os.RemoveAll(cfg.Hub.ConfigDir); err != nil {
log.Fatalf("failed to remove %s : %s", cfg.Hub.ConfigDir, err)
}
if err := os.RemoveAll(cfg.Hub.HubDir); err != nil {
log.Fatalf("failed to remove %s : %s", cfg.Hub.HubDir, err)
}
}
func testInstallItem(cfg *csconfig.Hub, t *testing.T, item Item) {
//Install the parser
@ -314,7 +321,8 @@ func TestInstallParser(t *testing.T) {
- check its status
- remove it
*/
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
getHubIdxOrFail(t)
//map iteration is random by itself
@ -345,7 +353,8 @@ func TestInstallCollection(t *testing.T) {
- check its status
- remove it
*/
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
getHubIdxOrFail(t)
//map iteration is random by itself

View file

@ -9,7 +9,8 @@ import (
//Download index, install collection. Add scenario to collection (hub-side), update index, upgrade collection
// We expect the new scenario to be installed
func TestUpgradeConfigNewScenarioInCollection(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
// fresh install of collection
getHubIdxOrFail(t)
@ -54,7 +55,8 @@ func TestUpgradeConfigNewScenarioInCollection(t *testing.T) {
// Install a collection, disable a scenario.
// Upgrade should install should not enable/download the disabled scenario.
func TestUpgradeConfigInDisabledSceanarioShouldNotBeInstalled(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
// fresh install of collection
getHubIdxOrFail(t)
@ -101,7 +103,8 @@ func getHubIdxOrFail(t *testing.T) {
// Upgrade should not enable/download the disabled scenario.
// Upgrade should install and enable the newly added scenario.
func TestUpgradeConfigNewScenarioIsInstalledWhenReferencedScenarioIsDisabled(t *testing.T) {
cfg := test_prepenv()
cfg := envSetup()
defer envTearDown(cfg)
// fresh install of collection
getHubIdxOrFail(t)