mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-04 23:35:11 -04:00
dev-docs: Go package docs (#958)
* Remove unused package * Add Go package docs to most packages Signed-off-by: Daniel Weiße <dw@edgeless.systems> Signed-off-by: Fabian Kammel <fk@edgeless.systems> Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> Co-authored-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> Co-authored-by: Fabian Kammel <fk@edgeless.systems>
This commit is contained in:
parent
b7740723ac
commit
690b50b29d
118 changed files with 735 additions and 750 deletions
105
upgrade-agent/internal/server/server_test.go
Normal file
105
upgrade-agent/internal/server/server_test.go
Normal file
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/versions/components"
|
||||
"github.com/edgelesssys/constellation/v2/upgrade-agent/upgradeproto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestVersionVerifier(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
versionString string
|
||||
wantErr bool
|
||||
}{
|
||||
"valid version": {
|
||||
versionString: "v1.1.1",
|
||||
},
|
||||
"v prefix missing": {
|
||||
versionString: "1.1.1",
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid space": {
|
||||
versionString: "v 1.1.1",
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid version": {
|
||||
versionString: "v1.1.1a",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
err := verifyVersion(tc.versionString)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareUpdate(t *testing.T) {
|
||||
validUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
|
||||
WantedKubernetesVersion: "v1.1.1",
|
||||
}
|
||||
testCases := map[string]struct {
|
||||
installer osInstaller
|
||||
updateRequest *upgradeproto.ExecuteUpdateRequest
|
||||
wantErr bool
|
||||
}{
|
||||
"works": {
|
||||
installer: stubOsInstaller{},
|
||||
updateRequest: validUpdateRequest,
|
||||
},
|
||||
"invalid version string": {
|
||||
installer: stubOsInstaller{},
|
||||
updateRequest: &upgradeproto.ExecuteUpdateRequest{WantedKubernetesVersion: "1337"},
|
||||
wantErr: true,
|
||||
},
|
||||
"install error": {
|
||||
installer: stubOsInstaller{InstallErr: fmt.Errorf("install error")},
|
||||
updateRequest: validUpdateRequest,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
err := prepareUpdate(context.Background(), tc.installer, tc.updateRequest)
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type stubOsInstaller struct {
|
||||
InstallErr error
|
||||
}
|
||||
|
||||
func (s stubOsInstaller) Install(ctx context.Context, kubernetesComponent components.Component) error {
|
||||
return s.InstallErr
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue