Skip to content

Commit

Permalink
fix the failing config_test where it needed the charts dependencies i…
Browse files Browse the repository at this point in the history
…nstalled.

Signed-off-by: Edward Welch <[email protected]>
  • Loading branch information
slim-bean committed Mar 1, 2024
1 parent 6140657 commit c4d44ea
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions production/helm/loki/test/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"os"
"os/exec"
"sync"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -19,6 +20,7 @@ type loki struct {
}

type values struct {
DeploymentMode string `yaml:"deploymentMode"`
Backend replicas `yaml:"backend"`
Compactor replicas `yaml:"compactor"`
Distributor replicas `yaml:"distributor"`
Expand All @@ -35,6 +37,9 @@ type values struct {
Loki loki `yaml:"loki"`
}

// This speeds up the tests, don't think this will cause problems but if you are reading this it probably did :)
var helmDependencyBuild sync.Once

func templateConfig(t *testing.T, vals values) error {
y, err := yaml.Marshal(&vals)
require.NoError(t, err)
Expand All @@ -46,6 +51,20 @@ func templateConfig(t *testing.T, vals values) error {
_, err = f.Write(y)
require.NoError(t, err)

var doOnceError error
helmDependencyBuild.Do(func() {
cmd := exec.Command("helm", "dependency", "build")
// Dependency build needs to be run from the parent directory where the chart is located.
cmd.Dir = "../"
var cmdOutput []byte
if cmdOutput, doOnceError = cmd.CombinedOutput(); err != nil {
t.Log("dependency build failed", "err", string(cmdOutput))
}
})
if doOnceError != nil {
return doOnceError
}

cmd := exec.Command("helm", "template", "../", "--values", f.Name())
if cmdOutput, err := cmd.CombinedOutput(); err != nil {
t.Log("template failed", "err", string(cmdOutput))
Expand Down Expand Up @@ -124,6 +143,9 @@ func Test_InvalidConfigs(t *testing.T) {
func Test_ValidConfigs(t *testing.T) {
t.Run("single binary", func(t *testing.T) {
vals := values{

DeploymentMode: "SingleBinary",

SingleBinary: replicas{Replicas: 1},

Backend: replicas{Replicas: 0},
Expand All @@ -149,6 +171,9 @@ func Test_ValidConfigs(t *testing.T) {

t.Run("scalable", func(t *testing.T) {
vals := values{

DeploymentMode: "SimpleScalable",

Backend: replicas{Replicas: 1},
Read: replicas{Replicas: 1},
Write: replicas{Replicas: 1},
Expand All @@ -174,6 +199,8 @@ func Test_ValidConfigs(t *testing.T) {

t.Run("distributed", func(t *testing.T) {
vals := values{
DeploymentMode: "Distributed",

Compactor: replicas{Replicas: 1},
Distributor: replicas{Replicas: 1},
IndexGateway: replicas{Replicas: 1},
Expand Down

0 comments on commit c4d44ea

Please sign in to comment.