2015-09-05 15:49:06 -04:00
|
|
|
package dockerfile
|
2015-01-27 10:57:34 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuilderFlags(t *testing.T) {
|
|
|
|
var expected string
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf := NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
bf.Args = []string{}
|
|
|
|
if err := bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test1 of %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
bf.Args = []string{"--"}
|
|
|
|
if err := bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test2 of %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 := bf.AddString("str1", "")
|
|
|
|
flBool1 := bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{}
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test3 of %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if flStr1.IsUsed() == true {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Test3 - str1 was not used!")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
if flBool1.IsUsed() == true {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Test3 - bool1 was not used!")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 = bf.AddString("str1", "HI")
|
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test4 of %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if flStr1.Value != "HI" {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Str1 was supposed to default to: HI")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
if flBool1.IsTrue() {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Bool1 was supposed to default to: false")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
if flStr1.IsUsed() == true {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Str1 was not used!")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
if flBool1.IsUsed() == true {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Bool1 was not used!")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 = bf.AddString("str1", "HI")
|
|
|
|
bf.Args = []string{"--str1"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err == nil {
|
|
|
|
t.Fatalf("Test %q was supposed to fail", bf.Args)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 = bf.AddString("str1", "HI")
|
|
|
|
bf.Args = []string{"--str1="}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected = ""
|
|
|
|
if flStr1.Value != expected {
|
|
|
|
t.Fatalf("Str1 (%q) should be: %q", flStr1.Value, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 = bf.AddString("str1", "HI")
|
|
|
|
bf.Args = []string{"--str1=BYE"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expected = "BYE"
|
|
|
|
if flStr1.Value != expected {
|
|
|
|
t.Fatalf("Str1 (%q) should be: %q", flStr1.Value, expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool1"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !flBool1.IsTrue() {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Test-b1 Bool1 was supposed to be true")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool1=true"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !flBool1.IsTrue() {
|
|
|
|
t.Fatalf("Test-b2 Bool1 was supposed to be true")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool1=false"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if flBool1.IsTrue() {
|
2016-12-25 01:37:31 -05:00
|
|
|
t.Fatal("Test-b3 Bool1 was supposed to be false")
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool1=false1"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err == nil {
|
|
|
|
t.Fatalf("Test %q was supposed to fail", bf.Args)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool2"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err == nil {
|
|
|
|
t.Fatalf("Test %q was supposed to fail", bf.Args)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---
|
|
|
|
|
2015-07-22 01:29:03 -04:00
|
|
|
bf = NewBFlags()
|
2015-01-27 10:57:34 -05:00
|
|
|
flStr1 = bf.AddString("str1", "HI")
|
|
|
|
flBool1 = bf.AddBool("bool1", false)
|
|
|
|
bf.Args = []string{"--bool1", "--str1=BYE"}
|
|
|
|
|
|
|
|
if err = bf.Parse(); err != nil {
|
|
|
|
t.Fatalf("Test %q was supposed to work: %s", bf.Args, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if flStr1.Value != "BYE" {
|
2017-02-16 10:56:53 -05:00
|
|
|
t.Fatalf("Test %s, str1 should be BYE", bf.Args)
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
if !flBool1.IsTrue() {
|
2017-02-16 10:56:53 -05:00
|
|
|
t.Fatalf("Test %s, bool1 should be true", bf.Args)
|
2015-01-27 10:57:34 -05:00
|
|
|
}
|
|
|
|
}
|