Files
troubleshoot/pkg/collect/etcd_test.go
Gerard Nguyen 47656a8e6f feat: etcd collector (#1589)
* new schema for etcd collector

* add placeholder

* wip

* get supported distribution

* add exec implementation

* wait for etcd pod to be ready

* misc

* update k0s etcd certs path

* fix unit tests

* address code reviews

* update from code review

* add etcdctl version
2024-08-13 08:42:26 +10:00

71 lines
1.8 KiB
Go

package collect
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)
func TestGetEtcdArgsByDistribution(t *testing.T) {
tests := []struct {
distribution string
expectedArgs []string
expectedPath string
expectedErr error
}{
{
distribution: "k0s",
expectedArgs: []string{
"--cacert", "/var/lib/k0s/pki/etcd/ca.crt",
"--cert", "/var/lib/k0s/pki/etcd/peer.crt",
"--key", "/var/lib/k0s/pki/etcd/peer.key",
"--write-out", "json",
"--endpoints", "https://127.0.0.1:2379",
},
expectedPath: "/var/lib/k0s/pki/etcd",
expectedErr: nil,
},
{
distribution: "embedded-cluster",
expectedArgs: []string{
"--cacert", "/var/lib/k0s/pki/etcd/ca.crt",
"--cert", "/var/lib/k0s/pki/etcd/peer.crt",
"--key", "/var/lib/k0s/pki/etcd/peer.key",
"--write-out", "json",
"--endpoints", "https://127.0.0.1:2379",
},
expectedPath: "/var/lib/k0s/pki/etcd",
expectedErr: nil,
},
{
distribution: "kurl",
expectedArgs: []string{
"--cacert", "/etc/kubernetes/pki/etcd/ca.crt",
"--cert", "/etc/kubernetes/pki/etcd/healthcheck-client.crt",
"--key", "/etc/kubernetes/pki/etcd/healthcheck-client.key",
"--write-out", "json",
"--endpoints", "https://127.0.0.1:2379",
},
expectedPath: "/etc/kubernetes/pki/etcd",
expectedErr: nil,
},
{
distribution: "unknown",
expectedArgs: nil,
expectedPath: "",
expectedErr: errors.Errorf("distribution unknown not supported"),
},
}
for _, test := range tests {
args, path, err := getEtcdArgsByDistribution(test.distribution)
assert.Equal(t, test.expectedArgs, args)
assert.Equal(t, test.expectedPath, path)
if test.expectedErr != nil {
assert.NotNil(t, err)
assert.EqualError(t, test.expectedErr, err.Error())
}
}
}