mirror of https://github.com/k3s-io/k3s
Moved testing utils into tests directory. Improved gotests template. (#3805)
* Moved testing utils into tests directory. Improved gotests template. * Updated cgroups2 with util folder rename Signed-off-by: dereknola <derek.nola@suse.com>pull/3820/head
parent
dcf0657b20
commit
4cc781b5e3
|
@ -41,7 +41,7 @@ jobs:
|
||||||
path: ./tests/cgroup2
|
path: ./tests/cgroup2
|
||||||
- name: "Boot Fedora VM"
|
- name: "Boot Fedora VM"
|
||||||
run: |
|
run: |
|
||||||
cp -r k3s.service k3s-rootless.service ./tests/testutil ./tests/cgroup2
|
cp -r k3s.service k3s-rootless.service ./tests/util ./tests/cgroup2
|
||||||
cd ./tests/cgroup2
|
cd ./tests/cgroup2
|
||||||
vagrant up
|
vagrant up
|
||||||
vagrant ssh-config >> ~/.ssh/config
|
vagrant ssh-config >> ~/.ssh/config
|
||||||
|
@ -51,7 +51,7 @@ jobs:
|
||||||
# Sonobuoy requires CoreDNS to be ready
|
# Sonobuoy requires CoreDNS to be ready
|
||||||
- name: "Waiting for CoreDNS to be ready"
|
- name: "Waiting for CoreDNS to be ready"
|
||||||
run: |
|
run: |
|
||||||
ssh default -- sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml /vagrant/testutil/wait-for-coredns.sh
|
ssh default -- sudo KUBECONFIG=/etc/rancher/k3s/k3s.yaml /vagrant/util/wait-for-coredns.sh
|
||||||
# Vagrant is slow, so we set --mode=quick here
|
# Vagrant is slow, so we set --mode=quick here
|
||||||
- name: "Run Sonobuoy (--mode=quick)"
|
- name: "Run Sonobuoy (--mode=quick)"
|
||||||
run: |
|
run: |
|
||||||
|
@ -69,7 +69,7 @@ jobs:
|
||||||
ssh default -- systemctl --user start k3s-rootless
|
ssh default -- systemctl --user start k3s-rootless
|
||||||
- name: "[Rootless] Waiting for CoreDNS to be ready"
|
- name: "[Rootless] Waiting for CoreDNS to be ready"
|
||||||
run: |
|
run: |
|
||||||
ssh default -- KUBECONFIG=/home/vagrant/.kube/k3s.yaml /vagrant/testutil/wait-for-coredns.sh
|
ssh default -- KUBECONFIG=/home/vagrant/.kube/k3s.yaml /vagrant/util/wait-for-coredns.sh
|
||||||
- name: "[Rootless] Run Sonobuoy (--mode=quick)"
|
- name: "[Rootless] Run Sonobuoy (--mode=quick)"
|
||||||
run: |
|
run: |
|
||||||
ssh default -- KUBECONFIG=/home/vagrant/.kube/k3s.yaml sonobuoy run --mode=quick --wait
|
ssh default -- KUBECONFIG=/home/vagrant/.kube/k3s.yaml sonobuoy run --mode=quick --wait
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{{define "function"}}
|
{{define "function"}}
|
||||||
{{- $f := .}}
|
{{- $f := .}}
|
||||||
|
|
||||||
func {{.TestName}}(t *testing.T) {
|
func Test_Unit{{.FullName}}(t *testing.T) {
|
||||||
{{- with .Receiver}}
|
{{- with .Receiver}}
|
||||||
{{- if .IsStruct}}
|
{{- if .IsStruct}}
|
||||||
{{- if .Fields}}
|
{{- if .Fields}}
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/rancher/k3s/pkg/util/tests"
|
testutil "github.com/rancher/k3s/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var serverCmd *exec.Cmd
|
var serverCmd *exec.Cmd
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
var err error
|
var err error
|
||||||
serverCmd, _, err = tests.K3sCmdAsync("server", "--cluster-init")
|
serverCmd, _, err = testutil.K3sCmdAsync("server", "--cluster-init")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -23,62 +23,62 @@ var _ = Describe("etcd snapshots", func() {
|
||||||
When("a new etcd is created", func() {
|
When("a new etcd is created", func() {
|
||||||
It("starts up with no problems", func() {
|
It("starts up with no problems", func() {
|
||||||
Eventually(func() (string, error) {
|
Eventually(func() (string, error) {
|
||||||
return tests.K3sCmd("kubectl", "get", "pods", "-A")
|
return testutil.K3sCmd("kubectl", "get", "pods", "-A")
|
||||||
}, "90s", "1s").Should(MatchRegexp("kube-system.+coredns.+1\\/1.+Running"))
|
}, "90s", "1s").Should(MatchRegexp("kube-system.+coredns.+1\\/1.+Running"))
|
||||||
})
|
})
|
||||||
It("saves an etcd snapshot", func() {
|
It("saves an etcd snapshot", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "save")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "save")).
|
||||||
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
||||||
})
|
})
|
||||||
It("list snapshots", func() {
|
It("list snapshots", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "ls")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "ls")).
|
||||||
To(MatchRegexp(`:///var/lib/rancher/k3s/server/db/snapshots/on-demand`))
|
To(MatchRegexp(`:///var/lib/rancher/k3s/server/db/snapshots/on-demand`))
|
||||||
})
|
})
|
||||||
It("deletes a snapshot", func() {
|
It("deletes a snapshot", func() {
|
||||||
lsResult, err := tests.K3sCmd("etcd-snapshot", "ls")
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
reg, err := regexp.Compile(`on-demand[^\s]+`)
|
reg, err := regexp.Compile(`on-demand[^\s]+`)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
snapshotName := reg.FindString(lsResult)
|
snapshotName := reg.FindString(lsResult)
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
Expect(testutil.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
||||||
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
When("saving a custom name", func() {
|
When("saving a custom name", func() {
|
||||||
It("starts with no snapshots", func() {
|
It("starts with no snapshots", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
Expect(testutil.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
||||||
})
|
})
|
||||||
It("saves an etcd snapshot with a custom name", func() {
|
It("saves an etcd snapshot with a custom name", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "save", "--name", "ALIVEBEEF")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "--name", "ALIVEBEEF")).
|
||||||
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/k3s/server/db/snapshots/ALIVEBEEF"))
|
To(ContainSubstring("Saving etcd snapshot to /var/lib/rancher/k3s/server/db/snapshots/ALIVEBEEF"))
|
||||||
})
|
})
|
||||||
It("deletes that snapshot", func() {
|
It("deletes that snapshot", func() {
|
||||||
lsResult, err := tests.K3sCmd("etcd-snapshot", "ls")
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
reg, err := regexp.Compile(`ALIVEBEEF[^\s]+`)
|
reg, err := regexp.Compile(`ALIVEBEEF[^\s]+`)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
snapshotName := reg.FindString(lsResult)
|
snapshotName := reg.FindString(lsResult)
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
Expect(testutil.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
||||||
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
When("using etcd snapshot prune", func() {
|
When("using etcd snapshot prune", func() {
|
||||||
It("starts with no snapshots", func() {
|
It("starts with no snapshots", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
Expect(testutil.K3sCmd("etcd-snapshot", "ls")).To(BeEmpty())
|
||||||
})
|
})
|
||||||
It("saves 3 different snapshots", func() {
|
It("saves 3 different snapshots", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
||||||
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
||||||
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "save", "-name", "PRUNE_TEST")).
|
||||||
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
To(ContainSubstring("Saving current etcd snapshot set to k3s-etcd-snapshots"))
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
})
|
})
|
||||||
It("lists all 3 snapshots", func() {
|
It("lists all 3 snapshots", func() {
|
||||||
lsResult, err := tests.K3sCmd("etcd-snapshot", "ls")
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
||||||
return c == '\n'
|
return c == '\n'
|
||||||
|
@ -87,9 +87,9 @@ var _ = Describe("etcd snapshots", func() {
|
||||||
Expect(sepLines).To(HaveLen(3))
|
Expect(sepLines).To(HaveLen(3))
|
||||||
})
|
})
|
||||||
It("prunes snapshots down to 2", func() {
|
It("prunes snapshots down to 2", func() {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "prune", "--snapshot-retention", "2", "--name", "PRUNE_TEST")).
|
Expect(testutil.K3sCmd("etcd-snapshot", "prune", "--snapshot-retention", "2", "--name", "PRUNE_TEST")).
|
||||||
To(BeEmpty())
|
To(BeEmpty())
|
||||||
lsResult, err := tests.K3sCmd("etcd-snapshot", "ls")
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
sepLines := strings.FieldsFunc(lsResult, func(c rune) bool {
|
||||||
return c == '\n'
|
return c == '\n'
|
||||||
|
@ -98,12 +98,12 @@ var _ = Describe("etcd snapshots", func() {
|
||||||
Expect(sepLines).To(HaveLen(2))
|
Expect(sepLines).To(HaveLen(2))
|
||||||
})
|
})
|
||||||
It("cleans up remaining snapshots", func() {
|
It("cleans up remaining snapshots", func() {
|
||||||
lsResult, err := tests.K3sCmd("etcd-snapshot", "ls")
|
lsResult, err := testutil.K3sCmd("etcd-snapshot", "ls")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
reg, err := regexp.Compile(`PRUNE_TEST[^\s]+`)
|
reg, err := regexp.Compile(`PRUNE_TEST[^\s]+`)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
for _, snapshotName := range reg.FindAllString(lsResult, -1) {
|
for _, snapshotName := range reg.FindAllString(lsResult, -1) {
|
||||||
Expect(tests.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
Expect(testutil.K3sCmd("etcd-snapshot", "delete", snapshotName)).
|
||||||
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
To(ContainSubstring("Removing the given locally stored etcd snapshot"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -111,7 +111,7 @@ var _ = Describe("etcd snapshots", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = AfterSuite(func() {
|
var _ = AfterSuite(func() {
|
||||||
Expect(tests.K3sKillAsync(serverCmd)).To(Succeed())
|
Expect(testutil.K3sKillAsync(serverCmd)).To(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
func Test_IntegrationEtcd(t *testing.T) {
|
func Test_IntegrationEtcd(t *testing.T) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/rancher/k3s/pkg/clientaccess"
|
"github.com/rancher/k3s/pkg/clientaccess"
|
||||||
"github.com/rancher/k3s/pkg/daemons/config"
|
"github.com/rancher/k3s/pkg/daemons/config"
|
||||||
"github.com/rancher/k3s/pkg/util/tests"
|
testutil "github.com/rancher/k3s/tests/util"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
etcd "go.etcd.io/etcd/clientv3"
|
etcd "go.etcd.io/etcd/clientv3"
|
||||||
)
|
)
|
||||||
|
@ -62,13 +62,13 @@ func Test_UnitETCD_IsInitialized(t *testing.T) {
|
||||||
config: generateTestConfig(),
|
config: generateTestConfig(),
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
if err := tests.GenerateDataDir(cnf); err != nil {
|
if err := testutil.GenerateDataDir(cnf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.MkdirAll(walDir(cnf), 0700)
|
return os.MkdirAll(walDir(cnf), 0700)
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return os.Remove(walDir(cnf))
|
return os.Remove(walDir(cnf))
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
|
@ -81,7 +81,7 @@ func Test_UnitETCD_IsInitialized(t *testing.T) {
|
||||||
config: generateTestConfig(),
|
config: generateTestConfig(),
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
if err := tests.GenerateDataDir(cnf); err != nil {
|
if err := testutil.GenerateDataDir(cnf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// We don't care if removal fails to find the dir
|
// We don't care if removal fails to find the dir
|
||||||
|
@ -89,7 +89,7 @@ func Test_UnitETCD_IsInitialized(t *testing.T) {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
|
@ -138,10 +138,10 @@ func Test_UnitETCD_Register(t *testing.T) {
|
||||||
handler: generateTestHandler(),
|
handler: generateTestHandler(),
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
return tests.GenerateRuntime(cnf)
|
return testutil.GenerateRuntime(cnf)
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -153,7 +153,7 @@ func Test_UnitETCD_Register(t *testing.T) {
|
||||||
handler: generateTestHandler(),
|
handler: generateTestHandler(),
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
if err := tests.GenerateRuntime(cnf); err != nil {
|
if err := testutil.GenerateRuntime(cnf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := os.MkdirAll(etcdDBDir(cnf), 0700); err != nil {
|
if err := os.MkdirAll(etcdDBDir(cnf), 0700); err != nil {
|
||||||
|
@ -168,7 +168,7 @@ func Test_UnitETCD_Register(t *testing.T) {
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tombstoneFile := filepath.Join(etcdDBDir(cnf), "tombstone")
|
tombstoneFile := filepath.Join(etcdDBDir(cnf), "tombstone")
|
||||||
os.Remove(tombstoneFile)
|
os.Remove(tombstoneFile)
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -225,10 +225,10 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
cnf.EtcdDisableSnapshots = true
|
cnf.EtcdDisableSnapshots = true
|
||||||
return tests.GenerateRuntime(cnf)
|
return testutil.GenerateRuntime(cnf)
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -244,10 +244,10 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
clientAccessInfo: nil,
|
clientAccessInfo: nil,
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
return tests.GenerateRuntime(cnf)
|
return testutil.GenerateRuntime(cnf)
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -263,13 +263,13 @@ func Test_UnitETCD_Start(t *testing.T) {
|
||||||
clientAccessInfo: nil,
|
clientAccessInfo: nil,
|
||||||
},
|
},
|
||||||
setup: func(cnf *config.Control) error {
|
setup: func(cnf *config.Control) error {
|
||||||
if err := tests.GenerateRuntime(cnf); err != nil {
|
if err := testutil.GenerateRuntime(cnf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return os.MkdirAll(walDir(cnf), 0700)
|
return os.MkdirAll(walDir(cnf), 0700)
|
||||||
},
|
},
|
||||||
teardown: func(cnf *config.Control) error {
|
teardown: func(cnf *config.Control) error {
|
||||||
tests.CleanupDataDir(cnf)
|
testutil.CleanupDataDir(cnf)
|
||||||
os.Remove(walDir(cnf))
|
os.Remove(walDir(cnf))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
k3s
|
k3s
|
||||||
k3s.service
|
k3s.service
|
||||||
k3s-rootless.service
|
k3s-rootless.service
|
||||||
testutil/
|
util/
|
||||||
.vagrant/
|
.vagrant/
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
# - k3s
|
# - k3s
|
||||||
# - k3s.service
|
# - k3s.service
|
||||||
# - k3s-rootless.service
|
# - k3s-rootless.service
|
||||||
# - testutil/
|
# - util/
|
||||||
Vagrant.configure("2") do |config|
|
Vagrant.configure("2") do |config|
|
||||||
config.vm.box = "fedora/34-cloud-base"
|
config.vm.box = "fedora/34-cloud-base"
|
||||||
memory = 2048
|
memory = 2048
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package tests
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -10,13 +10,13 @@ import (
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"github.com/rancher/k3s/pkg/util/tests"
|
testutil "github.com/rancher/k3s/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var serverCmd *exec.Cmd
|
var serverCmd *exec.Cmd
|
||||||
var _ = BeforeSuite(func() {
|
var _ = BeforeSuite(func() {
|
||||||
var err error
|
var err error
|
||||||
serverCmd, _, err = tests.K3sCmdAsync("server", "--cluster-init")
|
serverCmd, _, err = testutil.K3sCmdAsync("server", "--cluster-init")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -24,24 +24,24 @@ var _ = Describe("local storage", func() {
|
||||||
When("a new local storage is created", func() {
|
When("a new local storage is created", func() {
|
||||||
It("starts up with no problems", func() {
|
It("starts up with no problems", func() {
|
||||||
Eventually(func() (string, error) {
|
Eventually(func() (string, error) {
|
||||||
return tests.K3sCmd("kubectl", "get", "pods", "-A")
|
return testutil.K3sCmd("kubectl", "get", "pods", "-A")
|
||||||
}, "90s", "1s").Should(MatchRegexp("kube-system.+coredns.+1\\/1.+Running"))
|
}, "90s", "1s").Should(MatchRegexp("kube-system.+coredns.+1\\/1.+Running"))
|
||||||
})
|
})
|
||||||
It("creates a new pvc", func() {
|
It("creates a new pvc", func() {
|
||||||
Expect(tests.K3sCmd("kubectl", "create", "-f", "testdata/localstorage_pvc.yaml")).
|
Expect(testutil.K3sCmd("kubectl", "create", "-f", "../testdata/localstorage_pvc.yaml")).
|
||||||
To(ContainSubstring("persistentvolumeclaim/local-path-pvc created"))
|
To(ContainSubstring("persistentvolumeclaim/local-path-pvc created"))
|
||||||
})
|
})
|
||||||
It("creates a new pod", func() {
|
It("creates a new pod", func() {
|
||||||
Expect(tests.K3sCmd("kubectl", "create", "-f", "testdata/localstorage_pod.yaml")).
|
Expect(testutil.K3sCmd("kubectl", "create", "-f", "../testdata/localstorage_pod.yaml")).
|
||||||
To(ContainSubstring("pod/volume-test created"))
|
To(ContainSubstring("pod/volume-test created"))
|
||||||
})
|
})
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
It("shows storage up in kubectl", func() {
|
It("shows storage up in kubectl", func() {
|
||||||
Eventually(func() (string, error) {
|
Eventually(func() (string, error) {
|
||||||
return tests.K3sCmd("kubectl", "get", "pv")
|
return testutil.K3sCmd("kubectl", "get", "pv")
|
||||||
}, "30s", "1s").Should(MatchRegexp(`pvc.+2Gi.+Bound`))
|
}, "30s", "1s").Should(MatchRegexp(`pvc.+2Gi.+Bound`))
|
||||||
Eventually(func() (string, error) {
|
Eventually(func() (string, error) {
|
||||||
return tests.K3sCmd("kubectl", "get", "pvc")
|
return testutil.K3sCmd("kubectl", "get", "pvc")
|
||||||
}, "10s", "1s").Should(MatchRegexp(`local-path-pvc.+Bound`))
|
}, "10s", "1s").Should(MatchRegexp(`local-path-pvc.+Bound`))
|
||||||
})
|
})
|
||||||
It("has proper folder permissions", func() {
|
It("has proper folder permissions", func() {
|
||||||
|
@ -50,7 +50,7 @@ var _ = Describe("local storage", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(fmt.Sprintf("%04o", fileStat.Mode().Perm())).To(Equal("0701"))
|
Expect(fmt.Sprintf("%04o", fileStat.Mode().Perm())).To(Equal("0701"))
|
||||||
|
|
||||||
pvResult, err := tests.K3sCmd("kubectl", "get", "pv")
|
pvResult, err := testutil.K3sCmd("kubectl", "get", "pv")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
reg, err := regexp.Compile(`pvc[^\s]+`)
|
reg, err := regexp.Compile(`pvc[^\s]+`)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -60,16 +60,16 @@ var _ = Describe("local storage", func() {
|
||||||
Expect(fmt.Sprintf("%04o", fileStat.Mode().Perm())).To(Equal("0777"))
|
Expect(fmt.Sprintf("%04o", fileStat.Mode().Perm())).To(Equal("0777"))
|
||||||
})
|
})
|
||||||
It("deletes properly", func() {
|
It("deletes properly", func() {
|
||||||
Expect(tests.K3sCmd("kubectl", "delete", "pod", "volume-test")).
|
Expect(testutil.K3sCmd("kubectl", "delete", "pod", "volume-test")).
|
||||||
To(ContainSubstring("pod \"volume-test\" deleted"))
|
To(ContainSubstring("pod \"volume-test\" deleted"))
|
||||||
Expect(tests.K3sCmd("kubectl", "delete", "pvc", "local-path-pvc")).
|
Expect(testutil.K3sCmd("kubectl", "delete", "pvc", "local-path-pvc")).
|
||||||
To(ContainSubstring("persistentvolumeclaim \"local-path-pvc\" deleted"))
|
To(ContainSubstring("persistentvolumeclaim \"local-path-pvc\" deleted"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
var _ = AfterSuite(func() {
|
var _ = AfterSuite(func() {
|
||||||
Expect(tests.K3sKillAsync(serverCmd)).To(Succeed())
|
Expect(testutil.K3sKillAsync(serverCmd)).To(Succeed())
|
||||||
})
|
})
|
||||||
|
|
||||||
func Test_IntegrationLocalStorage(t *testing.T) {
|
func Test_IntegrationLocalStorage(t *testing.T) {
|
|
@ -1,4 +1,4 @@
|
||||||
package tests
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
|
@ -1,4 +1,4 @@
|
||||||
package tests
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
Loading…
Reference in New Issue