github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/test/suites/image/image.go (about) 1 // Copyright © 2021 Alibaba Group Holding Ltd. 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 image 16 17 import ( 18 "fmt" 19 20 "github.com/sealerio/sealer/test/testhelper" 21 "github.com/sealerio/sealer/test/testhelper/settings" 22 23 "github.com/onsi/gomega" 24 "github.com/onsi/gomega/gbytes" 25 "github.com/onsi/gomega/gexec" 26 ) 27 28 func DoImageOps(action, imageName string) { 29 cmd := "" 30 switch action { 31 case "pull": 32 cmd = fmt.Sprintf("%s pull %s -d", settings.DefaultSealerBin, imageName) 33 case "push": 34 cmd = fmt.Sprintf("%s push %s -d", settings.DefaultSealerBin, imageName) 35 case "rmi": 36 cmd = fmt.Sprintf("%s rmi %s -d", settings.DefaultSealerBin, imageName) 37 case "images": 38 cmd = fmt.Sprintf("%s images", settings.DefaultSealerBin) 39 case "inspect": 40 cmd = fmt.Sprintf("%s inspect %s -d", settings.DefaultSealerBin, imageName) 41 } 42 43 testhelper.RunCmdAndCheckResult(cmd, 0) 44 } 45 func TagImages(oldName, newName string) { 46 cmd := fmt.Sprintf("%s tag %s %s", settings.DefaultSealerBin, oldName, newName) 47 testhelper.RunCmdAndCheckResult(cmd, 0) 48 } 49 50 func CheckLoginResult(registryURL, username, passwd string, result bool) { 51 usernameCmd, passwdCmd := "", "" 52 if username != "" { 53 usernameCmd = fmt.Sprintf("-u %s", username) 54 } 55 if passwd != "" { 56 passwdCmd = fmt.Sprintf("-p %s", passwd) 57 } 58 loginCmd := fmt.Sprintf("%s login %s %s %s", settings.DefaultSealerBin, 59 settings.RegistryURL, 60 usernameCmd, 61 passwdCmd) 62 if result { 63 sess, err := testhelper.Start(loginCmd) 64 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 65 gomega.Eventually(sess).Should(gbytes.Say(fmt.Sprintln("Login Succeeded!"))) 66 gomega.Eventually(sess).Should(gexec.Exit(0)) 67 return 68 } 69 sess, err := testhelper.Start(loginCmd) 70 gomega.Expect(err).NotTo(gomega.HaveOccurred()) 71 gomega.Eventually(sess).ShouldNot(gbytes.Say(fmt.Sprintln("Login Succeeded!"))) 72 gomega.Eventually(sess).ShouldNot(gexec.Exit(0)) 73 }