<commit_before>package images

import (
	"fmt"
	"time"

	g "github.com/onsi/ginkgo"
	o "github.com/onsi/gomega"

	kapi "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"

	buildapi "github.com/openshift/api/build/v1"
	imageapi "github.com/openshift/api/image/v1"
	buildclientset "github.com/openshift/client-go/build/clientset/versioned"
	imageclientset "github.com/openshift/client-go/image/clientset/versioned"
	exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[Feature:ImageLayers] Image layer subresource", func() {
	defer g.GinkgoRecover()
	var oc *exutil.CLI
	var ns []string

	g.AfterEach(func() {
		if g.CurrentGinkgoTestDescription().Failed {
			for _, s := range ns {
				exutil.DumpPodLogsStartingWithInNamespace("", s, oc)
			}
		}
	})

	oc = exutil.NewCLI("image-layers", exutil.KubeConfigPath())

	g.It("should identify a deleted image as missing", func() {
		client := imageclientset.NewForConfigOrDie(oc.AdminConfig()).Image()
		_, err := client.ImageStreams(oc.Namespace()).Create(&imageapi.ImageStream{
			ObjectMeta: metav1.ObjectMeta{
				Name: "test",
			},
		})
		o.Expect(err).NotTo(o.HaveOccurred())
		_, err = client.ImageStreamMappings(oc.Namespace()).Create(&imageapi.ImageStreamMapping{
			ObjectMeta: metav1.ObjectMeta{
				Name: "test",
			},
			Image: imageapi.Image{
				ObjectMeta: metav1.ObjectMeta{
					Name: "an_image_to_be_deleted",
				},
				DockerImageReference: "example.com/random/image:latest",
			},
			Tag: "missing",
		})
		o.Expect(err).NotTo(o.HaveOccurred())
		err = client.Images().Delete("an_image_to_be_deleted", nil)
		o.Expect(err).NotTo(o.HaveOccurred())
		err = wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
			layers, err := client.ImageStreams(oc.Namespace()).Layers("test", metav1.GetOptions{})
			if err != nil {
				return false, err
			}
			ref, ok := layers.Images["an_image_to_be_deleted"]
			if !ok {
				return false, nil
			}
			o.Expect(ref.ImageMissing).To(o.BeTrue())
			return true, nil
		})
		o.Expect(err).NotTo(o.HaveOccurred())
	})

	g.It("should return layers from tagged images", func() {<commit_msg>ImageLayers test should loop until image is missing<commit_after>package images

import (
	"fmt"
	"time"

	g "github.com/onsi/ginkgo"
	o "github.com/onsi/gomega"

	kapi "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/errors"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/wait"

	buildapi "github.com/openshift/api/build/v1"
	imageapi "github.com/openshift/api/image/v1"
	buildclientset "github.com/openshift/client-go/build/clientset/versioned"
	imageclientset "github.com/openshift/client-go/image/clientset/versioned"
	exutil "github.com/openshift/origin/test/extended/util"
)

var _ = g.Describe("[Feature:ImageLayers] Image layer subresource", func() {
	defer g.GinkgoRecover()
	var oc *exutil.CLI
	var ns []string

	g.AfterEach(func() {
		if g.CurrentGinkgoTestDescription().Failed {
			for _, s := range ns {
				exutil.DumpPodLogsStartingWithInNamespace("", s, oc)
			}
		}
	})

	oc = exutil.NewCLI("image-layers", exutil.KubeConfigPath())

	g.It("should identify a deleted image as missing", func() {
		client := imageclientset.NewForConfigOrDie(oc.AdminConfig()).Image()
		_, err := client.ImageStreams(oc.Namespace()).Create(&imageapi.ImageStream{
			ObjectMeta: metav1.ObjectMeta{
				Name: "test",
			},
		})
		o.Expect(err).NotTo(o.HaveOccurred())
		_, err = client.ImageStreamMappings(oc.Namespace()).Create(&imageapi.ImageStreamMapping{
			ObjectMeta: metav1.ObjectMeta{
				Name: "test",
			},
			Image: imageapi.Image{
				ObjectMeta: metav1.ObjectMeta{
					Name: "an_image_to_be_deleted",
				},
				DockerImageReference: "example.com/random/image:latest",
			},
			Tag: "missing",
		})
		o.Expect(err).NotTo(o.HaveOccurred())
		err = client.Images().Delete("an_image_to_be_deleted", nil)
		o.Expect(err).NotTo(o.HaveOccurred())
		err = wait.PollImmediate(time.Second, time.Minute, func() (bool, error) {
			layers, err := client.ImageStreams(oc.Namespace()).Layers("test", metav1.GetOptions{})
			if err != nil {
				return false, err
			}
			ref, ok := layers.Images["an_image_to_be_deleted"]
			if !ok {
				return false, nil
			}
			return ref.ImageMissing, nil
		})
		o.Expect(err).NotTo(o.HaveOccurred())
	})

	g.It("should return layers from tagged images", func() {
{'fraction_non_alphanumeric': 0.1566644189705552, 'fraction_numerical': 0.005844009889862891, 'mean_word_length': 4.25383707201889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3078990', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1670, 'n_words': 258}