Add StructJob test with jobfile from HTTP Server

This commit is contained in:
Kenjiro Nakayama
2016-08-16 21:30:40 +09:00
parent 4836c0ffd6
commit 5edc9d1072

View File

@@ -1,8 +1,10 @@
package command
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"reflect"
"strings"
@@ -187,14 +189,8 @@ func TestHelpers_LineLimitReader_TimeLimit(t *testing.T) {
}
}
func TestStructJob(t *testing.T) {
fh, err := ioutil.TempFile("", "nomad")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(fh.Name())
_, err = fh.WriteString(`
job "job1" {
const (
job = `job "job1" {
type = "service"
datacenters = [ "dc1" ]
group "group1" {
@@ -203,12 +199,22 @@ job "job1" {
driver = "exec"
resources = {}
}
restart{
restart{
attempts = 10
mode = "delay"
}
mode = "delay"
}
}
}`)
}`
)
// Test StructJob with local jobfile
func TestStructJobWithLocal(t *testing.T) {
fh, err := ioutil.TempFile("", "nomad")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(fh.Name())
_, err = fh.WriteString(job)
if err != nil {
t.Fatalf("err: %s", err)
}
@@ -223,5 +229,26 @@ job "job1" {
if err != nil {
t.Fatalf("err: %s", err)
}
}
// Test StructJob with jobfile from HTTP Server
func TestStructJobWithHTTPServer(t *testing.T) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, job)
})
go http.ListenAndServe("127.0.0.1:12345", nil)
// Wait until HTTP Server starts certainly
time.Sleep(100 * time.Millisecond)
j := &JobGetter{}
sj, err := j.StructJob("http://127.0.0.1:12345/")
if err != nil {
t.Fatalf("err: %s", err)
}
err = sj.Validate()
if err != nil {
t.Fatalf("err: %s", err)
}
}