Skip to content

Commit

Permalink
Fix new linter issues. (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Oct 31, 2023
1 parent 9b9d801 commit 6ea0044
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
args: --build-tags integration -p bugs -p unused --timeout=5m
args: --build-tags integration -p bugs -p unused -D protogetter --timeout=5m

- name: Make tag
run: |
Expand All @@ -53,7 +53,7 @@ jobs:
make release
- name: Push image
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
14 changes: 7 additions & 7 deletions cmd/metal-api/internal/datastore/image_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type imageTestable struct{}
Expand Down Expand Up @@ -61,7 +61,7 @@ func (_ *imageTestable) search(q *ImageSearchQuery) ([]*metal.Image, error) { //
func TestRethinkStore_FindImage(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []findTest[*metal.Image, *ImageSearchQuery]{
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestRethinkStore_FindImage(t *testing.T) {
func TestRethinkStore_SearchImages(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []searchTest[*metal.Image, *ImageSearchQuery]{
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestRethinkStore_SearchImages(t *testing.T) {
func TestRethinkStore_ListImages(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []listTest[*metal.Image, *ImageSearchQuery]{
Expand All @@ -254,7 +254,7 @@ func TestRethinkStore_ListImages(t *testing.T) {
func TestRethinkStore_CreateImage(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []createTest[*metal.Image, *ImageSearchQuery]{
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestRethinkStore_CreateImage(t *testing.T) {
func TestRethinkStore_DeleteImage(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []deleteTest[*metal.Image, *ImageSearchQuery]{
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestRethinkStore_DeleteImage(t *testing.T) {
func TestRethinkStore_UpdateImage(t *testing.T) {
tt := &imageTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []updateTest[*metal.Image, *ImageSearchQuery]{
Expand Down
7 changes: 4 additions & 3 deletions cmd/metal-api/internal/datastore/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/metal-stack/metal-api/cmd/metal-api/internal/testdata"
"github.com/metal-stack/metal-api/cmd/metal-api/internal/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_getMostRecentImageFor(t *testing.T) {
Expand Down Expand Up @@ -282,15 +283,15 @@ func Test_sortImages(t *testing.T) {

func TestSemver(t *testing.T) {
c, err := semver.NewConstraint("~1")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, c)
v, err := semver.NewVersion("1.99.99")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, v)
satisfies := c.Check(v)
assert.True(t, satisfies)
v, err = semver.StrictNewVersion("19.01")
assert.Error(t, err)
require.Error(t, err)
assert.Nil(t, v)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/datastore/integer_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRethinkStore_AcquireRandomUniqueIntegerIntegration(t *testing.T) {

pool := rs.GetVRFPool()
got, err := pool.AcquireRandomUniqueInteger()
assert.NoError(t, err)
require.NoError(t, err)
assert.GreaterOrEqual(t, got, uint(rs.VRFPoolRangeMin))
assert.LessOrEqual(t, got, uint(rs.VRFPoolRangeMax))
}
Expand All @@ -64,7 +64,7 @@ func TestRethinkStore_AcquireUniqueIntegerTwiceIntegration(t *testing.T) {
pool := rs.GetVRFPool()
got, err := pool.AcquireUniqueInteger(10000)
require.NoError(t, err)
assert.Equal(t, got, uint(10000))
assert.Equal(t, uint(10000), got)

_, err = pool.AcquireUniqueInteger(10000)
assert.True(t, metal.IsConflict(err))
Expand Down
15 changes: 8 additions & 7 deletions cmd/metal-api/internal/datastore/integer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"

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

r "gopkg.in/rethinkdb/rethinkdb-go.v6"
)
Expand Down Expand Up @@ -98,9 +99,9 @@ func TestRethinkStore_ReleaseUniqueInteger(t *testing.T) {

got := ip.ReleaseUniqueInteger(tt.value)
if tt.err != nil {
assert.EqualError(t, got, tt.err.Error())
require.EqualError(t, got, tt.err.Error())
} else {
assert.NoError(t, got)
require.NoError(t, got)
}

if tt.requiresMock {
Expand All @@ -118,7 +119,7 @@ func TestRethinkStore_AcquireRandomUniqueInteger(t *testing.T) {
DeleteOpts{ReturnChanges: true})).Return(r.WriteResponse{Changes: changes}, nil)

got, err := ip.AcquireRandomUniqueInteger()
assert.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, rs.VRFPoolRangeMin, got)

mock.AssertExpectations(t)
Expand Down Expand Up @@ -160,9 +161,9 @@ func TestRethinkStore_AcquireUniqueInteger(t *testing.T) {

got, err := ip.AcquireUniqueInteger(tt.value)
if tt.err != nil {
assert.EqualError(t, err, tt.err.Error())
require.EqualError(t, err, tt.err.Error())
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, tt.value, got)
}

Expand Down Expand Up @@ -234,9 +235,9 @@ func TestRethinkStore_genericAcquire(t *testing.T) {

got, err := ip.genericAcquire(&term)
if tt.expectedErr != nil {
assert.EqualError(t, err, tt.expectedErr.Error())
require.EqualError(t, err, tt.expectedErr.Error())
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, tt.value, got)
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/metal-api/internal/datastore/machine_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type machineTestable struct{}
Expand Down Expand Up @@ -111,7 +111,7 @@ func (_ *machineTestable) defaultBody(m *metal.Machine) *metal.Machine {
func TestRethinkStore_FindMachine(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []findTest[*metal.Machine, *MachineSearchQuery]{
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestRethinkStore_FindMachine(t *testing.T) {
func TestRethinkStore_SearchMachines(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []searchTest[*metal.Machine, *MachineSearchQuery]{
Expand Down Expand Up @@ -827,7 +827,7 @@ func TestRethinkStore_SearchMachines(t *testing.T) {
func TestRethinkStore_ListMachines(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []listTest[*metal.Machine, *MachineSearchQuery]{
Expand All @@ -853,7 +853,7 @@ func TestRethinkStore_ListMachines(t *testing.T) {
func TestRethinkStore_CreateMachine(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []createTest[*metal.Machine, *MachineSearchQuery]{
Expand All @@ -879,7 +879,7 @@ func TestRethinkStore_CreateMachine(t *testing.T) {
func TestRethinkStore_DeleteMachine(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []deleteTest[*metal.Machine, *MachineSearchQuery]{
Expand Down Expand Up @@ -919,7 +919,7 @@ func TestRethinkStore_DeleteMachine(t *testing.T) {
func TestRethinkStore_UpdateMachine(t *testing.T) {
tt := &machineTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []updateTest[*metal.Machine, *MachineSearchQuery]{
Expand Down
14 changes: 7 additions & 7 deletions cmd/metal-api/internal/datastore/switch_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/metal-stack/metal-api/cmd/metal-api/internal/metal"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type switchTestable struct{}
Expand Down Expand Up @@ -66,7 +66,7 @@ func (_ *switchTestable) defaultBody(m *metal.Switch) *metal.Switch {
func TestRethinkStore_FindSwitch(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []findTest[*metal.Switch, *SwitchSearchQuery]{
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestRethinkStore_FindSwitch(t *testing.T) {
func TestRethinkStore_SearchSwitches(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []searchTest[*metal.Switch, *SwitchSearchQuery]{
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRethinkStore_SearchSwitches(t *testing.T) {
func TestRethinkStore_ListSwitches(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []listTest[*metal.Switch, *SwitchSearchQuery]{
Expand All @@ -226,7 +226,7 @@ func TestRethinkStore_ListSwitches(t *testing.T) {
func TestRethinkStore_CreateSwitch(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []createTest[*metal.Switch, *SwitchSearchQuery]{
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestRethinkStore_CreateSwitch(t *testing.T) {
func TestRethinkStore_DeleteSwitch(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []deleteTest[*metal.Switch, *SwitchSearchQuery]{
Expand Down Expand Up @@ -294,7 +294,7 @@ func TestRethinkStore_DeleteSwitch(t *testing.T) {
func TestRethinkStore_UpdateSwitch(t *testing.T) {
tt := &switchTestable{}
defer func() {
assert.NoError(t, tt.wipe())
require.NoError(t, tt.wipe())
}()

tests := []updateTest[*metal.Switch, *SwitchSearchQuery]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ func TestWaitServer(t *testing.T) {
mm := [][]int{{10, 7}}
for _, a := range aa {
for _, m := range mm {
require.True(t, a > 0)
require.True(t, m[0] > 0)
require.True(t, m[1] > 0)
require.True(t, m[0] >= m[1])
require.Greater(t, a, 0)
require.Greater(t, m[0], 0)
require.Greater(t, m[1], 0)
require.GreaterOrEqual(t, m[0], m[1])
tt = append(tt, &test{
numberApiInstances: a,
numberMachineInstances: m[0],
Expand Down Expand Up @@ -140,7 +140,7 @@ func (t *test) run() {
t.startMachineInstances()
t.notReadyMachines.Wait()

require.Equal(t, t.numberMachineInstances, len(wait))
require.Len(t, wait, t.numberMachineInstances)
for _, wait := range wait {
require.True(t, wait)
}
Expand All @@ -159,7 +159,7 @@ func (t *test) run() {
t.notReadyMachines.Wait()
}

require.Equal(t, t.numberMachineInstances, len(wait))
require.Len(t, wait, t.numberMachineInstances)
for _, wait := range wait {
require.True(t, wait)
}
Expand All @@ -168,12 +168,12 @@ func (t *test) run() {

t.unallocatedMachines.Wait()

require.Equal(t, t.numberAllocations, len(t.allocations))
require.Len(t, t.allocations, t.numberAllocations)
for _, allocated := range t.allocations {
require.True(t, allocated)
}

require.Equal(t, t.numberMachineInstances, len(wait))
require.Len(t, wait, t.numberMachineInstances)
for key, wait := range wait {
require.Equal(t, !containsKey(t.allocations, key), wait)
}
Expand Down
Loading

0 comments on commit 6ea0044

Please sign in to comment.