auth

Paddy 2014-09-18 Parent:022ce4262922 Child:fb827644bfd8

43:2a6d722a2b4b Browse Files

Add tests for validating client changes. Test that validating client changes fails when it's supposed to and succeeds when it's supposed to.

client_test.go

     1.1 --- a/client_test.go	Thu Sep 18 22:41:32 2014 -0400
     1.2 +++ b/client_test.go	Thu Sep 18 22:42:02 2014 -0400
     1.3 @@ -351,3 +351,53 @@
     1.4  		}
     1.5  	}
     1.6  }
     1.7 +
     1.8 +func TestClientChangeValidation(t *testing.T) {
     1.9 +	t.Parallel()
    1.10 +	change := ClientChange{}
    1.11 +	if err := change.Validate(); err != ErrEmptyChange {
    1.12 +		t.Errorf("Expected %s to give an error of %s, gave %s", "empty change", ErrEmptyChange, err)
    1.13 +	}
    1.14 +	names := map[string]error{
    1.15 +		"a":   ErrClientNameTooShort,
    1.16 +		"ab":  nil,
    1.17 +		"abc": nil,
    1.18 +		"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopq": ErrClientNameTooLong,
    1.19 +	}
    1.20 +	for name, expectation := range names {
    1.21 +		change = ClientChange{Name: &name}
    1.22 +		if err := change.Validate(); err != expectation {
    1.23 +			t.Errorf("Expected %s to give an error of %s, gave %s", name, expectation, err)
    1.24 +		}
    1.25 +	}
    1.26 +	longPath := ""
    1.27 +	for i := 0; i < 1025; i++ {
    1.28 +		longPath = fmt.Sprintf("%s%d", longPath, i)
    1.29 +	}
    1.30 +	logos := map[string]error{
    1.31 +		"https://www.example.com/" + longPath: ErrClientLogoTooLong,
    1.32 +		"https://www.example.com/ab":          nil,
    1.33 +		"www.example.com/ab":                  ErrClientLogoNotURL,
    1.34 +		"test":                                ErrClientLogoNotURL,
    1.35 +		"":                                    nil,
    1.36 +	}
    1.37 +	for logo, expectation := range logos {
    1.38 +		change = ClientChange{Logo: &logo}
    1.39 +		if err := change.Validate(); err != expectation {
    1.40 +			t.Errorf("Expected %s to give an error of %s, gave %s", logo, expectation, err)
    1.41 +		}
    1.42 +	}
    1.43 +	websites := map[string]error{
    1.44 +		"https://www.example.com/" + longPath: ErrClientWebsiteTooLong,
    1.45 +		"https://www.example.com/ab":          nil,
    1.46 +		"www.example.com/ab":                  ErrClientWebsiteNotURL,
    1.47 +		"test":                                ErrClientWebsiteNotURL,
    1.48 +		"":                                    nil,
    1.49 +	}
    1.50 +	for website, expectation := range websites {
    1.51 +		change = ClientChange{Website: &website}
    1.52 +		if err := change.Validate(); err != expectation {
    1.53 +			t.Errorf("Expected %s to give an error of %s, gave %s", website, expectation, err)
    1.54 +		}
    1.55 +	}
    1.56 +}