<commit_before>package imagefetcher_test

import (
	"errors"

	"github.com/fsouza/go-dockerclient"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/room101-ci/agent/api/builds/imagefetcher"

	"github.com/room101-ci/agent/testhelpers/fakedocker"
)

var _ = Describe("Imagefetcher", func() {
	var dockerImageClient *fakedocker.Client
	var fetcher *ImageFetcher

	BeforeEach(func() {
		dockerImageClient = fakedocker.NewClient()
		fetcher = NewImageFetcher(dockerImageClient)
	})

	It("pulls the image and returns its id", func() {
		dockerImageClient.InspectImageResult = &docker.Image{
			ID: "some-id",
		}

		id, err := fetcher.Fetch("some-name")
		Ω(err).ShouldNot(HaveOccurred())

		Ω(dockerImageClient.PulledImages()).Should(ContainElement(fakedocker.PulledImage{
			PullImageOptions: docker.PullImageOptions{
				Repository: "some-name",
			},
		}))

		Ω(id).Should(Equal("some-id"))
	})

	Context("when pulling the image fails", func() {
		disaster := errors.New("oh no!")

		BeforeEach(func() {
			dockerImageClient.PullImageError = disaster
		})

		It("returns the error", func() {
			_, err := fetcher.Fetch("some-name")
			Ω(err).Should(Equal(disaster))
		})
	})

	Context("when inspecting the image fails", func() {
		disaster := errors.New("oh no!")

		BeforeEach(func() {
			dockerImageClient.InspectImageError = disaster
		})
<commit_msg>update test for logging change<commit_after>package imagefetcher_test

import (
	"errors"
	"os"

	"github.com/fsouza/go-dockerclient"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	. "github.com/room101-ci/agent/api/builds/imagefetcher"

	"github.com/room101-ci/agent/testhelpers/fakedocker"
)

var _ = Describe("Imagefetcher", func() {
	var dockerImageClient *fakedocker.Client
	var fetcher *ImageFetcher

	BeforeEach(func() {
		dockerImageClient = fakedocker.NewClient()
		fetcher = NewImageFetcher(dockerImageClient)
	})

	It("pulls the image and returns its id", func() {
		dockerImageClient.InspectImageResult = &docker.Image{
			ID: "some-id",
		}

		id, err := fetcher.Fetch("some-name")
		Ω(err).ShouldNot(HaveOccurred())

		Ω(dockerImageClient.PulledImages()).Should(ContainElement(fakedocker.PulledImage{
			PullImageOptions: docker.PullImageOptions{
				Repository:   "some-name",
				OutputStream: os.Stderr,
			},
		}))

		Ω(id).Should(Equal("some-id"))
	})

	Context("when pulling the image fails", func() {
		disaster := errors.New("oh no!")

		BeforeEach(func() {
			dockerImageClient.PullImageError = disaster
		})

		It("returns the error", func() {
			_, err := fetcher.Fetch("some-name")
			Ω(err).Should(Equal(disaster))
		})
	})

	Context("when inspecting the image fails", func() {
		disaster := errors.New("oh no!")

		BeforeEach(func() {
			dockerImageClient.InspectImageError = disaster
		})

{'fraction_non_alphanumeric': 0.1508559201141227, 'fraction_numerical': 0.0042796005706134095, 'mean_word_length': 4.5, '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': '3510370', 'n_tokens_mistral': 1103, 'n_tokens_neox': 981, 'n_words': 159}