MCPcopy Create free account
hub / github.com/CrunchyData/postgres-operator / TestInstanceEnvironment

Function TestInstanceEnvironment

internal/patroni/config_test.go:564–648  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

562}
563
564func TestInstanceEnvironment(t *testing.T) {
565 t.Parallel()
566
567 cluster := new(v1beta1.PostgresCluster)
568 cluster.Default()
569 cluster.Spec.PostgresVersion = 12
570 leaderService := new(corev1.Service)
571 podService := new(corev1.Service)
572 podService.Name = "pod-dns"
573
574 vars := instanceEnvironment(cluster, podService, leaderService, nil)
575
576 assert.Assert(t, cmp.MarshalMatches(vars, `
577- name: PATRONI_NAME
578 valueFrom:
579 fieldRef:
580 apiVersion: v1
581 fieldPath: metadata.name
582- name: PATRONI_KUBERNETES_POD_IP
583 valueFrom:
584 fieldRef:
585 apiVersion: v1
586 fieldPath: status.podIP
587- name: PATRONI_KUBERNETES_PORTS
588 value: |
589 []
590- name: PATRONI_POSTGRESQL_CONNECT_ADDRESS
591 value: $(PATRONI_NAME).pod-dns:5432
592- name: PATRONI_POSTGRESQL_LISTEN
593 value: '*:5432'
594- name: PATRONI_POSTGRESQL_CONFIG_DIR
595 value: /pgdata/pg12
596- name: PATRONI_POSTGRESQL_DATA_DIR
597 value: /pgdata/pg12
598- name: PATRONI_RESTAPI_CONNECT_ADDRESS
599 value: $(PATRONI_NAME).pod-dns:8008
600- name: PATRONI_RESTAPI_LISTEN
601 value: '*:8008'
602- name: PATRONICTL_CONFIG_FILE
603 value: /etc/patroni
604 `))
605
606 t.Run("MatchingPorts", func(t *testing.T) {
607 leaderService.Spec.Ports = []corev1.ServicePort{{Name: "postgres"}}
608 leaderService.Spec.Ports[0].TargetPort.StrVal = "postgres"
609 containers := []corev1.Container{{Name: "okay"}}
610 containers[0].Ports = []corev1.ContainerPort{{
611 Name: "postgres", ContainerPort: 9999, Protocol: corev1.ProtocolTCP,
612 }}
613
614 vars := instanceEnvironment(cluster, podService, leaderService, containers)
615
616 assert.Assert(t, cmp.MarshalMatches(vars, `
617- name: PATRONI_NAME
618 valueFrom:
619 fieldRef:
620 apiVersion: v1
621 fieldPath: metadata.name

Callers

nothing calls this directly

Calls 3

MarshalMatchesFunction · 0.92
instanceEnvironmentFunction · 0.85
DefaultMethod · 0.45

Tested by

no test coverage detected