mirror of
https://github.com/ipedrazas/drone-helm.git
synced 2026-06-04 18:24:13 +08:00
110 lines
2.7 KiB
Go
110 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInitialiseKubeconfig(t *testing.T) {
|
|
|
|
cmd := make([]string, 2)
|
|
cmd[0] = "install"
|
|
cmd[1] = "--debug"
|
|
|
|
plugin := Plugin{
|
|
Config: Config{
|
|
APIServer: "http://myapiserver",
|
|
Token: "secret-token",
|
|
HelmCommand: cmd,
|
|
Namespace: "default",
|
|
SkipTLSVerify: true,
|
|
},
|
|
}
|
|
|
|
configfile := "config3.test"
|
|
initialiseKubeconfig(&plugin.Config, "kubeconfig", configfile)
|
|
data, err := ioutil.ReadFile(configfile)
|
|
if err != nil {
|
|
t.Errorf("Error reading file %v", err)
|
|
}
|
|
kubeConfigStr := string(data)
|
|
|
|
if !strings.Contains(kubeConfigStr, "secret-token") {
|
|
t.Errorf("Kubeconfig doesn't render token")
|
|
}
|
|
if !strings.Contains(kubeConfigStr, "http://myapiserver") {
|
|
t.Errorf("Kubeconfig doesn't render APIServer")
|
|
}
|
|
|
|
}
|
|
|
|
func TestGetHelmCommand(t *testing.T) {
|
|
os.Setenv("DRONE_BUILD_EVENT", "push")
|
|
plugin := &Plugin{
|
|
Config: Config{
|
|
APIServer: "http://myapiserver",
|
|
Token: "secret-token",
|
|
HelmCommand: nil,
|
|
Namespace: "default",
|
|
SkipTLSVerify: true,
|
|
Debug: true,
|
|
DryRun: true,
|
|
Chart: "./chart/test",
|
|
Release: "test-release",
|
|
Values: "image.tag=v.0.1.0,nameOverride=my-over-app",
|
|
},
|
|
}
|
|
setHelmCommand(plugin)
|
|
res := strings.Join(plugin.Config.HelmCommand[:], " ")
|
|
expected := "upgrade --install test-release ./chart/test --set image.tag=v.0.1.0,nameOverride=my-over-app --namespace default --dry-run --debug"
|
|
if res != expected {
|
|
t.Errorf("Result is %s and we expected %s", res, expected)
|
|
}
|
|
}
|
|
|
|
func TestSetHelmHelp(t *testing.T) {
|
|
plugin := &Plugin{
|
|
Config: Config{
|
|
HelmCommand: nil,
|
|
Namespace: "default",
|
|
SkipTLSVerify: true,
|
|
Debug: true,
|
|
DryRun: true,
|
|
Chart: "./chart/test",
|
|
Release: "test-release",
|
|
Prefix: "MY",
|
|
Values: "image.tag=$TAG,api=${API_SERVER},nameOverride=my-over-app,second.tag=${TAG}",
|
|
},
|
|
}
|
|
setHelmHelp(plugin)
|
|
if plugin.Config.HelmCommand == nil {
|
|
t.Error("Helm help is not displayed")
|
|
}
|
|
}
|
|
|
|
func TestDetHelmInit(t *testing.T) {
|
|
plugin := &Plugin{
|
|
Config: Config{
|
|
HelmCommand: nil,
|
|
Namespace: "default",
|
|
SkipTLSVerify: true,
|
|
Debug: true,
|
|
DryRun: true,
|
|
Chart: "./chart/test",
|
|
Release: "test-release",
|
|
Prefix: "MY",
|
|
Values: "image.tag=$TAG,api=${API_SERVER},nameOverride=my-over-app,second.tag=${TAG}",
|
|
TillerNs: "system-test",
|
|
},
|
|
}
|
|
init := doHelmInit(plugin)
|
|
result := strings.Join(init, " ")
|
|
expected := "init --tiller-namespace " + plugin.Config.TillerNs
|
|
|
|
if expected != result {
|
|
t.Error("Tiller not installed in proper namespace")
|
|
}
|
|
}
|