Skip to content

Commit

Permalink
chore: add testifylint (#449)
Browse files Browse the repository at this point in the history
Let's use testify more consistently and better! 🌮
  • Loading branch information
jharley authored Mar 1, 2024
1 parent ad6fd97 commit 0f6adc6
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 117 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- predeclared
- staticcheck
- tenv
- testifylint
- unconvert
- unparam
- unused
Expand Down
3 changes: 2 additions & 1 deletion client/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAuthMetadata(t *testing.T) {
Expand All @@ -15,8 +16,8 @@ func TestAuthMetadata(t *testing.T) {
t.Run("List", func(t *testing.T) {
ctx := context.Background()
metadata, err := c.Auth.List(ctx)
require.NoError(t, err)

assert.NoError(t, err)
assert.NotEmpty(t, metadata.APIKeyAccess)
assert.NotEmpty(t, metadata.Team.Name)
assert.NotEmpty(t, metadata.Team.Slug)
Expand Down
19 changes: 9 additions & 10 deletions client/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,30 @@ func TestBoards(t *testing.T) {
},
}
b, err = c.Boards.Create(ctx, data)

assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, b.ID)

// copy ID before asserting equality
data.ID = b.ID
data.Queries[0].QueryID = b.Queries[0].QueryID

// ensure the board URL got populated
assert.NotEqual(t, b.Links.BoardURL, "")
assert.NotEqual(t, "", b.Links.BoardURL)
data.Links.BoardURL = b.Links.BoardURL

assert.Equal(t, data, b)
})

t.Run("List", func(t *testing.T) {
result, err := c.Boards.List(ctx)
require.NoError(t, err)

assert.NoError(t, err)
assert.Contains(t, result, *b, "could not find newly created board with List")
})

t.Run("Get", func(t *testing.T) {
board, err := c.Boards.Get(ctx, b.ID)
assert.NoError(t, err)
require.NoError(t, err)

assert.Equal(t, *b, *board)
})
Expand All @@ -97,7 +96,7 @@ func TestBoards(t *testing.T) {
},
TimeRange: client.ToPtr(client.DefaultQueryTimeRange),
})
assert.NoError(t, err)
require.NoError(t, err)
b.ColumnLayout = client.BoardColumnStyleMulti
b.Queries = append(b.Queries, client.BoardQuery{
Caption: "A second query",
Expand All @@ -107,22 +106,22 @@ func TestBoards(t *testing.T) {
})

result, err := c.Boards.Update(ctx, b)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, b, result)
})

t.Run("Delete", func(t *testing.T) {
err := c.Boards.Delete(ctx, b.ID)

assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Fail to get deleted Board", func(t *testing.T) {
_, err := c.Boards.Get(ctx, b.ID)

var de client.DetailedError
assert.Error(t, err)
assert.ErrorAs(t, err, &de)
require.Error(t, err)
require.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})
}
16 changes: 7 additions & 9 deletions client/burn_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ func TestBurnAlerts(t *testing.T) {
t.Run(fmt.Sprintf("Create: %s", testName), func(t *testing.T) {
data := &testCase.createRequest
burnAlert, err = c.BurnAlerts.Create(ctx, dataset, data)

assert.NoError(t, err, "failed to create BurnAlert")
require.NoError(t, err, "failed to create BurnAlert")
assert.NotNil(t, burnAlert.ID, "BurnAlert ID is empty")
assert.NotNil(t, burnAlert.CreatedAt, "created at is empty")
assert.NotNil(t, burnAlert.UpdatedAt, "updated at is empty")
Expand All @@ -183,7 +182,7 @@ func TestBurnAlerts(t *testing.T) {

t.Run(fmt.Sprintf("Get: %s", testName), func(t *testing.T) {
result, err := c.BurnAlerts.Get(ctx, dataset, burnAlert.ID)
assert.NoError(t, err, "failed to get BurnAlert by ID")
require.NoError(t, err, "failed to get BurnAlert by ID")
assert.Equal(t, burnAlert, result)
})

Expand All @@ -192,8 +191,7 @@ func TestBurnAlerts(t *testing.T) {
data.ID = burnAlert.ID

burnAlert, err = c.BurnAlerts.Update(ctx, dataset, data)

assert.NoError(t, err, "failed to update BurnAlert")
require.NoError(t, err, "failed to update BurnAlert")

// copy dynamic field before asserting equality
data.AlertType = burnAlert.AlertType
Expand All @@ -206,24 +204,24 @@ func TestBurnAlerts(t *testing.T) {

t.Run(fmt.Sprintf("ListForSLO: %s", testName), func(t *testing.T) {
results, err := c.BurnAlerts.ListForSLO(ctx, dataset, slo.ID)
require.NoError(t, err, "failed to list burn alerts for SLO")

assert.NoError(t, err, "failed to list burn alerts for SLO")
assert.NotZero(t, len(results))
assert.Equal(t, burnAlert.ID, results[0].ID, "newly created BurnAlert not in list of SLO's burn alerts")
})

t.Run(fmt.Sprintf("Delete - %s", testName), func(t *testing.T) {
err = c.BurnAlerts.Delete(ctx, dataset, burnAlert.ID)

assert.NoError(t, err, "failed to delete BurnAlert")
require.NoError(t, err, "failed to delete BurnAlert")
})

t.Run(fmt.Sprintf("Fail to GET a deleted burn alert: %s", testName), func(t *testing.T) {
_, err := c.BurnAlerts.Get(ctx, dataset, burnAlert.ID)

var de client.DetailedError
assert.Error(t, err)
assert.ErrorAs(t, err, &de)
require.Error(t, err)
require.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})
}
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestClient_InvalidConfig(t *testing.T) {
APIKey: "123",
APIUrl: "cache_object:foo/bar",
})
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not parse APIUrl")
}

Expand Down
21 changes: 8 additions & 13 deletions client/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ func TestColumns(t *testing.T) {
Type: client.ToPtr(client.ColumnTypeFloat),
}
column, err = c.Columns.Create(ctx, dataset, data)

assert.NoError(t, err)
require.NoError(t, err)

data.ID = column.ID
assert.NotNil(t, column.LastWrittenAt, "last written at is empty")
Expand All @@ -46,22 +45,19 @@ func TestColumns(t *testing.T) {

t.Run("List", func(t *testing.T) {
columns, err := c.Columns.List(ctx, dataset)

assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, columns, *column, "could not find column with List")
})

t.Run("Get", func(t *testing.T) {
result, err := c.Columns.Get(ctx, dataset, column.ID)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, *column, *result)
})

t.Run("GetByKeyName", func(t *testing.T) {
result, err := c.Columns.GetByKeyName(ctx, dataset, column.KeyName)

assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, *column, *result)
})

Expand All @@ -75,8 +71,7 @@ func TestColumns(t *testing.T) {
Type: client.ToPtr(client.ColumnTypeBoolean),
}
column, err = c.Columns.Update(ctx, dataset, data)

assert.NoError(t, err)
require.NoError(t, err)

data.ID = column.ID
assert.Equal(t, column.Description, data.Description)
Expand All @@ -94,15 +89,15 @@ func TestColumns(t *testing.T) {
t.Run("Delete", func(t *testing.T) {
err = c.Columns.Delete(ctx, dataset, column.ID)

assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("Fail to get deleted Column", func(t *testing.T) {
_, err := c.Columns.Get(ctx, dataset, column.ID)

var de client.DetailedError
assert.Error(t, err)
assert.ErrorAs(t, err, &de)
require.Error(t, err)
require.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})
}
Expand Down
18 changes: 9 additions & 9 deletions client/dataset_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func TestDatasetDefinitions(t *testing.T) {

t.Run("Reset and Assert Default state", func(t *testing.T) {
err := c.DatasetDefinitions.ResetAll(ctx, dataset)
assert.NoError(t, err)
require.NoError(t, err)

result, err := c.DatasetDefinitions.Get(ctx, dataset)
assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, definitionDefaults["duration_ms"], result.DurationMs.Name)
assert.Equal(t, "error", result.Error.Name)
assert.Equal(t, "name", result.Name.Name)
Expand All @@ -89,23 +89,23 @@ func TestDatasetDefinitions(t *testing.T) {
Name: &client.DefinitionColumn{Name: testCol.KeyName},
Error: &client.DefinitionColumn{Name: testDC.Alias},
})
assert.NoError(t, err)
require.NoError(t, err)
// refetch to be extra sure that our update took effect
datasetDef, err := c.DatasetDefinitions.Get(ctx, dataset)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, datasetDef.Name.Name, testCol.KeyName)
assert.Equal(t, datasetDef.Name.ColumnType, "column")
assert.Equal(t, "column", datasetDef.Name.ColumnType)
assert.Equal(t, datasetDef.Error.Name, testDC.Alias)
assert.Equal(t, datasetDef.Error.ColumnType, "derived_column")
assert.Equal(t, "derived_column", datasetDef.Error.ColumnType)
})

t.Run("Reset the fields: ensure reverted to default", func(t *testing.T) {
result, err := c.DatasetDefinitions.Update(ctx, dataset, &client.DatasetDefinition{
Name: client.EmptyDatasetDefinition(),
Error: client.EmptyDatasetDefinition(),
})
assert.NoError(t, err)
assert.Equal(t, result.Name.Name, "name")
assert.Equal(t, result.Error.Name, "error")
require.NoError(t, err)
assert.Equal(t, "name", result.Name.Name)
assert.Equal(t, "error", result.Error.Name)
})
}
16 changes: 7 additions & 9 deletions client/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/honeycombio/terraform-provider-honeycombio/client"
)
Expand All @@ -23,8 +24,7 @@ func TestDatasets(t *testing.T) {

t.Run("List", func(t *testing.T) {
d, err := c.Datasets.List(ctx)

assert.NoError(t, err)
require.NoError(t, err)

for _, dataset := range d {
assert.NotNil(t, dataset.LastWrittenAt, "last written at is empty")
Expand All @@ -41,8 +41,7 @@ func TestDatasets(t *testing.T) {

t.Run("Get", func(t *testing.T) {
d, err := c.Datasets.Get(ctx, currentDataset.Slug)

assert.NoError(t, err)
require.NoError(t, err)

assert.NotNil(t, d.LastWrittenAt, "last written at is empty")
assert.NotNil(t, d.CreatedAt, "created at is empty")
Expand All @@ -57,8 +56,8 @@ func TestDatasets(t *testing.T) {
_, err := c.Datasets.Get(ctx, "does-not-exist")

var de client.DetailedError
assert.Error(t, err)
assert.ErrorAs(t, err, &de)
require.Error(t, err)
require.ErrorAs(t, err, &de)
assert.True(t, de.IsNotFound())
})

Expand All @@ -67,8 +66,7 @@ func TestDatasets(t *testing.T) {
Name: datasetName,
}
d, err := c.Datasets.Create(ctx, createDataset)

assert.NoError(t, err)
require.NoError(t, err)

assert.NotNil(t, d.LastWrittenAt, "last written at is empty")
assert.NotNil(t, d.CreatedAt, "created at is empty")
Expand All @@ -94,7 +92,7 @@ func TestDatasets(t *testing.T) {
c.Datasets.Update(ctx, &client.Dataset{Name: datasetName})
})
d, err := c.Datasets.Update(ctx, updateDataset)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, d.Description, updatedDescription)
assert.Equal(t, d.ExpandJSONDepth, updatedExpandJSONDepth)
})
Expand Down
Loading

0 comments on commit 0f6adc6

Please sign in to comment.