mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-05 15:55:24 -04:00
api: restructure api pkg (#1851)
* api: rename AttestationVersionRepo to Client * api: move client into separate subpkg for clearer import paths. * api: rename configapi -> attestationconfig * api: rename versionsapi -> versions * api: rename sut to client * api: split versionsapi client and make it public * api: split versionapi fetcher and make it public * config: move attestationversion type to config * api: fix attestationconfig client test Co-authored-by: Adrian Stobbe <stobbe.adrian@gmail.com>
This commit is contained in:
parent
289665eb22
commit
30f2b332b3
105 changed files with 1042 additions and 916 deletions
|
@ -1,221 +0,0 @@
|
|||
/*
|
||||
Copyright (c) Edgeless Systems GmbH
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package versionsapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCLIInfoJSONPath(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
info CLIInfo
|
||||
wantPath string
|
||||
}{
|
||||
"cli info": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/test-ref/stream/nightly/v1.0.0/cli/info.json",
|
||||
},
|
||||
"cli info release": {
|
||||
info: CLIInfo{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantPath: constants.CDNAPIPrefix + "/ref/-/stream/stable/v1.0.0/cli/info.json",
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.wantPath, tc.info.JSONPath())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLIInfoURL(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
info CLIInfo
|
||||
wantURL string
|
||||
wantPath string
|
||||
}{
|
||||
"cli info": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantURL: constants.CDNRepositoryURL + "/" + constants.CDNAPIPrefix + "/ref/test-ref/stream/nightly/v1.0.0/cli/info.json",
|
||||
},
|
||||
"cli info release": {
|
||||
info: CLIInfo{
|
||||
Ref: ReleaseRef,
|
||||
Stream: "stable",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantURL: constants.CDNRepositoryURL + "/" + constants.CDNAPIPrefix + "/ref/-/stream/stable/v1.0.0/cli/info.json",
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
url, err := tc.info.URL()
|
||||
assert.NoError(err)
|
||||
assert.Equal(tc.wantURL, url)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLIInfoValidate(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
info CLIInfo
|
||||
wantErr bool
|
||||
}{
|
||||
"valid cli info": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
},
|
||||
"invalid ref": {
|
||||
info: CLIInfo{
|
||||
Ref: "",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid stream": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "",
|
||||
Version: "v1.0.0",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid version": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid k8s versions": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
Kubernetes: []string{"1", "", "1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"multiple errors": {
|
||||
info: CLIInfo{
|
||||
Ref: "",
|
||||
Stream: "",
|
||||
Version: "",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
err := tc.info.Validate()
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLIInfoValidateRequest(t *testing.T) {
|
||||
testCases := map[string]struct {
|
||||
info CLIInfo
|
||||
wantErr bool
|
||||
}{
|
||||
"valid cli info": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
},
|
||||
"invalid ref": {
|
||||
info: CLIInfo{
|
||||
Ref: "",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid stream": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "",
|
||||
Version: "v1.0.0",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid version": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"invalid k8s versions": {
|
||||
info: CLIInfo{
|
||||
Ref: "test-ref",
|
||||
Stream: "nightly",
|
||||
Version: "v1.0.0",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
"multiple errors": {
|
||||
info: CLIInfo{
|
||||
Ref: "",
|
||||
Stream: "",
|
||||
Version: "",
|
||||
Kubernetes: []string{"v1.26.1", "v1.3.3", "v1.32"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for name, tc := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
err := tc.info.ValidateRequest()
|
||||
|
||||
if tc.wantErr {
|
||||
assert.Error(err)
|
||||
} else {
|
||||
assert.NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue