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 test logic what check null string to accounts.parseURL() test codes. #25011

Closed
dbadoy opened this issue Jun 2, 2022 · 1 comment
Closed

Comments

@dbadoy
Copy link
Contributor

dbadoy commented Jun 2, 2022

// go-ethereum/accounts/url.go
func parseURL(url string) (URL, error) {
	parts := strings.Split(url, "://")
	if len(parts) != 2 || parts[0] == "" {
		return URL{}, errors.New("protocol scheme missing")
	}
	return URL{
		Scheme: parts[0],
		Path:   parts[1],
	}, nil
}
// go-ethereum/accounts/url_test.go
func TestURLParsing(t *testing.T) {
	url, err := parseURL("https://ethereum.org")
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}
	if url.Scheme != "https" {
		t.Errorf("expected: %v, got: %v", "https", url.Scheme)
	}
	if url.Path != "ethereum.org" {
		t.Errorf("expected: %v, got: %v", "ethereum.org", url.Path)
	}

	_, err = parseURL("ethereum.org")
	if err == nil {
		t.Error("expected err, got: nil")
	}
}

url_test.go is checking this part,

len(parts) != 2

But, doesn't check this,

parts[0] == ""

I think, it would be nice to add this logic.

// go-ethereum/accounts/url_test.go
func TestURLParsing(t *testing.T) {
	url, err := parseURL("https://ethereum.org")
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}
	if url.Scheme != "https" {
		t.Errorf("expected: %v, got: %v", "https", url.Scheme)
	}
	if url.Path != "ethereum.org" {
		t.Errorf("expected: %v, got: %v", "ethereum.org", url.Path)
	}

	_, err = parseURL("ethereum.org")
	if err == nil {
		t.Error("expected err, got: nil")
	}

        // here
  	_, err = parseURL("")
	if err == nil {
		t.Error("expected err, got: nil")
	}
}

thanks.

@ligi
Copy link
Member

ligi commented Jun 2, 2022

makes sense - can you PR it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
@ligi @holiman @dbadoy and others