github.com/hooklift/nomad@v0.5.7-0.20170407200202-db11e7dd7b55/command/agent/config_parse_test.go (about) 1 package agent 2 3 import ( 4 "path/filepath" 5 "reflect" 6 "testing" 7 "time" 8 9 "github.com/hashicorp/nomad/nomad/structs/config" 10 ) 11 12 func TestConfig_Parse(t *testing.T) { 13 cases := []struct { 14 File string 15 Result *Config 16 Err bool 17 }{ 18 { 19 "basic.hcl", 20 &Config{ 21 Region: "foobar", 22 Datacenter: "dc2", 23 NodeName: "my-web", 24 DataDir: "/tmp/nomad", 25 LogLevel: "ERR", 26 BindAddr: "192.168.0.1", 27 EnableDebug: true, 28 Ports: &Ports{ 29 HTTP: 1234, 30 RPC: 2345, 31 Serf: 3456, 32 }, 33 Addresses: &Addresses{ 34 HTTP: "127.0.0.1", 35 RPC: "127.0.0.2", 36 Serf: "127.0.0.3", 37 }, 38 AdvertiseAddrs: &AdvertiseAddrs{ 39 RPC: "127.0.0.3", 40 Serf: "127.0.0.4", 41 }, 42 Client: &ClientConfig{ 43 Enabled: true, 44 StateDir: "/tmp/client-state", 45 AllocDir: "/tmp/alloc", 46 Servers: []string{"a.b.c:80", "127.0.0.1:1234"}, 47 NodeClass: "linux-medium-64bit", 48 Meta: map[string]string{ 49 "foo": "bar", 50 "baz": "zip", 51 }, 52 Options: map[string]string{ 53 "foo": "bar", 54 "baz": "zip", 55 }, 56 ChrootEnv: map[string]string{ 57 "/opt/myapp/etc": "/etc", 58 "/opt/myapp/bin": "/bin", 59 }, 60 NetworkInterface: "eth0", 61 NetworkSpeed: 100, 62 CpuCompute: 4444, 63 MaxKillTimeout: "10s", 64 ClientMinPort: 1000, 65 ClientMaxPort: 2000, 66 Reserved: &Resources{ 67 CPU: 10, 68 MemoryMB: 10, 69 DiskMB: 10, 70 IOPS: 10, 71 ReservedPorts: "1,100,10-12", 72 ParsedReservedPorts: []int{1, 10, 11, 12, 100}, 73 }, 74 GCInterval: 6 * time.Second, 75 GCParallelDestroys: 6, 76 GCDiskUsageThreshold: 82, 77 GCInodeUsageThreshold: 91, 78 NoHostUUID: true, 79 }, 80 Server: &ServerConfig{ 81 Enabled: true, 82 BootstrapExpect: 5, 83 DataDir: "/tmp/data", 84 ProtocolVersion: 3, 85 NumSchedulers: 2, 86 EnabledSchedulers: []string{"test"}, 87 NodeGCThreshold: "12h", 88 EvalGCThreshold: "12h", 89 JobGCThreshold: "12h", 90 HeartbeatGrace: "30s", 91 RetryJoin: []string{"1.1.1.1", "2.2.2.2"}, 92 StartJoin: []string{"1.1.1.1", "2.2.2.2"}, 93 RetryInterval: "15s", 94 RejoinAfterLeave: true, 95 RetryMaxAttempts: 3, 96 EncryptKey: "abc", 97 }, 98 Telemetry: &Telemetry{ 99 StatsiteAddr: "127.0.0.1:1234", 100 StatsdAddr: "127.0.0.1:2345", 101 DisableHostname: true, 102 UseNodeName: false, 103 CollectionInterval: "3s", 104 collectionInterval: 3 * time.Second, 105 PublishAllocationMetrics: true, 106 PublishNodeMetrics: true, 107 }, 108 LeaveOnInt: true, 109 LeaveOnTerm: true, 110 EnableSyslog: true, 111 SyslogFacility: "LOCAL1", 112 DisableUpdateCheck: true, 113 DisableAnonymousSignature: true, 114 Atlas: &AtlasConfig{ 115 Infrastructure: "armon/test", 116 Token: "abcd", 117 Join: true, 118 Endpoint: "127.0.0.1:1234", 119 }, 120 Consul: &config.ConsulConfig{ 121 ServerServiceName: "nomad", 122 ClientServiceName: "nomad-client", 123 Addr: "127.0.0.1:9500", 124 Token: "token1", 125 Auth: "username:pass", 126 EnableSSL: &trueValue, 127 VerifySSL: &trueValue, 128 CAFile: "/path/to/ca/file", 129 CertFile: "/path/to/cert/file", 130 KeyFile: "/path/to/key/file", 131 ServerAutoJoin: &trueValue, 132 ClientAutoJoin: &trueValue, 133 AutoAdvertise: &trueValue, 134 ChecksUseAdvertise: &trueValue, 135 }, 136 Vault: &config.VaultConfig{ 137 Addr: "127.0.0.1:9500", 138 AllowUnauthenticated: &trueValue, 139 Enabled: &falseValue, 140 Role: "test_role", 141 TLSCaFile: "/path/to/ca/file", 142 TLSCaPath: "/path/to/ca", 143 TLSCertFile: "/path/to/cert/file", 144 TLSKeyFile: "/path/to/key/file", 145 TLSServerName: "foobar", 146 TLSSkipVerify: &trueValue, 147 TaskTokenTTL: "1s", 148 Token: "12345", 149 }, 150 TLSConfig: &config.TLSConfig{ 151 EnableHTTP: true, 152 EnableRPC: true, 153 VerifyServerHostname: true, 154 CAFile: "foo", 155 CertFile: "bar", 156 KeyFile: "pipe", 157 }, 158 HTTPAPIResponseHeaders: map[string]string{ 159 "Access-Control-Allow-Origin": "*", 160 }, 161 }, 162 false, 163 }, 164 } 165 166 for _, tc := range cases { 167 t.Logf("Testing parse: %s", tc.File) 168 169 path, err := filepath.Abs(filepath.Join("./config-test-fixtures", tc.File)) 170 if err != nil { 171 t.Fatalf("file: %s\n\n%s", tc.File, err) 172 continue 173 } 174 175 actual, err := ParseConfigFile(path) 176 if (err != nil) != tc.Err { 177 t.Fatalf("file: %s\n\n%s", tc.File, err) 178 continue 179 } 180 181 if !reflect.DeepEqual(actual, tc.Result) { 182 t.Fatalf("file: %s\n\n%#v\n\n%#v", tc.File, actual, tc.Result) 183 } 184 } 185 }