Skip to content

Commit

Permalink
fix style, tests for policy type "all"
Browse files Browse the repository at this point in the history
  • Loading branch information
acc-jon committed Oct 31, 2020
1 parent 82ea9ac commit 94cd15a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
51 changes: 51 additions & 0 deletions pkg/policy/all_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright (C) 2020 Accurics, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package policy

import (
"reflect"
"sort"
"testing"
)

func TestPolicyTypeAllExpandedCorrectly(t *testing.T) {
t.Run("policy type all gets right policy names", func(t *testing.T) {

want := SupportedPolicyTypes(false)
got := supportedCloudProvider["all"].policyNames()

sort.Strings(want)
sort.Strings(got)

if !reflect.DeepEqual(got, want) {
t.Errorf("got: '%v', want: '%v'", got, want)
}
})

t.Run("policy type all gets right policy paths", func(t *testing.T) {

want := GetDefaultPolicyPaths(SupportedPolicyTypes(false))
got := GetDefaultPolicyPaths([]string{"all"})

sort.Strings(want)
sort.Strings(got)

if !reflect.DeepEqual(got, want) {
t.Errorf("got: '%v', want: '%v'", got, want)
}
})
}
1 change: 0 additions & 1 deletion pkg/policy/cloud-providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func RegisterIndirectCloudProvider(cloudType supportedCloudType, iacTypeDefault
registerActualCloudProvider(cloudType, iacTypeDefault, iacVersionDefault, true, getPolicyNames)
}

// IsCloudProviderSupported returns whether a cloud provider is supported in terrascan
// RegisterCloudProvider registers a cloud provider with terrascan
func RegisterCloudProvider(cloudType supportedCloudType, iacTypeDefault supportedIacType, iacVersionDefault supportedIacVersion) {
registerActualCloudProvider(cloudType, iacTypeDefault, iacVersionDefault, false, func() []string { return []string{basePolicyPath + "/" + string(cloudType)} })
Expand Down
2 changes: 1 addition & 1 deletion pkg/policy/cloud-providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestSupportedPolicyTypes(t *testing.T) {
})
}

func TestSupportediNotIndirectPolicyTypes(t *testing.T) {
func TestSupportedNotIndirectPolicyTypes(t *testing.T) {
t.Run("supported policy types", func(t *testing.T) {
var want []string
for k, v := range supportedCloudProvider {
Expand Down
2 changes: 2 additions & 0 deletions pkg/policy/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ type EngineOutput struct {
*results.ViolationStore `json:"results" yaml:"results" xml:"results"`
}

// EngineOutputFromViolationStore returns an EngineOutput intialized from ViolationStore
func EngineOutputFromViolationStore(store *results.ViolationStore) EngineOutput {
return EngineOutput{
xml.Name{},
store,
}
}

// AsViolationStore returns EngineOutput as a ViolationStore
func (me EngineOutput) AsViolationStore() results.ViolationStore {
if me.ViolationStore == nil {
return results.ViolationStore{}
Expand Down

0 comments on commit 94cd15a

Please sign in to comment.