github.com/informationsea/shellflow@v0.1.3/configuration_test.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "reflect" 6 "testing" 7 8 "github.com/BurntSushi/toml" 9 ) 10 11 func TestMemory(t *testing.T) { 12 { 13 m, e := NewMemory("1023") 14 if e != nil { 15 t.Fatalf("Bad parse result: %s", e.Error()) 16 } 17 18 if x := m.memoryByte; x != 1023 { 19 t.Fatalf("Bad memory byte: %d", x) 20 } 21 22 if x := m.Byte(); x != 1023 { 23 t.Fatalf("Bad memory byte: %d", x) 24 } 25 26 if x := m.KiloByte(); x != 1023/1024. { 27 t.Fatalf("Bad memory byte: %f", x) 28 } 29 30 if x := m.MegaByte(); x != 1023/1024./1024. { 31 t.Fatalf("Bad memory byte: %f", x) 32 } 33 34 if x := m.GigaByte(); x != 1023/1024./1024./1024. { 35 t.Fatalf("Bad memory byte: %f", x) 36 } 37 38 if s := m.String(); s != "1023" { 39 t.Fatalf("Bad memory byte: %s", s) 40 } 41 } 42 43 { 44 m, e := NewMemory("1.1k") 45 if e != nil { 46 t.Fatalf("Bad parse result: %s", e.Error()) 47 } 48 49 if x := m.memoryByte; x != 1126 { 50 t.Fatalf("Bad memory byte: %d", x) 51 } 52 53 if x := m.Byte(); x != 1126 { 54 t.Fatalf("Bad memory byte: %d", x) 55 } 56 57 if x := m.KiloByte(); x != 1126/1024. { 58 t.Fatalf("Bad memory byte: %f", x) 59 } 60 61 if x := m.MegaByte(); x != 1126/1024./1024. { 62 t.Fatalf("Bad memory byte: %f", x) 63 } 64 65 if x := m.GigaByte(); x != 1126/1024./1024./1024. { 66 t.Fatalf("Bad memory byte: %f", x) 67 } 68 69 if s := m.String(); s != "1.10k" { 70 t.Fatalf("Bad memory byte: %s", s) 71 } 72 } 73 74 { 75 m, e := NewMemory("1.21M") 76 if e != nil { 77 t.Fatalf("Bad parse result: %s", e.Error()) 78 } 79 80 if x := m.memoryByte; x != 1268776 { 81 t.Fatalf("Bad memory byte: %d", x) 82 } 83 84 if x := m.Byte(); x != 1268776 { 85 t.Fatalf("Bad memory byte: %d", x) 86 } 87 88 if x := m.KiloByte(); x != 1268776/1024. { 89 t.Fatalf("Bad memory byte: %f", x) 90 } 91 92 if x := m.MegaByte(); x != 1268776/1024./1024. { 93 t.Fatalf("Bad memory byte: %f", x) 94 } 95 96 if x := m.GigaByte(); x != 1268776/1024./1024./1024. { 97 t.Fatalf("Bad memory byte: %f", x) 98 } 99 100 if s := m.String(); s != "1.21M" { 101 t.Fatalf("Bad memory byte: %s", s) 102 } 103 } 104 105 { 106 m, e := NewMemory("2.34G") 107 if e != nil { 108 t.Fatalf("Bad parse result: %s", e.Error()) 109 } 110 111 if x := m.memoryByte; x != 2512555868 { 112 t.Fatalf("Bad memory byte: %d", x) 113 } 114 115 if s := m.String(); s != "2.34G" { 116 t.Fatalf("Bad memory byte: %s", s) 117 } 118 } 119 } 120 121 func TestTomlLoad(t *testing.T) { 122 var d Configuration 123 _, err := toml.DecodeFile("default_config.toml", &d) 124 if err != nil { 125 t.Fatalf("%s", err.Error()) 126 } 127 128 expected := Configuration{ 129 Environment: nil, 130 Backend: Backend{""}, 131 Command: []CommandConfiguration{ 132 CommandConfiguration{ 133 RegExp: "mkdir +(-p +)?[^;&]+", 134 RunImmediate: true, 135 }, 136 CommandConfiguration{ 137 RegExp: "example_dont_inheirt_path", 138 DontInheirtPath: true, 139 }, 140 CommandConfiguration{ 141 RegExp: "gatk .*", 142 SGEOption: []string{"-l", "s_vmem=20G,mem_req=20G", "-pe", "def_slot", "2"}, 143 }, 144 CommandConfiguration{ 145 RegExp: "samtools .*", 146 SGEOption: []string{"-l", "s_vmem=10G,mem_req=10G", "-pe", "def_slot", "2"}, 147 }, 148 CommandConfiguration{ 149 RegExp: "java .*", 150 SGEOption: []string{"-l", "s_vmem=40G,mem_req=40G"}, 151 }, 152 }, 153 } 154 155 if !reflect.DeepEqual(expected, d) { 156 j, err := json.MarshalIndent(d, "", " ") 157 if err != nil { 158 t.Fatalf("%s", err.Error()) 159 } 160 t.Fatalf("bad conf: %s", j) 161 } 162 } 163 164 func TestTomlLoad2(t *testing.T) { 165 _, err := LoadConfiguration() 166 if err != nil { 167 t.Fatalf("error: %s", err.Error()) 168 } 169 }