File: new_test.go

package info (click to toggle)
golang-github-containers-buildah 1.41.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 8,148 kB
  • sloc: sh: 2,569; makefile: 241; perl: 187; asm: 16; awk: 12; ansic: 1
file content (37 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package buildah

import (
	"testing"

	"github.com/containers/storage"
	"github.com/openshift/imagebuilder"
	"github.com/stretchr/testify/assert"
)

func TestGetImageName(t *testing.T) {
	t.Parallel()
	tt := []struct {
		caseName string
		name     string
		names    []string
		expected string
	}{
		{"tagged image", "busybox1", []string{"docker.io/library/busybox:latest", "docker.io/library/busybox1:latest"}, "docker.io/library/busybox1:latest"},
		{"image name not in the resolved image names", "image1", []string{"docker.io/library/busybox:latest", "docker.io/library/busybox1:latest"}, "docker.io/library/busybox:latest"},
		{"resolved image with empty name list", "image1", []string{}, "image1"},
	}

	for _, tc := range tt {
		img := &storage.Image{Names: tc.names}
		res := getImageName(tc.name, img)
		if res != tc.expected {
			t.Errorf("test case '%s' failed: expected %#v but got %#v", tc.caseName, tc.expected, res)
		}
	}
}

func TestNoBaseImageSpecifierIsScratch(t *testing.T) {
	t.Parallel()
	assert.Equal(t, "scratch", imagebuilder.NoBaseImageSpecifier) // juuuuust in case
	assert.Equal(t, "scratch", BaseImageFakeName)
}