Skip to content

Commit

Permalink
vendor: Remove gopkg.in/check.v1 dependency
Browse files Browse the repository at this point in the history
Remove gopkg.in/check.v1 dependency in preparation to merge cilium-cli
repo with cilium repo [^1]. Use github.com/stretchr/testify/assert for
assertions instead.

Ref: cilium/design-cfps#9
[^1]: https://github.com/cilium/cilium/blob/cd8f44c0e95f53f6e5cdbd6daffc5e9a3009c8a7/.golangci.yaml#L75

Signed-off-by: Michi Mutsuzaki <[email protected]>
  • Loading branch information
michi-covalent committed Jul 15, 2024
1 parent 9ffcbb4 commit 2ddeb2f
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 2,443 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/spf13/pflag v1.0.6-0.20210604193023-d5e0c0615ace
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8
google.golang.org/grpc v1.65.0
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
helm.sh/helm/v3 v3.15.3
k8s.io/api v0.30.2
k8s.io/apimachinery v0.30.2
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
28 changes: 10 additions & 18 deletions internal/utils/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@ package utils
import (
"testing"

"gopkg.in/check.v1"
"github.com/stretchr/testify/assert"
)

func Test(t *testing.T) {
check.TestingT(t)
}

type UtilsSuite struct{}

var _ = check.Suite(&UtilsSuite{})

type failIfCalled struct {
c *check.C
t *testing.T
}

func (f *failIfCalled) Log(_ string, _ ...interface{}) {
f.c.Error("log method should not be called")
f.t.Error("log method should not be called")
}

type countIfCalled struct {
Expand All @@ -33,17 +25,17 @@ func (c *countIfCalled) Log(_ string, _ ...interface{}) {
c.count++
}

func (b *UtilsSuite) TestExec(c *check.C) {
_, err := Exec(&failIfCalled{c}, "true")
c.Assert(err, check.IsNil)
func TestExec(t *testing.T) {
_, err := Exec(&failIfCalled{t}, "true")
assert.NoError(t, err)

cl := &countIfCalled{0}
_, err = Exec(cl, "false")
c.Assert(err, check.Not(check.IsNil))
c.Assert(cl.count, check.Equals, 1)
assert.Error(t, err)
assert.Equal(t, 1, cl.count)

cl.count = 0
_, err = Exec(cl, "sh", "-c", "'echo foo; exit 1'")
c.Assert(err, check.Not(check.IsNil))
c.Assert(cl.count, check.Equals, 2)
assert.Error(t, err)
assert.Equal(t, 2, cl.count)
}
30 changes: 11 additions & 19 deletions k8s/pipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ import (
"io"
"testing"

"gopkg.in/check.v1"
"github.com/stretchr/testify/assert"
)

func Test(t *testing.T) {
check.TestingT(t)
}

type CopyPipeSuites struct{}

var _ = check.Suite(&CopyPipeSuites{})

type remoteFile struct {
bytes []byte

Expand Down Expand Up @@ -48,7 +40,7 @@ func (r *remoteFile) ReadWithFailure(offset uint64, writer io.Writer) error {

}

func (b *CopyPipeSuites) TestCopyWithoutRetry(c *check.C) {
func TestCopyWithoutRetry(t *testing.T) {
remoteFile := &remoteFile{
bytes: []byte{1, 2, 3},
}
Expand All @@ -59,11 +51,11 @@ func (b *CopyPipeSuites) TestCopyWithoutRetry(c *check.C) {

res := &bytes.Buffer{}
_, err := io.Copy(res, pipe)
c.Assert(err, check.IsNil)
c.Assert(res.Bytes(), check.DeepEquals, remoteFile.bytes)
assert.NoError(t, err)
assert.Equal(t, remoteFile.bytes, res.Bytes())
}

func (b *CopyPipeSuites) TestCopyWithRetry(c *check.C) {
func TestCopyWithRetry(t *testing.T) {
remoteFile := &remoteFile{
bytes: []byte{1, 2, 3},
maxFailures: 2,
Expand All @@ -76,11 +68,11 @@ func (b *CopyPipeSuites) TestCopyWithRetry(c *check.C) {

res := &bytes.Buffer{}
_, err := io.Copy(res, pipe)
c.Assert(err, check.IsNil)
c.Assert(res.Bytes(), check.DeepEquals, remoteFile.bytes)
assert.NoError(t, err)
assert.Equal(t, remoteFile.bytes, res.Bytes())
}

func (b *CopyPipeSuites) TestCopyWithExhaustedRetry(c *check.C) {
func TestCopyWithExhaustedRetry(t *testing.T) {
remoteFile := &remoteFile{
bytes: []byte{1, 2, 3},
maxFailures: 3,
Expand All @@ -93,7 +85,7 @@ func (b *CopyPipeSuites) TestCopyWithExhaustedRetry(c *check.C) {

res := &bytes.Buffer{}
_, err := io.Copy(res, pipe)
c.Assert(err, check.NotNil)
c.Assert(err, check.ErrorMatches, "dropping out copy after 2 retries: unexpected EOF")
c.Assert(res.Bytes(), check.HasLen, 0)
assert.Error(t, err)
assert.Equal(t, err.Error(), "dropping out copy after 2 retries: unexpected EOF")
assert.Empty(t, res.Bytes())
}
108 changes: 50 additions & 58 deletions status/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@ import (
"github.com/cilium/cilium/api/v1/models"
ciliumv2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/go-openapi/strfmt"
"gopkg.in/check.v1"
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cilium/cilium-cli/defaults"
)

func Test(t *testing.T) {
check.TestingT(t)
}

type StatusSuite struct{}

var _ = check.Suite(&StatusSuite{})

var (
fakeParameters = K8sStatusParameters{
Namespace: "kube-system",
Expand Down Expand Up @@ -164,95 +156,95 @@ func (c *k8sStatusMockClient) CiliumDbgEndpoints(_ context.Context, _, _ string)
return nil, nil
}

func (b *StatusSuite) TestMockClient(c *check.C) {
func TestMockClient(t *testing.T) {
client := newK8sStatusMockClient()
c.Assert(client, check.Not(check.IsNil))
assert.NotNil(t, client)
}

func (b *StatusSuite) TestStatus(c *check.C) {
func TestStatus(t *testing.T) {
client := newK8sStatusMockClient()
c.Assert(client, check.Not(check.IsNil))
assert.NotNil(t, client)

collector, err := NewK8sStatusCollector(client, fakeParameters)
c.Assert(err, check.IsNil)
c.Assert(collector, check.Not(check.IsNil))
assert.NoError(t, err)
assert.NotNil(t, collector)

client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 10, 10, 10, 0, 10, 1, 1)
status, err := collector.Status(context.Background())
c.Assert(err, check.IsNil)
c.Assert(status, check.Not(check.IsNil))
c.Assert(status.PodState[defaults.AgentDaemonSetName].Desired, check.Equals, 10)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Ready, check.Equals, 10)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Available, check.Equals, 10)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Unavailable, check.Equals, 0)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)], check.Equals, 10)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)], check.Equals, 0)
c.Assert(len(status.CiliumStatus), check.Equals, 10)
assert.NoError(t, err)
assert.NotNil(t, status)
assert.Equal(t, 10, status.PodState[defaults.AgentDaemonSetName].Desired)
assert.Equal(t, 10, status.PodState[defaults.AgentDaemonSetName].Ready)
assert.Equal(t, 10, status.PodState[defaults.AgentDaemonSetName].Available)
assert.Equal(t, 0, status.PodState[defaults.AgentDaemonSetName].Unavailable)
assert.Equal(t, 10, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)])
assert.Equal(t, 0, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)])
assert.Len(t, status.CiliumStatus, 10)

client.reset()
client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 10, 5, 5, 5, 10, 2, 2)
status, err = collector.Status(context.Background())
c.Assert(err, check.IsNil)
c.Assert(status, check.Not(check.IsNil))
c.Assert(status.PodState[defaults.AgentDaemonSetName].Desired, check.Equals, 10)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Ready, check.Equals, 5)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Available, check.Equals, 5)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Unavailable, check.Equals, 5)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)], check.Equals, 5)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)], check.Equals, 5)
c.Assert(len(status.CiliumStatus), check.Equals, 5)
assert.NoError(t, err)
assert.NotNil(t, status)
assert.Equal(t, 10, status.PodState[defaults.AgentDaemonSetName].Desired)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Ready)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Available)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Unavailable)
assert.Equal(t, 5, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)])
assert.Equal(t, 5, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)])
assert.Len(t, status.CiliumStatus, 5)

client.reset()
client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 10, 5, 5, 5, 10, 3, 3)
delete(client.status, "cilium-2")
status, err = collector.Status(context.Background())
c.Assert(err, check.IsNil)
c.Assert(status, check.Not(check.IsNil))
c.Assert(status.PodState[defaults.AgentDaemonSetName].Desired, check.Equals, 10)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Ready, check.Equals, 5)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Available, check.Equals, 5)
c.Assert(status.PodState[defaults.AgentDaemonSetName].Unavailable, check.Equals, 5)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)], check.Equals, 5)
c.Assert(status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)], check.Equals, 5)
c.Assert(len(status.CiliumStatus), check.Equals, 5)
c.Assert(status.CiliumStatus["cilium-2"], check.IsNil)
assert.NoError(t, err)
assert.NotNil(t, status)
assert.Equal(t, 10, status.PodState[defaults.AgentDaemonSetName].Desired)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Ready)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Available)
assert.Equal(t, 5, status.PodState[defaults.AgentDaemonSetName].Unavailable)
assert.Equal(t, 5, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodRunning)])
assert.Equal(t, 5, status.PhaseCount[defaults.AgentDaemonSetName][string(corev1.PodFailed)])
assert.Len(t, status.CiliumStatus, 5)
assert.Nil(t, status.CiliumStatus["cilium-2"])

client.reset()
// observed generation behind
client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 5, 5, 5, 5, 5, 3, 2)
status, err = collector.Status(context.Background())
c.Assert(err, check.IsNil)
c.Assert(status, check.Not(check.IsNil))
c.Assert(status.Errors["cilium"]["cilium"].Errors, check.HasLen, 1)
c.Assert(status.Errors["cilium"]["cilium"].Errors[0], check.ErrorMatches, ".*rollout has not started.*")
assert.NoError(t, err)
assert.NotNil(t, status)
assert.Len(t, status.Errors["cilium"]["cilium"].Errors, 1)
assert.Regexp(t, ".*rollout has not started.*", status.Errors["cilium"]["cilium"].Errors[0].Error())

client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 5, 5, 5, 5, 1, 3, 3)
status, err = collector.Status(context.Background())
c.Assert(err, check.IsNil)
c.Assert(status, check.Not(check.IsNil))
c.Assert(status.Errors["cilium"]["cilium"].Errors, check.HasLen, 1)
c.Assert(status.Errors["cilium"]["cilium"].Errors[0], check.ErrorMatches, ".*is rolling out.*")
assert.NoError(t, err)
assert.NotNil(t, status)
assert.Len(t, status.Errors["cilium"]["cilium"].Errors, 1)
assert.Regexp(t, ".*is rolling out.*", status.Errors["cilium"]["cilium"].Errors[0].Error())
}

func (b *StatusSuite) TestFormat(c *check.C) {
func TestFormat(t *testing.T) {
client := newK8sStatusMockClient()
c.Assert(client, check.Not(check.IsNil))
assert.NotNil(t, client)

collector, err := NewK8sStatusCollector(client, fakeParameters)
c.Assert(err, check.IsNil)
c.Assert(collector, check.Not(check.IsNil))
assert.NoError(t, err)
assert.NotNil(t, collector)

client.setDaemonSet("kube-system", defaults.AgentDaemonSetName, defaults.AgentPodSelector, 10, 5, 5, 5, 10, 4, 4)
delete(client.status, "cilium-2")

client.addPod("kube-system", "cilium-operator-1", "k8s-app=cilium-operator", []corev1.Container{{Image: "cilium-operator:1.9"}}, corev1.PodStatus{Phase: corev1.PodRunning})

status, err := collector.Status(context.Background())
c.Assert(err, check.IsNil)
assert.NoError(t, err)
buf := status.Format()
c.Assert(buf[len(buf)-1], check.Equals, byte('\n'))
assert.Equal(t, byte('\n'), buf[len(buf)-1])

var nilStatus *Status
buf = nilStatus.Format()
c.Assert(buf, check.Equals, "")
assert.Empty(t, buf)
}
Loading

0 comments on commit 2ddeb2f

Please sign in to comment.