Skip to content

Commit 0f4adc4

Browse files
add ubuntu server bypass error case for invalid registry urls
Signed-off-by: Michael Valdron <[email protected]>
1 parent 33f2bee commit 0f4adc4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pkg/devfile/parser/parse_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import (
2323
"net/http"
2424
"net/http/httptest"
2525
"os"
26+
"os/exec"
2627
"path"
2728
"path/filepath"
2829
"reflect"
30+
"runtime"
2931
"strings"
3032
"testing"
3133

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

4710+
// set invalidRegistryURLErr to expect server misbehaving
4711+
// if distribution is Ubuntu Server
4712+
if runtime.GOOS == "linux" {
4713+
cmd := exec.Command("lsb_release", "-a")
4714+
var stdout, stderr bytes.Buffer
4715+
cmd.Stdout = &stdout
4716+
cmd.Stderr = &stderr
4717+
4718+
if err := cmd.Run(); err != nil {
4719+
t.Errorf("Test_parseFromRegistry() unexpected error while fetching distribution: %v", stderr.String())
4720+
return
4721+
}
4722+
4723+
lsbrelease := stdout.String()
4724+
if strings.Contains(lsbrelease, "Ubuntu") {
4725+
cmd := exec.Command("dpkg", "-l", "ubuntu-desktop")
4726+
cmd.Stderr = &stderr
4727+
4728+
// This command will fail if Ubuntu Server
4729+
if err := cmd.Run(); err != nil && !strings.Contains(stderr.String(), "dpkg-query: no packages found matching ubuntu-desktop") {
4730+
t.Errorf("Test_parseFromRegistry() unexpected error while fetching distribution: %v", stderr.String())
4731+
return
4732+
} else if err != nil {
4733+
invalidRegistryURLErr += "|Get .* dial tcp: lookup http on .*: server misbehaving"
4734+
}
4735+
}
4736+
}
4737+
47084738
testServer := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
47094739
var data []byte
47104740
var err error

0 commit comments

Comments
 (0)