Skip to content

Commit

Permalink
chore(internal): added engine version related tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: Lorenzo Susini <[email protected]>
  • Loading branch information
FedeDP and loresuso committed Jan 4, 2024
1 parent 5cb7f75 commit e4fa731
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions internal/follower/follower_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 The Falco Authors

Check failure on line 2 in internal/follower/follower_test.go

View workflow job for this annotation

GitHub Actions / Lint golang files

Actual: 2024 The Falco Authors
//
// 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 follower

import (
"os"
"testing"

"github.com/pterm/pterm"
"github.com/stretchr/testify/assert"

"github.com/falcosecurity/falcoctl/pkg/oci"
"github.com/falcosecurity/falcoctl/pkg/output"
)

func TestCheckRequirements(t *testing.T) {
printer := output.NewPrinter(pterm.LogLevelDebug, pterm.LogFormatterJSON, os.Stdout)
config := Config{
FalcoVersions: map[string]string{"engine_version_semver": "0.26.0", "engine_version": "26"},
}
f, err := New("ghcr.io/falcosecurity/rules/my_rule:0.1.0", printer, &config)
assert.NoError(t, err)

type testArtifact struct {
conf *oci.ArtifactConfig
expectErr bool
testName string
}
var testArtifactConfigs = []testArtifact{
{
conf: &oci.ArtifactConfig{
Name: "my_rule",
Version: "0.1.0",
Requirements: []oci.ArtifactRequirement{{Name: "engine_version_semver", Version: "0.26.0"}},
},
expectErr: false,
testName: "New rules with new semver engine version",
},
{
conf: &oci.ArtifactConfig{
Name: "my_rule",
Version: "0.1.0",
Requirements: []oci.ArtifactRequirement{{Name: "engine_version_semver", Version: "26"}},
},
expectErr: true,
testName: "New rules with old int engine version",
},
{
conf: &oci.ArtifactConfig{
Name: "my_rule",
Version: "0.1.0",
Requirements: []oci.ArtifactRequirement{{Name: "engine_version", Version: "26"}},
},
expectErr: false,
testName: "Old rules with old int engine version",
},
{
conf: &oci.ArtifactConfig{
Name: "my_rule",
Version: "0.1.0",
Requirements: []oci.ArtifactRequirement{{Name: "engine_version", Version: "0.26.0"}},
},
expectErr: true,
testName: "Old rules with new semver engine version",
},
}

for _, artConf := range testArtifactConfigs {
t.Run(artConf.testName, func(t *testing.T) {
err = f.checkRequirements(artConf.conf)
if artConf.expectErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
})
}
}

0 comments on commit e4fa731

Please sign in to comment.