Skip to content

Commit

Permalink
Unit tests: remove leftover files
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 21, 2023
1 parent 91eb39c commit 323a328
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
35 changes: 22 additions & 13 deletions pkg/cwhub/cwhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/cwhub/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 323a328

Please sign in to comment.