Add global bin tests along with testdata
This commit is contained in:
parent
0d298c9951
commit
334d8c2bf0
76
cmd/dkl-dir2config/main_test.go
Normal file
76
cmd/dkl-dir2config/main_test.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
testDir = "testdata"
|
||||||
|
goldenFile = "config.yaml.golden"
|
||||||
|
outFile = "config.yaml"
|
||||||
|
|
||||||
|
binName = "dkl-dir2config"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
Build and run the code with default parameters and testdata
|
||||||
|
*/
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
fmt.Println("Building...")
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
binName += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
|
build := exec.Command("go", "build", "-o", filepath.Join(testDir, binName))
|
||||||
|
if err := build.Run(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Cannot build : %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Running Tests...")
|
||||||
|
result := m.Run()
|
||||||
|
|
||||||
|
fmt.Println("Cleaning Up ... ")
|
||||||
|
os.Remove(binName)
|
||||||
|
os.Exit(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunMain(t *testing.T) {
|
||||||
|
err := os.Chdir(testDir)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("RunWithNoArgument", func(t *testing.T) {
|
||||||
|
cmd := exec.Command("./" + binName)
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("CompareOutputs", func(t *testing.T) {
|
||||||
|
cmd := exec.Command("./"+binName, "-out", outFile)
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := os.ReadFile(outFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
expected, err := os.ReadFile(goldenFile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ret := bytes.Compare(output, expected); ret != 0 {
|
||||||
|
t.Fatalf("Output (%v) of length %d is different than expected (%v) of length %d", outFile, len(output), goldenFile, len(expected))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
39
cmd/dkl-dir2config/testdata/cert-requests.yaml
vendored
Normal file
39
cmd/dkl-dir2config/testdata/cert-requests.yaml
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
- name: etcd-server
|
||||||
|
ca: etcd
|
||||||
|
profile: server
|
||||||
|
per_host: true
|
||||||
|
template: |
|
||||||
|
{"CN":"{{.host.name}}","hosts":["127.0.0.1","{{.host.ip}}"],"key":{"algo":"ecdsa","size":256}}
|
||||||
|
- name: etcd-peer
|
||||||
|
ca: etcd
|
||||||
|
profile: peer
|
||||||
|
per_host: true
|
||||||
|
template: |
|
||||||
|
{"CN":"{{.host.name}}","hosts":["127.0.0.1","{{.host.ip}}"],"key":{"algo":"ecdsa","size":256}}
|
||||||
|
- name: etcd-client
|
||||||
|
ca: etcd
|
||||||
|
profile: client
|
||||||
|
template: |
|
||||||
|
{"CN":"client","hosts":["*"],"key":{"algo":"ecdsa","size":256}}
|
||||||
|
|
||||||
|
- name: apiserver
|
||||||
|
ca: cluster
|
||||||
|
profile: server
|
||||||
|
per_host: true
|
||||||
|
template: |
|
||||||
|
{"CN":"{{.host.name}}","hosts":[
|
||||||
|
"kubernetes", "kubernetes.default", "kubernetes.default.svc.{{.cluster.domain}}","{{.host.name}}",
|
||||||
|
"127.0.0.1","{{.cluster.kubernetes_svc_ip}}","{{.vars.public_vip}}",
|
||||||
|
{{- if .vars.apiserver_vip }}"{{.vars.apiserver_vip}}",{{ end }}
|
||||||
|
"{{.host.ip}}"
|
||||||
|
],"key":{"algo":"ecdsa","size":521}}
|
||||||
|
- name: cluster-client
|
||||||
|
ca: cluster
|
||||||
|
profile: client
|
||||||
|
template: |
|
||||||
|
{"CN":"client","hosts":["*"],"key":{"algo":"ecdsa","size":256}}
|
||||||
|
- name: kubelet-client
|
||||||
|
ca: cluster
|
||||||
|
profile: client
|
||||||
|
template: |
|
||||||
|
{"CN":"kubelet-client","names":[{"O":"system:masters"}],"hosts":["*"],"key":{"algo":"ecdsa","size":256}}
|
1
cmd/dkl-dir2config/testdata/clusters/test.yaml
vendored
Normal file
1
cmd/dkl-dir2config/testdata/clusters/test.yaml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
from: v1.19:test
|
6187
cmd/dkl-dir2config/testdata/config.yaml
vendored
Normal file
6187
cmd/dkl-dir2config/testdata/config.yaml
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6187
cmd/dkl-dir2config/testdata/config.yaml.golden
vendored
Normal file
6187
cmd/dkl-dir2config/testdata/config.yaml.golden
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
cmd/dkl-dir2config/testdata/defaults
vendored
Submodule
1
cmd/dkl-dir2config/testdata/defaults
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit be8c8592fbc39267755978860a095cbf297e924d
|
1
cmd/dkl-dir2config/testdata/groups/test-master.yaml
vendored
Normal file
1
cmd/dkl-dir2config/testdata/groups/test-master.yaml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
from: v1.19:master
|
3
cmd/dkl-dir2config/testdata/hosts/test1.yaml
vendored
Normal file
3
cmd/dkl-dir2config/testdata/hosts/test1.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ip: 172.16.0.1
|
||||||
|
cluster: test
|
||||||
|
group: test-master
|
3
cmd/dkl-dir2config/testdata/hosts/test2.yaml
vendored
Normal file
3
cmd/dkl-dir2config/testdata/hosts/test2.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ip: 172.16.0.2
|
||||||
|
cluster: test
|
||||||
|
group: test-master
|
3
cmd/dkl-dir2config/testdata/hosts/test3.yaml
vendored
Normal file
3
cmd/dkl-dir2config/testdata/hosts/test3.yaml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
ip: 172.16.0.3
|
||||||
|
cluster: test
|
||||||
|
group: test-master
|
34
cmd/dkl-dir2config/testdata/ssl-config.json
vendored
Normal file
34
cmd/dkl-dir2config/testdata/ssl-config.json
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"signing": {
|
||||||
|
"default": {
|
||||||
|
"expiry": "43800h"
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"server": {
|
||||||
|
"expiry": "43800h",
|
||||||
|
"usages": [
|
||||||
|
"signing",
|
||||||
|
"key encipherment",
|
||||||
|
"server auth"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"client": {
|
||||||
|
"expiry": "43800h",
|
||||||
|
"usages": [
|
||||||
|
"signing",
|
||||||
|
"key encipherment",
|
||||||
|
"client auth"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"peer": {
|
||||||
|
"expiry": "43800h",
|
||||||
|
"usages": [
|
||||||
|
"signing",
|
||||||
|
"key encipherment",
|
||||||
|
"server auth",
|
||||||
|
"client auth"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user