<commit_before>package k8s

import (
	"testing"

	apps_v1 "k8s.io/api/apps/v1"
	core_v1 "k8s.io/api/core/v1"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestDeployment(t *testing.T) {
	d := &apps_v1.Deployment{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.DeploymentSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.DeploymentStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(0, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.Deployment)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[0].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}

func TestDeploymentMultipleContainers(t *testing.T) {
	d := &apps_v1.Deployment{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.DeploymentSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hi-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/bye-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.DeploymentStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(1, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.Deployment)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[1].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}<commit_msg>daemonset and statefulset conversion tests<commit_after>package k8s

import (
	"testing"

	apps_v1 "k8s.io/api/apps/v1"
	core_v1 "k8s.io/api/core/v1"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestDeployment(t *testing.T) {
	d := &apps_v1.Deployment{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.DeploymentSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.DeploymentStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(0, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.Deployment)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[0].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}

func TestDeploymentMultipleContainers(t *testing.T) {
	d := &apps_v1.Deployment{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.DeploymentSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hi-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/bye-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.DeploymentStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(1, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.Deployment)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[1].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}

func TestStatefulSetMultipleContainers(t *testing.T) {
	d := &apps_v1.StatefulSet{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.StatefulSetSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hi-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/bye-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.StatefulSetStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(1, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.StatefulSet)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[1].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}

func TestDaemonsetlSetMultipleContainers(t *testing.T) {
	d := &apps_v1.DaemonSet{
		meta_v1.TypeMeta{},
		meta_v1.ObjectMeta{
			Name:        "dep-1",
			Namespace:   "xxxx",
			Annotations: map[string]string{},
			Labels:      map[string]string{},
		},
		apps_v1.DaemonSetSpec{
			Template: core_v1.PodTemplateSpec{
				Spec: core_v1.PodSpec{
					Containers: []core_v1.Container{
						{
							Image: "gcr.io/v2-namespace/hi-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/hello-world:1.1.1",
						},
						{
							Image: "gcr.io/v2-namespace/bye-world:1.1.1",
						},
					},
				},
			},
		},
		apps_v1.DaemonSetStatus{},
	}

	gr, err := NewGenericResource(d)
	if err != nil {
		t.Fatalf("failed to create generic resource: %s", err)
	}

	gr.UpdateContainer(1, "hey/there")

	updated, ok := gr.GetResource().(*apps_v1.DaemonSet)
	if !ok {
		t.Fatalf("conversion failed")
	}

	if updated.Spec.Template.Spec.Containers[1].Image != "hey/there" {
		t.Errorf("unexpected image: %s", updated.Spec.Template.Spec.Containers[0].Image)
	}
}
{'fraction_non_alphanumeric': 0.17011995637949837, 'fraction_numerical': 0.023991275899672846, 'mean_word_length': 3.035197988686361, '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': '2463174', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2535, 'n_words': 364}