Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Datree
Commits
eab59cd1
Commit
eab59cd1
authored
3 years ago
by
shmuelsa
Browse files
Options
Download
Email Patches
Plain Diff
fix: set simple format as default for CI env
parent
62e84471
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bl/evaluation/evaluator.go
+2
-4
bl/evaluation/evaluator.go
bl/evaluation/evaluator_test.go
+5
-15
bl/evaluation/evaluator_test.go
cmd/test/main.go
+13
-10
cmd/test/main.go
cmd/test/main_test.go
+2
-1
cmd/test/main_test.go
with
22 additions
and
30 deletions
+22
-30
bl/evaluation/evaluator.go
+
2
-
4
View file @
eab59cd1
...
...
@@ -17,14 +17,12 @@ type CLIClient interface {
type
Evaluator
struct
{
cliClient
CLIClient
osInfo
*
OSInfo
ciContext
*
ciContext
.
CIContext
}
func
New
(
c
CLIClient
)
*
Evaluator
{
return
&
Evaluator
{
cliClient
:
c
,
osInfo
:
NewOSInfo
(),
ciContext
:
ciContext
.
Extract
(),
}
}
...
...
@@ -43,7 +41,7 @@ type EvaluationResults struct {
}
}
func
(
e
*
Evaluator
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
{
func
(
e
*
Evaluator
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
,
ciContext
*
ciContext
.
CIContext
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
{
createEvaluationResponse
,
err
:=
e
.
cliClient
.
CreateEvaluation
(
&
cliClient
.
CreateEvaluationRequest
{
K8sVersion
:
&
k8sVersion
,
CliId
:
cliId
,
...
...
@@ -53,7 +51,7 @@ func (e *Evaluator) CreateEvaluation(cliId string, cliVersion string, k8sVersion
Os
:
e
.
osInfo
.
OS
,
PlatformVersion
:
e
.
osInfo
.
PlatformVersion
,
KernelVersion
:
e
.
osInfo
.
KernelVersion
,
CIContext
:
e
.
ciContext
,
CIContext
:
ciContext
,
},
})
...
...
This diff is collapsed.
Click to expand it.
bl/evaluation/evaluator_test.go
+
5
-
15
View file @
eab59cd1
...
...
@@ -73,21 +73,21 @@ func TestCreateEvaluation(t *testing.T) {
PlatformVersion
:
"1.2.3"
,
KernelVersion
:
"4.5.6"
,
},
ciContext
:
&
ciContext
.
CIContext
{
IsCI
:
true
,
CIEnv
:
"travis"
,
},
}
cliId
:=
"test_token"
cliVersion
:=
"0.0.7"
k8sVersion
:=
"1.18.1"
policyName
:=
"Default"
ciContext
:=
&
ciContext
.
CIContext
{
IsCI
:
true
,
CIEnv
:
"travis"
,
}
mockedCliClient
.
On
(
"CreateEvaluation"
,
mock
.
Anything
)
.
Return
(
&
cliClient
.
CreateEvaluationResponse
{
EvaluationId
:
1
,
K8sVersion
:
k8sVersion
},
nil
)
expectedCreateEvaluationResponse
:=
&
cliClient
.
CreateEvaluationResponse
{
EvaluationId
:
1
,
K8sVersion
:
k8sVersion
}
createEvaluationResponse
,
_
:=
evaluator
.
CreateEvaluation
(
cliId
,
cliVersion
,
k8sVersion
,
policyName
)
createEvaluationResponse
,
_
:=
evaluator
.
CreateEvaluation
(
cliId
,
cliVersion
,
k8sVersion
,
policyName
,
ciContext
)
mockedCliClient
.
AssertCalled
(
t
,
"CreateEvaluation"
,
mock
.
Anything
)
assert
.
Equal
(
t
,
expectedCreateEvaluationResponse
,
createEvaluationResponse
)
...
...
@@ -109,7 +109,6 @@ func TestEvaluate(t *testing.T) {
evaluator
:=
&
Evaluator
{
cliClient
:
mockedCliClient
,
osInfo
:
tt
.
args
.
osInfo
,
ciContext
:
tt
.
args
.
ciContext
,
}
// TODO: define and check the rest of the values
...
...
@@ -129,7 +128,6 @@ func TestEvaluate(t *testing.T) {
type
evaluateArgs
struct
{
validFilesConfigurations
[]
*
extractor
.
FileConfigurations
osInfo
*
OSInfo
ciContext
*
ciContext
.
CIContext
isInteractiveMode
bool
rulesCount
int
response
*
cliClient
.
CreateEvaluationResponse
...
...
@@ -167,10 +165,6 @@ func request_evaluation_all_valid() *evaluateTestCase {
PlatformVersion
:
"1.2.3"
,
KernelVersion
:
"4.5.6"
,
},
ciContext
:
&
ciContext
.
CIContext
{
IsCI
:
true
,
CIEnv
:
"travis"
,
},
isInteractiveMode
:
true
,
},
mock
:
&
evaluatorMock
{
...
...
@@ -240,10 +234,6 @@ func request_evaluation_all_invalid() *evaluateTestCase {
PlatformVersion
:
"1.2.3"
,
KernelVersion
:
"4.5.6"
,
},
ciContext
:
&
ciContext
.
CIContext
{
IsCI
:
true
,
CIEnv
:
"travis"
,
},
isInteractiveMode
:
true
,
},
mock
:
&
evaluatorMock
{
...
...
This diff is collapsed.
Click to expand it.
cmd/test/main.go
+
13
-
10
View file @
eab59cd1
...
...
@@ -26,7 +26,7 @@ import (
type
Evaluator
interface
{
Evaluate
(
filesConfigurations
[]
*
extractor
.
FileConfigurations
,
evaluationResponse
*
cliClient
.
CreateEvaluationResponse
,
isInteractiveMode
bool
)
(
evaluation
.
ResultType
,
error
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
,
ciContext
*
ciContext
.
CIContext
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
UpdateFailedYamlValidation
(
invalidFiles
[]
*
validation
.
InvalidYamlFile
,
evaluationId
int
,
stopEvaluation
bool
)
error
UpdateFailedK8sValidation
(
invalidFiles
[]
*
validation
.
InvalidK8sFile
,
evaluationId
int
,
stopEvaluation
bool
)
error
}
...
...
@@ -73,12 +73,6 @@ func (flags *TestCommandFlags) Validate() error {
}
func
(
flags
*
TestCommandFlags
)
Transform
()
{
if
flags
.
Output
==
""
&&
ciContext
.
Extract
()
.
IsCI
{
flags
.
Output
=
"simple"
}
}
type
EvaluationPrinter
interface
{
PrintWarnings
(
warnings
[]
printer
.
Warning
)
PrintSummaryTable
(
summary
printer
.
Summary
)
...
...
@@ -170,12 +164,15 @@ func New(ctx *TestCommandContext) *cobra.Command {
testCommandFlags
:=
TestCommandFlags
{
Output
:
outputFlag
,
K8sVersion
:
k8sVersion
,
IgnoreMissingSchemas
:
ignoreMissingSchemas
,
PolicyName
:
policy
,
SchemaLocations
:
schemaLocations
,
OnlyK8sFiles
:
onlyK8sFiles
}
err
=
testCommandFlags
.
Validate
()
testCommandFlags
.
Transform
()
if
err
!=
nil
{
return
err
}
if
testCommandFlags
.
Output
==
""
&&
ciContext
.
Extract
()
.
IsCI
{
testCommandFlags
.
Output
=
"simple"
}
err
=
test
(
ctx
,
args
,
testCommandFlags
)
if
err
!=
nil
{
return
err
...
...
@@ -184,7 +181,11 @@ func New(ctx *TestCommandContext) *cobra.Command {
},
}
testCommand
.
Flags
()
.
StringP
(
"output"
,
"o"
,
""
,
"Define output format"
)
if
ciContext
.
Extract
()
.
IsCI
{
testCommand
.
Flags
()
.
StringP
(
"output"
,
"o"
,
"simple"
,
"Define output format"
)
}
else
{
testCommand
.
Flags
()
.
StringP
(
"output"
,
"o"
,
""
,
"Define output format"
)
}
testCommand
.
Flags
()
.
StringP
(
"schema-version"
,
"s"
,
""
,
"Set kubernetes version to validate against. Defaults to 1.18.0"
)
testCommand
.
Flags
()
.
StringP
(
"policy"
,
"p"
,
""
,
"Policy name to run against"
)
testCommand
.
Flags
()
.
Bool
(
"only-k8s-files"
,
false
,
"Evaluate only valid yaml files with the properties 'apiVersion' and 'kind'. Ignore everything else"
)
...
...
@@ -324,7 +325,9 @@ func evaluate(ctx *TestCommandContext, filesPaths []string, flags TestCommandFla
validationManager
:=
&
ValidationManager
{}
filesPathsLen
:=
len
(
filesPaths
)
createEvaluationResponse
,
err
:=
ctx
.
Evaluator
.
CreateEvaluation
(
cliId
,
ctx
.
CliVersion
,
flags
.
K8sVersion
,
flags
.
PolicyName
)
ciContext
:=
ciContext
.
Extract
()
createEvaluationResponse
,
err
:=
ctx
.
Evaluator
.
CreateEvaluation
(
cliId
,
ctx
.
CliVersion
,
flags
.
K8sVersion
,
flags
.
PolicyName
,
ciContext
)
if
err
!=
nil
{
return
validationManager
,
nil
,
evaluation
.
ResultType
{},
err
}
...
...
This diff is collapsed.
Click to expand it.
cmd/test/main_test.go
+
2
-
1
View file @
eab59cd1
...
...
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/datreeio/datree/bl/validation"
"github.com/datreeio/datree/pkg/ciContext"
"github.com/datreeio/datree/pkg/cliClient"
"github.com/datreeio/datree/pkg/extractor"
"github.com/datreeio/datree/pkg/printer"
...
...
@@ -24,7 +25,7 @@ func (m *mockEvaluator) Evaluate(filesConfigurationsChan []*extractor.FileConfig
return
args
.
Get
(
0
)
.
(
evaluation
.
ResultType
),
args
.
Error
(
1
)
}
func
(
m
*
mockEvaluator
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
{
func
(
m
*
mockEvaluator
)
CreateEvaluation
(
cliId
string
,
cliVersion
string
,
k8sVersion
string
,
policyName
string
,
ciContext
*
ciContext
.
CIContext
)
(
*
cliClient
.
CreateEvaluationResponse
,
error
)
{
args
:=
m
.
Called
(
cliId
,
cliVersion
,
k8sVersion
,
policyName
)
return
args
.
Get
(
0
)
.
(
*
cliClient
.
CreateEvaluationResponse
),
args
.
Error
(
1
)
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help