source [file join \
            [file dirname [file dirname [file join [pwd] [info script]]]] \
            devtools testutilities.tcl]

testsNeedTcl  8.2
testsNeedTcltest 2.0

# uri and base64

testing {
    useLocal autoproxy.tcl autoproxy
}

# Clear the autoproxy package state for each test
proc packageReset {} {
    array set ::autoproxy::options {
        authProc "" basic "" no_proxy "" proxy_host "" proxy_port ""
    }
}

test autoproxy-1.0.0 "autoproxy::init standard" -setup {
    packageReset
} -body {
    autoproxy::init http://localhost:13128 "hosta,hostb"
    list [autoproxy::cget -host] \
        [autoproxy::cget -port] \
        [autoproxy::cget -no_proxy]
} -result {localhost 13128 {hosta hostb}}

test autoproxy-1.0.1 "autoproxy::init standard, auth" -setup {
    packageReset
} -body {
    autoproxy::init http://user:secret@localhost:13128 "hosta,hostb"
    list [autoproxy::cget -host] \
        [autoproxy::cget -port] \
        [autoproxy::cget -no_proxy] \
        [base64::decode [lindex [autoproxy::cget -basic] 1 1]]
} -result {localhost 13128 {hosta hostb} user:secret}

test autoproxy-1.0.2 "autoproxy::init standard, override" -setup {
    packageReset
} -body {
    autoproxy::init http://proxyone:13128 "hosta,hostb"
    autoproxy::init http://proxytwo:13129 "hostc,hostd"
    list [autoproxy::cget -host] \
        [autoproxy::cget -port] \
        [autoproxy::cget -no_proxy]
} -result {proxytwo 13129 {hostc hostd}}

test autoproxy-1.0.3 "autoproxy::init standard, auth, override" -setup {
    packageReset
} -body {
    autoproxy::init http://user:secret@localhost:13128 "hosta,hostb"
    autoproxy::init http://luser:passwd@proxy:13129 "hostc,hostd"
    list [autoproxy::cget -host] \
        [autoproxy::cget -port] \
        [autoproxy::cget -no_proxy] \
        [base64::decode [lindex [autoproxy::cget -basic] 1 1]]
} -result {proxy 13129 {hostc hostd} luser:passwd}

test autoproxy-1.0.4 "autoproxy::init standard, colons" -setup {
    packageReset
} -body {
    autoproxy::init http://localhost:13128 "hosta;hostb"
    list [autoproxy::cget -host] \
        [autoproxy::cget -port] \
        [autoproxy::cget -no_proxy]
} -result {localhost 13128 {hosta hostb}}

test autoproxy-1.1.0 "autoproxy::configure -host" -setup {
    packageReset
} -body {
    autoproxy::configure -host proxyhost
    autoproxy::cget -host
} -result {proxyhost}

test autoproxy-1.1.1 "autoproxy::configure -port" -setup {
    packageReset
} -body {
    autoproxy::configure -port 3128
    autoproxy::cget -port
} -result {3128}

test autoproxy-1.1.2 "autoproxy::configure -proxy_host" -setup {
    packageReset
} -body {
    autoproxy::configure -proxy_host proxyhost
    autoproxy::cget -proxy_host
} -result {proxyhost}

test autoproxy-1.1.3 "autoproxy::configure -proxy_port" -setup {
    packageReset
} -body {
    autoproxy::configure -proxy_port 3128
    autoproxy::cget -proxy_port
} -result {3128}

test autoproxy-1.1.4 "autoproxy::configure -no_proxy" -setup {
    packageReset
} -body {
    autoproxy::configure -no_proxy "localhost otherhost"
    autoproxy::cget -no_proxy
} -result {localhost otherhost}

test autoproxy-1.1.5 "autoproxy::configure -no_proxy override" -setup {
    packageReset
} -body {
    autoproxy::configure -no_proxy "localhost otherhost"
    autoproxy::configure -no_proxy "althost"
    autoproxy::cget -no_proxy
} -result {althost}

test autoproxy-1.1.6 "autoproxy::configure -authProc" -setup {
    packageReset
} -body {
    autoproxy::configure -authProc my_auth_proc
    autoproxy::cget -authProc
} -result {my_auth_proc}

test autoproxy-1.2.0 "autoproxy::configure -basic set details" -setup {
    packageReset
} -body {
    autoproxy::configure -basic -user test -password secret -realm tcllib
    autoproxy::cget -basic
} -result {Proxy-Authorization {Basic dGVzdDpzZWNyZXQ=}}

test autoproxy-1.2.1 "autoproxy::configure -basic confirm encoding" -setup {
    packageReset
} -body {
    autoproxy::configure -basic -user test -password secret -realm tcllib
    base64::decode [lindex [autoproxy::cget -basic] 1 1]
} -result {test:secret}

test autoproxy-1.2.2 "autoproxy::configure -basic reset" -setup {
    packageReset
    autoproxy::configure -basic -user test -password secret -realm tcllib
} -body {
    autoproxy::configure -basic --
    autoproxy::cget -basic
} -result {}

test autoproxy-1.2.3 "autoproxy::configure -basic reset (2)" -setup {
    packageReset
    autoproxy::configure -basic -user test -password secret -realm tcllib
} -body {
    autoproxy::configure -basic
    autoproxy::cget -basic
} -result {}

testsuiteCleanup

# Local variables:
#   mode: tcl
#   indent-tabs-mode: nil
# End:
