You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
10 years ago
|
package moon
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestArgs(t *testing.T) {
|
||
|
var one struct {
|
||
|
Host string `name: host; short: h; default: localhost`
|
||
|
Port int `name: port; short: p; required: true`
|
||
10 years ago
|
User string `name: user; short: u`
|
||
|
ZipIt bool `name: zip; short: z`
|
||
|
Verbose bool `name: verbose; short: v`
|
||
10 years ago
|
UseSSL bool `name: ssl_enabled; long: ssl-enabled`
|
||
|
CertPath string `name: ssl_cert; long: ssl-cert`
|
||
|
}
|
||
10 years ago
|
args := []string{"program", "--host=example.com", "--port", "9000", "-u", "fart", "-zv"}
|
||
10 years ago
|
vals, err := parseArgs(args, &one)
|
||
|
if err != nil {
|
||
|
t.Error(err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if vals["host"] != "example.com" {
|
||
|
t.Errorf("expected host 'example.com', saw host '%s'", vals["host"])
|
||
|
}
|
||
|
|
||
|
if vals["port"] != 9000 {
|
||
|
t.Errorf("expected port 9000, saw port %d", vals["port"])
|
||
|
}
|
||
10 years ago
|
|
||
|
if vals["user"] != "fart" {
|
||
|
t.Errorf("expected user 'fart', saw user '%s'", vals["user"])
|
||
|
}
|
||
|
|
||
|
if vals["zip"] != true {
|
||
|
t.Errorf("expected zip to be true, is false")
|
||
|
}
|
||
|
|
||
|
if vals["verbose"] != true {
|
||
|
t.Errorf("expected verbose to be true, is false")
|
||
|
}
|
||
10 years ago
|
}
|