Skip to content

Commit

Permalink
validation: add a generate smoke-test
Browse files Browse the repository at this point in the history
To avoid cases where our own validation code would consider our defaults
unsafe (which has happened in the past severall times), add a smoke-test
to ensure that this won't happen. Our defaults should not be
intentionally invalid, as that confuses downstreams like umoci which use
runtime-tools for the default as well as for validation of the generated
configuration.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
  • Loading branch information
cyphar committed Oct 2, 2017
1 parent 5d22fd0 commit fc0b7d8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions validation/generate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package validation

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/opencontainers/runtime-tools/generate"
"github.com/opencontainers/runtime-tools/validate"
)

// Smoke test to ensure that _at the very least_ our default configuration
// passes the validation tests. If this test fails, something is _very_ wrong
// and needs to be fixed immediately (as it will break downstreams that depend
// on us for a "sane default" and do compliance testing -- such as umoci).
func TestGenerateValid(t *testing.T) {
bundle, err := ioutil.TempDir("", "TestGenerateValid_bundle")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(bundle)

// Create our toy bundle.
rootfsPath := filepath.Join(bundle, "rootfs")
if err := os.Mkdir(rootfsPath, 0755); err != nil {
t.Fatal(err)
}
configPath := filepath.Join(bundle, "config.json")
g := generate.New()
if err := (&g).SaveToFile(configPath, generate.ExportOptions{Seccomp: false}); err != nil {
t.Fatal(err)
}

// Validate the bundle.
v, err := validate.NewValidatorFromPath(bundle, true, runtime.GOOS)
if err != nil {
t.Errorf("unexpected NewValidatorFromPath error: %+v", err)
}
if err := v.CheckAll(); err != nil {
t.Errorf("unexpected error(s) validating default: %+v", err)
}
}

0 comments on commit fc0b7d8

Please sign in to comment.