Skip to content

Commit

Permalink
fix code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
patilpankaj212 committed Dec 29, 2020
1 parent 0212180 commit 78b6822
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pkg/config/config-reader.go
Expand Up @@ -52,13 +52,13 @@ func NewTerrascanConfigReader(fileName string) (*TerrascanConfigReader, error) {
// return error if file doesn't exist
_, err := os.Stat(fileName)
if err != nil {
zap.S().Debugf("config file: %s, doesn't exist", fileName)
zap.S().Error("config file: %s, doesn't exist", fileName)
return configReader, ErrNotPresent
}

data, err := ioutil.ReadFile(fileName)
if err != nil {
zap.S().Debugf("error loading config file", zap.Error(err))
zap.S().Error("error loading config file", zap.Error(err))
return configReader, errTomlLoadConfig
}

Expand Down
12 changes: 2 additions & 10 deletions pkg/config/config-reader_test.go
Expand Up @@ -119,16 +119,8 @@ func TestNewTerrascanConfigReader(t *testing.T) {
t.Errorf("NewTerrascanConfigReader() = got %v, want %v", got, tt.want)
}
if tt.assertGetters {
if !reflect.DeepEqual(got.GetPolicyConfig(), tt.Policy) {
t.Errorf("NewTerrascanConfigReader() = got config: %v, want config: %v", got.GetPolicyConfig(), tt.Policy)
}

if !reflect.DeepEqual(got.GetNotifications(), tt.notifications) {
t.Errorf("NewTerrascanConfigReader() = got notifications: %v, want notifications: %v", got.GetNotifications(), tt.notifications)
}

if !reflect.DeepEqual(got.GetRules(), tt.Rules) {
t.Errorf("NewTerrascanConfigReader() = got rules: %v, want rules: %v", got.GetRules(), tt.Rules)
if !reflect.DeepEqual(got.GetPolicyConfig(), tt.Policy) || !reflect.DeepEqual(got.GetNotifications(), tt.notifications) || !reflect.DeepEqual(got.GetRules(), tt.Rules) {
t.Errorf("NewTerrascanConfigReader() = got config: %v, notifications: %v, rules: %v want config: %v, notifications: %v, rules: %v", got.GetPolicyConfig(), got.GetNotifications(), got.GetRules(), tt.Policy, tt.notifications, tt.Rules)
}
}
})
Expand Down
16 changes: 2 additions & 14 deletions pkg/config/global_test.go
Expand Up @@ -74,20 +74,8 @@ func TestLoadGlobalConfig(t *testing.T) {
t.Errorf("LoadGlobalConfig() error = %v, wantErr %v", err, tt.wantErr)
}

if GetPolicyBasePath() != tt.policyBasePath {
t.Errorf("LoadGlobalConfig() error = got BasePath: %v, want BasePath: %v", tt.policyBasePath, Global.Policy.BasePath)
}

if GetPolicyRepoPath() != tt.policyRepoPath {
t.Errorf("LoadGlobalConfig() error = got RepoPath: %v, want RepoPath: %v", tt.policyRepoPath, Global.Policy.RepoPath)
}

if GetPolicyRepoURL() != tt.repoURL {
t.Errorf("LoadGlobalConfig() error = got RepoURL: %v, want RepoURL: %v", tt.repoURL, Global.Policy.RepoURL)
}

if GetPolicyBranch() != tt.branchName {
t.Errorf("LoadGlobalConfig() error = got BranchName: %v, want BranchName: %v", tt.branchName, Global.Policy.Branch)
if GetPolicyBasePath() != tt.policyBasePath || GetPolicyRepoPath() != tt.policyRepoPath || GetPolicyRepoURL() != tt.repoURL || GetPolicyBranch() != tt.branchName {
t.Errorf("LoadGlobalConfig() error = got BasePath: %v, RepoPath: %v, RepoURL: %v, BranchName: %v, want BasePath: %v, RepoPath: %v, RepoURL: %v, BranchName: %v", GetPolicyBasePath(), GetPolicyRepoPath(), GetPolicyRepoURL(), GetPolicyBranch(), tt.policyBasePath, tt.policyRepoPath, tt.repoURL, tt.branchName)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/policy/opa/engine_test.go
Expand Up @@ -29,7 +29,7 @@ func TestFilterRules(t *testing.T) {
name: "scan rules test",
args: args{
policyPath: testPolicyPath,
scanRules: []string{"Rule.0", "Rule.1", "Rule.2", "Rule.3", "Rule.11"},
scanRules: []string{"Rule.0", "Rule.1", "Rule.2", "Rule.3", "Rule.10"},
},
regoDataMap: getTestRegoDataMap(10),
assert: true,
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestFilterRules(t *testing.T) {
name: "both scan and skip rules supplied",
args: args{
policyPath: testPolicyPath,
scanRules: []string{"Rule.10", "Rule.11", "Rule.12", "Rule.15", "Rule.31", "Rule.32", "Rule.40", "Rule.41", "Rule.42"},
scanRules: []string{"Rule.6", "Rule.7", "Rule.8", "Rule.15", "Rule.31", "Rule.32", "Rule.40", "Rule.41", "Rule.42"},
skipRules: []string{"Rule.31", "Rule.32", "Rule.38"},
},
regoDataMap: getTestRegoDataMap(50),
Expand Down
3 changes: 3 additions & 0 deletions pkg/runtime/executor_test.go
Expand Up @@ -60,6 +60,9 @@ func (m MockPolicyEngine) Init(input string, scanRules, skipRules []string) erro
}

func (m MockPolicyEngine) FilterRules(input string, scanRules, skipRules []string) {
/*
This method does nothing. Required to fullfil the Engine interface contract
*/
}

func (m MockPolicyEngine) Configure() error {
Expand Down

0 comments on commit 78b6822

Please sign in to comment.