Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-senechal committed Dec 21, 2023
1 parent 7a46384 commit e96876e
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 79 deletions.
1 change: 1 addition & 0 deletions int/api/websites/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (h *registryHandler) Handle(_ operations.AllDomainsGetterParams) middleware
//nolint:revive
return utils.NewGoneResponder()

//nolint:govet
results, err := Registry(h.config)
if err != nil {
return operations.NewMyDomainsGetterInternalServerError().
Expand Down
1 change: 1 addition & 0 deletions int/api/websites/my.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (h *domainsHandler) Handle(params operations.MyDomainsGetterParams) middlew
//nolint:revive
return utils.NewGoneResponder()

//nolint:govet
client := node.NewClient(h.config.NodeURL)

myDomainNames, err := my.Domains(*h.config, client, params.Nickname)
Expand Down
1 change: 1 addition & 0 deletions int/api/websites/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (h *websitePrepare) Handle(params operations.WebsiteUploaderPrepareParams)
//nolint:revive
return utils.NewGoneResponder()

//nolint:govet
archive, errorResponse := readAndCheckArchive(params.Zipfile)
if errorResponse != nil {
return errorResponse
Expand Down
1 change: 1 addition & 0 deletions int/api/websites/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (h *websiteUploadHandler) Handle(params operations.WebsiteUploaderUploadPar
//nolint:revive
return utils.NewGoneResponder()

//nolint:govet
archive, errorResponse := readAndCheckArchive(params.Zipfile)
if errorResponse != nil {
return errorResponse
Expand Down
1 change: 1 addition & 0 deletions int/api/websites/uploadMissed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (h *uploadMissedChunkHandler) Handle(params operations.WebsiteUploadMissing
//nolint:revive
return utils.NewGoneResponder()

//nolint:govet
archive, errorResponse := readAndCheckArchive(params.Zipfile)
if errorResponse != nil {
return errorResponse
Expand Down
3 changes: 2 additions & 1 deletion int/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

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

func TestPath_MASSAHOME(t *testing.T) {
Expand All @@ -12,6 +13,6 @@ func TestPath_MASSAHOME(t *testing.T) {
t.Setenv("MASSA_HOME", wantedPath)

path, err := Path()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, wantedPath, path)
}
3 changes: 2 additions & 1 deletion int/configuration/configuration_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"testing"

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

func TestPath_Unix(t *testing.T) {
path, err := Path()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, "/usr/local/share/massastation", path)
}
2 changes: 1 addition & 1 deletion int/configuration/configuration_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func TestPath_Windows(t *testing.T) {
expectedPath = filepath.Dir(expectedPath)

path, err := Path()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expectedPath, path)
}
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"embed"

"flag"
"fmt"
"log"
Expand All @@ -21,6 +20,7 @@ import (
)

//go:embed all:web/massastation/dist
//nolint:nolintlint,typecheck
var assets embed.FS

type StartFlags struct {
Expand Down Expand Up @@ -97,13 +97,13 @@ func main() {
// Create application with options
err = wails.Run(&options.App{
Title: "Massa Station",
Width: 1280,
Height: 720,
Width: 1280, //nolint:gomnd
Height: 720, //nolint:gomnd
AssetServer: &assetserver.Options{
Assets: assets,
},
OnStartup: func(ctx context.Context) {
server.Start(networkManager, pluginManager)
server.Start(networkManager, pluginManager) //nolint:contextcheck
err := pluginManager.RunAll()
if err != nil {
logger.Fatalf("while running all plugins: %w", err)
Expand All @@ -116,6 +116,6 @@ func main() {
})

if err != nil {
println("Error:", err.Error())
logger.Errorf("error while running wails: %s", err.Error())
}
}
14 changes: 7 additions & 7 deletions pkg/certificate/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package certificate
import (
"testing"

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

func TestReadFile(t *testing.T) {
Expand All @@ -21,9 +21,9 @@ func TestReadFile(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
_, err := readFile(tt.filepath)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand All @@ -45,9 +45,9 @@ func TestLoadCertificate(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
_, err := LoadCertificate(tt.filepath)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand All @@ -69,9 +69,9 @@ func TestLoadPrivateKey(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
_, err := LoadPrivateKey(tt.filepath)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/certificate/pem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package certificate
import (
"testing"

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

const (
Expand Down Expand Up @@ -48,9 +48,9 @@ func TestDecodePEM(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
_, err := DecodePEM([]byte(tt.data))
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand Down Expand Up @@ -105,9 +105,9 @@ func TestDecodeExpectedPEM(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
_, err := DecodeExpectedPEM([]byte(tt.data), tt.expected)
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestPemTypeIsValid(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.p.IsValid())
require.Equal(t, tt.want, tt.p.IsValid())
})
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestPemTypeString(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.p.String())
require.Equal(t, tt.want, tt.p.String())
})
}
}
Expand Down Expand Up @@ -250,12 +250,12 @@ func TestNewPemType(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
got, err := NewPemType(test.args.str)
if test.wantErr {
assert.Error(t, err)
require.Error(t, err)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}

assert.Equal(t, test.want, got)
require.Equal(t, test.want, got)
})
}
}
4 changes: 2 additions & 2 deletions pkg/certificate/store/store_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/massalabs/station/pkg/certificate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestManualCheck(t *testing.T) {
Expand All @@ -25,5 +25,5 @@ func TestManualCheck(t *testing.T) {
}

err = Add(cert)
assert.NoError(t, err)
require.NoError(t, err)
}
50 changes: 25 additions & 25 deletions pkg/certstore/store_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func TestCertStore_AddCertificate(t *testing.T) {
err := store.AddCertificate(cert)

if tt.wantErr != nil {
assert.Error(t, err)
assert.ErrorIs(t, err, tt.wantErr)
require.Error(t, err)
require.ErrorIs(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand Down Expand Up @@ -190,10 +190,10 @@ func TestCertStore_RemoveCertificate(t *testing.T) {
err := store.RemoveCertificate(cert)

if tt.wantErr != nil {
assert.Error(t, err)
assert.ErrorIs(t, err, tt.wantErr)
require.Error(t, err)
require.ErrorIs(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
require.NoError(t, err)
}
})
}
Expand Down Expand Up @@ -281,10 +281,10 @@ func TestCertStore_FetchCertificates(t *testing.T) {
certPool, err := store.FetchCertificates()

if tt.wantErr != nil {
assert.Error(t, err)
assert.ErrorIs(t, err, tt.wantErr)
require.Error(t, err)
require.ErrorIs(t, err, tt.wantErr)
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.Len(t, certPool.Subjects(), tt.poolLength)
}
})
Expand All @@ -304,7 +304,7 @@ func TestCertStore_Close(t *testing.T) {
}

err := store.Close(false)
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("checkNonFreedCtx is true", func(t *testing.T) {
Expand All @@ -316,7 +316,7 @@ func TestCertStore_Close(t *testing.T) {
mockAPI.EXPECT().CertCloseStore(windows.Handle(1), uint32(windows.CERT_CLOSE_STORE_CHECK_FLAG)).Return(nil)

err := store.Close(true)
assert.NoError(t, err)
require.NoError(t, err)
})

t.Run("checkNonFreedCtx is false", func(t *testing.T) {
Expand All @@ -328,7 +328,7 @@ func TestCertStore_Close(t *testing.T) {
mockAPI.EXPECT().CertCloseStore(windows.Handle(1), uint32(0)).Return(nil)

err := store.Close(false)
assert.NoError(t, err)
require.NoError(t, err)
})
}

Expand All @@ -342,7 +342,7 @@ func TestNewCertStore(t *testing.T) {
mockAPI.EXPECT().UTF16PtrFromString("testStore").Return(nil, errors.New("conversion error"))

_, err := NewCertStore(mockAPI, "testStore")
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "unable to convert store name to UTF16")
})

Expand All @@ -351,7 +351,7 @@ func TestNewCertStore(t *testing.T) {
mockAPI.EXPECT().CertOpenSystemStore(windows.Handle(0), gomock.Any()).Return(windows.Handle(0), errors.New("store opening error"))

_, err := NewCertStore(mockAPI, "testStore")
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "unable to open system certificate store")
})

Expand All @@ -360,7 +360,7 @@ func TestNewCertStore(t *testing.T) {
mockAPI.EXPECT().CertOpenSystemStore(windows.Handle(0), gomock.Any()).Return(windows.Handle(1), nil)

store, err := NewCertStore(mockAPI, "testStore")
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, store)
assert.Equal(t, windows.Handle(1), store.handler)
})
Expand Down Expand Up @@ -417,13 +417,13 @@ func TestInterpretError(t *testing.T) {
if tc.expected != nil {
// shall match
// the expected error
assert.ErrorIs(t, actual, tc.expected)
require.ErrorIs(t, actual, tc.expected)
// the initial error
assert.ErrorAs(t, actual, &tc.err)
require.ErrorAs(t, actual, &tc.err)
// the expected error string
assert.EqualError(t, actual, tc.errStr)
} else {
assert.NoError(t, actual)
require.NoError(t, actual)
}
})
}
Expand All @@ -436,32 +436,32 @@ func TestManualCheck(t *testing.T) {

// Initialize the certificate store.
store, err := NewCertStore(NewWindowsImpl(), RootStore)
assert.NoError(t, err)
require.NoError(t, err)

// Add the certificate to the store.
err = store.AddCertificate(cert)
assert.NoError(t, err)
require.NoError(t, err)

// Check that the added certificate is in the list.
pool, err := store.FetchCertificates()
assert.NoError(t, err)
require.NoError(t, err)
assert.True(t, certInPool(cert, pool))

// Delete the added certificate.
err = store.RemoveCertificate(cert)
assert.NoError(t, err)
require.NoError(t, err)

// Check that the deleted certificate is no longer in the list.
pool, err = store.FetchCertificates()
assert.NoError(t, err)
require.NoError(t, err)
assert.False(t, certInPool(cert, pool))

// Delete a non existing certificate and verify that there is an error.
err = store.RemoveCertificate(cert)
assert.Error(t, err)
require.Error(t, err)

// Close the store checking for non freed context.
// This is needed to avoid memory leaks.
err = store.Close(true)
assert.NoError(t, err)
require.NoError(t, err)
}
Loading

0 comments on commit e96876e

Please sign in to comment.