This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-349) Add updated install unit tests
In this commit, update unit tests have been added for the newly refactored `pkg/install/install.go`. The `install_config.go` mock file for mocking the private config processor has been updated, implementing the new config processor interface.
- Loading branch information
1 parent
c69e0cc
commit 09a9ba0
Showing
2 changed files
with
219 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
package mock | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"github.com/puppetlabs/pdkgo/pkg/config_processor" | ||
) | ||
|
||
type InstallConfig struct { | ||
ExpectedSourceDir string | ||
ExpectedTargetDir string | ||
ExpectedForce bool | ||
NamespacedPathResponse string | ||
|
||
ErrResponse error | ||
ExpectedConfigFile string | ||
Metadata config_processor.ConfigMetadata | ||
ErrResponse error | ||
} | ||
|
||
func (ic *InstallConfig) ProcessConfig(sourceDir, targetDir string, force bool) (string, error) { | ||
func (ic *InstallConfig) GetConfigMetadata(configFile string) (metadata config_processor.ConfigMetadata, err error) { | ||
if ic.ErrResponse != nil { | ||
return "", ic.ErrResponse | ||
return metadata, ic.ErrResponse | ||
} | ||
|
||
if sourceDir != ic.ExpectedSourceDir { | ||
return "", fmt.Errorf("sourceDir (%v) did not match expected value (%v)", sourceDir, ic.ExpectedSourceDir) | ||
if ic.ExpectedConfigFile != configFile { | ||
return ic.Metadata, fmt.Errorf("configFile (%v) did not match expected value (%v)", configFile, ic.ExpectedConfigFile) | ||
} | ||
|
||
if targetDir != ic.ExpectedTargetDir { | ||
return "", fmt.Errorf("targetDir (%v) did not match expected value (%v)", targetDir, ic.ExpectedTargetDir) | ||
return ic.Metadata, nil | ||
} | ||
|
||
func (ic *InstallConfig) CheckConfig(configFile string) error { | ||
if ic.ErrResponse != nil { | ||
return ic.ErrResponse | ||
} | ||
|
||
if force != ic.ExpectedForce { | ||
return "", fmt.Errorf("force (%v) did not match expected value (%v)", force, ic.ExpectedForce) | ||
if ic.ExpectedConfigFile != configFile { | ||
return fmt.Errorf("configFile (%v) did not match expected value (%v)", configFile, ic.ExpectedConfigFile) | ||
} | ||
return ic.NamespacedPathResponse, nil | ||
} | ||
|
||
func (ic *InstallConfig) CheckConfig(configFile string) error { | ||
return nil | ||
return ic.ErrResponse | ||
} |