Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ubuntu server bypass error case for invalid registry urls #217

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading