Skip to content

Commit

Permalink
pkg/client: Replace gocheck with built-in go test
Browse files Browse the repository at this point in the history
Signed-off-by: Tam Mach <[email protected]>
  • Loading branch information
sayboras committed May 3, 2024
1 parent fca80e9 commit 2112488
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,39 @@ import (
"testing"
"time"

. "github.com/cilium/checkmate"
"github.com/stretchr/testify/require"

"github.com/cilium/cilium/api/v1/models"
)

// Hook up gocheck into the "go test" runner.
type ClientTestSuite struct{}

var _ = Suite(&ClientTestSuite{})

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

func (cs *ClientTestSuite) TestHint(c *C) {
func TestHint(t *testing.T) {
var err error
c.Assert(Hint(err), IsNil)
require.Nil(t, Hint(err))

err = errors.New("foo bar")
c.Assert(Hint(err), ErrorMatches, "foo bar")
require.ErrorContains(t, Hint(err), "foo bar")

err = fmt.Errorf("ayy lmao")
c.Assert(Hint(err), ErrorMatches, "ayy lmao")
require.ErrorContains(t, Hint(err), "ayy lmao")

err = context.DeadlineExceeded
c.Assert(Hint(err), ErrorMatches, "Cilium API client timeout exceeded")
require.ErrorContains(t, Hint(err), "Cilium API client timeout exceeded")

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()

<-ctx.Done()
err = ctx.Err()

c.Assert(Hint(err), ErrorMatches, "Cilium API client timeout exceeded")
require.ErrorContains(t, Hint(err), "Cilium API client timeout exceeded")
}

func (cs *ClientTestSuite) TestClusterReadiness(c *C) {
c.Assert(clusterReadiness(&models.RemoteCluster{Ready: true}), Equals, "ready")
c.Assert(clusterReadiness(&models.RemoteCluster{Ready: false}), Equals, "not-ready")
func TestClusterReadiness(t *testing.T) {
require.Equal(t, "ready", clusterReadiness(&models.RemoteCluster{Ready: true}))
require.Equal(t, "not-ready", clusterReadiness(&models.RemoteCluster{Ready: false}))
}

func (cs *ClientTestSuite) TestNumReadyClusters(c *C) {
c.Assert(NumReadyClusters(nil), Equals, 0)
c.Assert(NumReadyClusters(
[]*models.RemoteCluster{{Ready: true}, {Ready: true}, {Ready: false}},
), Equals, 2)
func TestNumReadyClusters(t *testing.T) {
require.Equal(t, 0, NumReadyClusters(nil))
require.Equal(t, 2, NumReadyClusters([]*models.RemoteCluster{{Ready: true}, {Ready: true}, {Ready: false}}))
}

0 comments on commit 2112488

Please sign in to comment.