github.com/flanksource/konfigadm@v0.12.0/pkg/phases/trusted_ca_test.go (about)

     1  package phases_test
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	. "github.com/flanksource/konfigadm/pkg/types"
     9  	"github.com/onsi/gomega"
    10  )
    11  
    12  func TestTrustedCA(t *testing.T) {
    13  	cfg, g := NewFixture("trusted_ca.yml", t).Build()
    14  	wd, _ := os.Getwd()
    15  	err := os.Chdir("../..")
    16  	g.Expect(err).ToNot(gomega.HaveOccurred())
    17  	defer os.Chdir(wd) // nolint: errcheck
    18  	files, commands, err := cfg.ApplyPhases()
    19  	g.Expect(err).ToNot(gomega.HaveOccurred())
    20  	g.Expect(files).To(gomega.HaveLen(3))
    21  
    22  	g.Expect(files).To(gomega.HaveKey("/tmp/install_certs"))
    23  	data, _ := ioutil.ReadFile("fixtures/files/example-k8s-ca.pem")
    24  
    25  	file0 := files["/tmp/konfigadm-trusted-0.pem"]
    26  	g.Expect(file0.Content).To(gomega.Equal(string(data)))
    27  	file1 := files["/tmp/konfigadm-trusted-1.pem"]
    28  	g.Expect(file1.Content).To(gomega.Equal(string(cfg.TrustedCA[1])))
    29  
    30  	g.Expect(commands).To(gomega.HaveLen(4))
    31  	g.Expect(commands[0].Cmd).To(gomega.Equal("/tmp/install_certs /tmp/konfigadm-trusted-0.pem"))
    32  	g.Expect(commands[1].Cmd).To(gomega.Equal("/tmp/install_certs /tmp/konfigadm-trusted-1.pem"))
    33  	g.Expect(commands[2].Cmd).To(gomega.Equal("rm -r /tmp/konfigadm-trusted-*.pem"))
    34  	g.Expect(commands[3].Cmd).To(gomega.Equal("rm -r /tmp/install_certs"))
    35  }