github.com/rkt/rkt@v1.30.1-0.20200224141603-171c416fac02/tests/rkt_status_test.go (about) 1 // Copyright 2017 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 package main 16 17 import ( 18 "fmt" 19 "io/ioutil" 20 "os" 21 "testing" 22 23 "github.com/rkt/rkt/tests/testutils" 24 ) 25 26 func TestUuidFile(t *testing.T) { 27 const imgName = "rkt-uuid-file-status-test" 28 imagePath := patchTestACI(fmt.Sprintf("%s.aci", imgName), fmt.Sprintf("--name=%s", imgName)) 29 defer os.Remove(imagePath) 30 31 ctx := testutils.NewRktRunCtx() 32 defer ctx.Cleanup() 33 34 cmd := fmt.Sprintf("%s --insecure-options=image prepare %s", ctx.Cmd(), imagePath) 35 podUuid := runRktAndGetUUID(t, cmd) 36 tmpDir := mustTempDir(imgName) 37 defer os.RemoveAll(tmpDir) 38 uuidFile, err := ioutil.TempFile(tmpDir, "uuid-file") 39 if err != nil { 40 panic(fmt.Sprintf("Cannot create uuid-file: %v", err)) 41 } 42 uuidFilePath := uuidFile.Name() 43 if err := ioutil.WriteFile(uuidFilePath, []byte(podUuid), 0600); err != nil { 44 panic(fmt.Sprintf("Cannot write pod uuid to uuid-file %v", err)) 45 } 46 statusCmd := fmt.Sprintf("%s status --uuid-file=%s", ctx.Cmd(), uuidFilePath) 47 runRktAndCheckRegexOutput(t, statusCmd, "state=prepared") 48 }