versions: consolidate various types of Components

There used to be three definitions of a Component type, and conversion
routines between the three. Since the use case is always the same, and
the Component semantics are defined by versions.go and the installer, it
seems appropriate to define the Component type there and import it in
the necessary places.
This commit is contained in:
Markus Rudy 2023-12-11 08:08:55 +01:00 committed by Markus Rudy
parent a8fb6c5af0
commit a1dbd13f95
25 changed files with 454 additions and 379 deletions

View file

@ -35,7 +35,7 @@ func TestInstall(t *testing.T) {
serverURL := "http://server/path"
testCases := map[string]struct {
server httpBufconnServer
component components.Component
component *components.Component
hash string
destination string
extract bool
@ -44,8 +44,8 @@ func TestInstall(t *testing.T) {
}{
"download works": {
server: newHTTPBufconnServerWithBody([]byte("file-contents")),
component: components.Component{
URL: serverURL,
component: &components.Component{
Url: serverURL,
Hash: "sha256:f03779b36bece74893fd6533a67549675e21573eb0e288d87158738f9c24594e",
InstallPath: "/destination",
},
@ -53,8 +53,8 @@ func TestInstall(t *testing.T) {
},
"download with extract works": {
server: newHTTPBufconnServerWithBody(createTarGz([]byte("file-contents"), "/destination")),
component: components.Component{
URL: serverURL,
component: &components.Component{
Url: serverURL,
Hash: "sha256:a52a1664ca0a6ec9790384e3d058852ab8b3a8f389a9113d150fdc6ab308d949",
InstallPath: "/prefix",
Extract: true,
@ -63,8 +63,8 @@ func TestInstall(t *testing.T) {
},
"hash validation fails": {
server: newHTTPBufconnServerWithBody([]byte("file-contents")),
component: components.Component{
URL: serverURL,
component: &components.Component{
Url: serverURL,
Hash: "sha256:abc",
InstallPath: "/destination",
},
@ -72,8 +72,8 @@ func TestInstall(t *testing.T) {
},
"download fails": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
component: components.Component{
URL: serverURL,
component: &components.Component{
Url: serverURL,
Hash: "sha256:abc",
InstallPath: "/destination",
},