github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/untag_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/hanks177/podman/v4/test/utils"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("Podman untag", func() {
    13  	var (
    14  		tempdir    string
    15  		err        error
    16  		podmanTest *PodmanTestIntegration
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		tempdir, err = CreateTempDirInTempDir()
    21  		if err != nil {
    22  			os.Exit(1)
    23  		}
    24  		podmanTest = PodmanTestCreate(tempdir)
    25  		podmanTest.Setup()
    26  	})
    27  
    28  	AfterEach(func() {
    29  		podmanTest.Cleanup()
    30  		f := CurrentGinkgoTestDescription()
    31  		processTestResult(f)
    32  
    33  	})
    34  
    35  	It("podman untag all", func() {
    36  		podmanTest.AddImageToRWStore(cirros)
    37  		tags := []string{cirros, "registry.com/foo:bar", "localhost/foo:bar"}
    38  
    39  		cmd := []string{"tag"}
    40  		cmd = append(cmd, tags...)
    41  		session := podmanTest.Podman(cmd)
    42  		session.WaitWithDefaultTimeout()
    43  		Expect(session).Should(Exit(0))
    44  
    45  		// Make sure that all tags exists.
    46  		for _, t := range tags {
    47  			session = podmanTest.Podman([]string{"image", "exists", t})
    48  			session.WaitWithDefaultTimeout()
    49  			Expect(session).Should(Exit(0))
    50  		}
    51  
    52  		// No arguments -> remove all tags.
    53  		session = podmanTest.Podman([]string{"untag", cirros})
    54  		session.WaitWithDefaultTimeout()
    55  		Expect(session).Should(Exit(0))
    56  
    57  		// Make sure that none of tags exists anymore.
    58  		for _, t := range tags {
    59  			session = podmanTest.Podman([]string{"image", "exists", t})
    60  			session.WaitWithDefaultTimeout()
    61  			Expect(session).Should(Exit(1))
    62  		}
    63  	})
    64  
    65  	It("podman tag/untag - tag normalization", func() {
    66  		podmanTest.AddImageToRWStore(cirros)
    67  
    68  		tests := []struct {
    69  			tag, normalized string
    70  		}{
    71  			{"registry.com/image:latest", "registry.com/image:latest"},
    72  			{"registry.com/image", "registry.com/image:latest"},
    73  			{"image:latest", "localhost/image:latest"},
    74  			{"image", "localhost/image:latest"},
    75  		}
    76  
    77  		// Make sure that the user input is normalized correctly for
    78  		// `podman tag` and `podman untag`.
    79  		for _, tt := range tests {
    80  			session := podmanTest.Podman([]string{"tag", cirros, tt.tag})
    81  			session.WaitWithDefaultTimeout()
    82  			Expect(session).Should(Exit(0))
    83  
    84  			session = podmanTest.Podman([]string{"image", "exists", tt.normalized})
    85  			session.WaitWithDefaultTimeout()
    86  			Expect(session).Should(Exit(0))
    87  
    88  			session = podmanTest.Podman([]string{"untag", cirros, tt.tag})
    89  			session.WaitWithDefaultTimeout()
    90  			Expect(session).Should(Exit(0))
    91  
    92  			session = podmanTest.Podman([]string{"image", "exists", tt.normalized})
    93  			session.WaitWithDefaultTimeout()
    94  			Expect(session).Should(Exit(1))
    95  		}
    96  	})
    97  
    98  })