github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/tests/rkt_ace_validator_test.go (about) 1 // Copyright 2015 The rkt Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build !fly,!kvm 16 17 package main 18 19 import ( 20 "fmt" 21 "strings" 22 "testing" 23 24 "github.com/rkt/rkt/tests/testutils" 25 ) 26 27 // Spin up the appc ACE validator pod and return the result. 28 29 // You'll find the actual application at vendor/github.com/appc/spec/ace/validator.go, 30 // the two ACIs are built from that 31 32 func TestAceValidator(t *testing.T) { 33 newStringSet := func(strs ...string) map[string]struct{} { 34 m := make(map[string]struct{}, len(strs)) 35 for _, s := range strs { 36 m[s] = struct{}{} 37 } 38 return m 39 } 40 expected := []map[string]struct{}{ 41 newStringSet("prestart"), 42 newStringSet("main", "sidekick"), 43 // newStringSet("poststop"), // Disabled by caseyc for #2870 44 } 45 pattern := `ace-validator-(?:main|sidekick)\[\d+\]: ([[:alpha:]]+) OK` 46 47 ctx := testutils.NewRktRunCtx() 48 defer ctx.Cleanup() 49 50 if err := ctx.LaunchMDS(); err != nil { 51 t.Fatalf("Cannot launch metadata service: %v", err) 52 } 53 54 aceMain := testutils.GetValueFromEnvOrPanic("RKT_ACE_MAIN_IMAGE") 55 aceSidekick := testutils.GetValueFromEnvOrPanic("RKT_ACE_SIDEKICK_IMAGE") 56 57 rktArgs := fmt.Sprintf("--debug --insecure-options=image run --mds-register --volume database,kind=empty %s %s", 58 aceMain, aceSidekick) 59 rktCmd := fmt.Sprintf("%s %s", ctx.Cmd(), rktArgs) 60 61 child := spawnOrFail(t, rktCmd) 62 defer waitOrFail(t, child, 0) 63 64 out := "" 65 for _, set := range expected { 66 for len(set) > 0 { 67 results, o, err := expectRegexWithOutput(child, pattern) 68 out += o 69 if err != nil { 70 var keys []string 71 for k := range set { 72 keys = append(keys, fmt.Sprintf("%q", k)) 73 } 74 ex := strings.Join(keys, " or ") 75 t.Fatalf("Expected %s, but not found: %v\nOutput: %v", ex, err, out) 76 } 77 if len(results) != 2 { 78 t.Fatalf("Unexpected regex results, expected a whole match and one submatch, got %#v", results) 79 } 80 aceStage := results[1] 81 if _, ok := set[aceStage]; ok { 82 t.Logf("Got expected ACE stage %q", aceStage) 83 delete(set, aceStage) 84 } else { 85 t.Logf("Ignoring unknown ACE stage %q", aceStage) 86 } 87 } 88 } 89 }