hasValidValues() -> has ConnectionValues()

This commit is contained in:
tpltnt 2014-02-16 01:10:08 +01:00
parent 4ba3d1c0d2
commit 4dcf7d03c5
2 changed files with 34 additions and 14 deletions

10
irc.go
View File

@ -389,9 +389,9 @@ func IRC(nick, user string) *Connection {
return irc return irc
} }
// Returns true if all values in struct make // Returns true if all values in struct allow for
// somewhat sense. // establishing a connection.
func (irc *Connection) hasValidValues() bool { func (irc *Connection) hasConnectionValues() bool {
if 0 == len(irc.nick) { if 0 == len(irc.nick) {
return false return false
} }
@ -404,6 +404,10 @@ func (irc *Connection) hasValidValues() bool {
return false return false
} }
if 0 == len(irc.server) {
return false
}
if nil == irc.Log { if nil == irc.Log {
return false return false
} }

View File

@ -163,25 +163,27 @@ func TestIRCemptyUser(t *testing.T) {
} }
func TestHasValidValues0(t *testing.T) { func TestHasConnectionValues0(t *testing.T) {
irccon := IRC("go-eventirc", "go-eventirc") irccon := IRC("go-eventirc", "go-eventirc")
if nil == irccon { if nil == irccon {
t.Error("creating IRC struct failed") t.Error("creating IRC struct failed")
} }
if false == irccon.hasValidValues() { irccon.server = "foo"
if false == irccon.hasConnectionValues() {
t.Error("valid struct not detected as such") t.Error("valid struct not detected as such")
} }
} }
func TestHasValidValues1(t *testing.T) { func TestHasConnectionValues1(t *testing.T) {
irccon := IRC("go-eventirc", "go-eventirc") irccon := IRC("go-eventirc", "go-eventirc")
if nil == irccon { if nil == irccon {
t.Error("creating IRC struct failed") t.Error("creating IRC struct failed")
} }
irccon.server = "foo"
irccon.Version = "" irccon.Version = ""
if irccon.hasValidValues() { if irccon.hasConnectionValues() {
t.Error("empty 'Version' not detected") t.Error("empty 'Version' not detected")
} }
} }
@ -191,33 +193,47 @@ func TestHasValidValues2(t *testing.T) {
if nil == irccon { if nil == irccon {
t.Error("creating IRC struct failed") t.Error("creating IRC struct failed")
} }
irccon.server = "foo"
irccon.nick = "" irccon.nick = ""
if irccon.hasValidValues() { if irccon.hasConnectionValues() {
t.Error("empty 'nick' not detected") t.Error("empty 'nick' not detected")
} }
} }
func TestHasValidValues3(t *testing.T) { func TestHasConnectionValues3(t *testing.T) {
irccon := IRC("go-eventirc", "go-eventirc") irccon := IRC("go-eventirc", "go-eventirc")
if nil == irccon { if nil == irccon {
t.Error("creating IRC struct failed") t.Error("creating IRC struct failed")
} }
irccon.server = "foo"
irccon.user = "" irccon.user = ""
if irccon.hasValidValues() { if irccon.hasConnectionValues() {
t.Error("empty 'user' not detected") t.Error("empty 'user' not detected")
} }
} }
func TestHasValidValues4(t *testing.T) { func TestHasConnectionValues4(t *testing.T) {
irccon := IRC("go-eventirc", "go-eventirc")
if nil == irccon {
t.Error("creating IRC struct failed")
}
irccon.server = "foo"
irccon.Log = nil
if irccon.hasConnectionValues() {
t.Error("nil pointer 'Log' not detected")
}
}
func TestHasConnectionValues5(t *testing.T) {
irccon := IRC("go-eventirc", "go-eventirc") irccon := IRC("go-eventirc", "go-eventirc")
if nil == irccon { if nil == irccon {
t.Error("creating IRC struct failed") t.Error("creating IRC struct failed")
} }
irccon.Log = nil if irccon.hasConnectionValues() {
if irccon.hasValidValues() { t.Error("empty 'server' not detected")
t.Error("nil pointer 'Log' not detected")
} }
} }