Skip to content

Commit

Permalink
add ubuntu server bypass error case for invalid registry urls
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Valdron <[email protected]>
  • Loading branch information
michael-valdron committed Jun 11, 2024
1 parent 33f2bee commit 73e917f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/devfile/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import (
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -4705,6 +4707,34 @@ func Test_parseFromRegistry(t *testing.T) {
resourceDownloadErr := "failed to pull stack from registry .*"
badDevfileErr := "error parsing devfile because of non-compliant data"

// set invalidRegistryURLErr to expect server misbehaving
// if distribution is Ubuntu Server
if runtime.GOOS == "linux" {
cmd := exec.Command("lsb_release", "-a")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
t.Errorf("Test_parseFromRegistry() unexpected error while fetching distribution: %v", stderr.String())
return
}

lsbrelease := stdout.String()
if strings.Contains(lsbrelease, "Ubuntu") {
cmd := exec.Command("dpkg", "-l", "ubuntu-desktop")
cmd.Stderr = &stderr

// This command will fail if Ubuntu Server
if err := cmd.Run(); err != nil && !strings.Contains(stderr.String(), "dpkg-query: no packages found matching ubuntu-desktop") {
t.Errorf("Test_parseFromRegistry() unexpected error while fetching distribution: %v", stderr.String())
return
} else if err != nil {
invalidRegistryURLErr = "Get .* dial tcp: lookup http on .*: server misbehaving"
}
}
}

testServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var data []byte
var err error
Expand Down

0 comments on commit 73e917f

Please sign in to comment.