Exemplo n.º 1
0
func TestAsyncPipe(t *testing.T) {
	server := NewServer()
	defer server.Close()

	req := MockRequest{}
	req.Url = "/async_pipe"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"stack": []map[string]interface{}{
			map[string]interface{}{
				"url":    "/urls",
				"method": "GET",
				"data":   map[string]string{},
			},
		},
	}

	server.Test(&req, func(msg *MockResponse) {
		pipeResponse := []MockResponse{}
		utils.Convert(&msg.Data, &pipeResponse)

		if len(pipeResponse) != 1 {
			t.Error("Expected Length of output 1")
		}

		if pipeResponse[0].Status != 200 {
			t.Error("Expected 200 from Server")
		}

	})
}
Exemplo n.º 2
0
func TestCreatePDFCollection(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = "/assets"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"mime_type":  "application/pdf",
		"name":       randSeq(10),
		"collection": randSeq(5),
	}

	server.Test(&req, func(msg *tests.MockResponse) {
		utils.Convert(&msg.Data, &assetRet)

		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Asset creation should return status 200.")
		}

		for _, key := range []string{"upload_url", "url", "_id"} {
			if val, ok := assetRet[key]; !ok || len(val) == 0 {
				fmt.Printf("%# v", pretty.Formatter(msg))
				t.Error(key + " should be a valid string in creation return.")
			}
		}
	})
}
Exemplo n.º 3
0
func TestMixPipe(t *testing.T) {
	server := NewServer()
	defer server.Close()

	req := MockRequest{}
	req.Url = "/pipe"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"stack": []map[string]interface{}{
			map[string]interface{}{
				"url":    "/urls",
				"method": "GET",
				"data":   map[string]string{},
			},
			map[string]interface{}{
				"url":    "/urls",
				"method": "POST",
				"data":   map[string]string{},
			},
			map[string]interface{}{
				"url":    "/urlsd",
				"method": "GET",
				"data":   map[string]string{},
			},
		},
	}

	server.Test(&req, func(msg *MockResponse) {
		pipeResponse := []MockResponse{}
		utils.Convert(&msg.Data, &pipeResponse)

		if len(pipeResponse) != 3 {
			t.Error("Expected Length of output 1")
		}

		if pipeResponse[0].Status != 200 {
			t.Error("Expected 200 from Server")
		}

		if pipeResponse[1].Status != 501 {
			t.Error("Post pipe call on /urls should not be allowed")
		}

		if pipeResponse[2].Status != 404 {
			t.Error("/urlsd should not be found")
		}
	})
}
Exemplo n.º 4
0
func TestUrls(t *testing.T) {
	server := NewServer()
	defer server.Close()

	req := MockRequest{}
	req.Url = "/urls"

	server.Test(&req, func(msg *MockResponse) {
		if msg.Status != 200 {
			t.Error("Expected Status return", msg.Status)
		}

		urlResponse := map[string]string{}
		utils.Convert(&msg.Data, &urlResponse)

		if _, ok := urlResponse["async_pipe"]; !ok {
			t.Error("Invalid response from Server")
		}
	})
}
Exemplo n.º 5
0
func TestCreatePDFURLName(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	f1 := randSeq(5)
	f2 := randSeq(10)
	f3 := randSeq(3)

	name := fmt.Sprintf("%v--%v//-%v.pdf", f1, f2, f3)

	req := tests.MockRequest{}
	req.Url = "/assets"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"mime_type": "application/pdf",
		"name":      name,
	}

	server.Test(&req, func(msg *tests.MockResponse) {
		utils.Convert(&msg.Data, &assetRet)

		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Asset creation should return status 200.")
			return
		}

		upload_url, err := url.Parse(assetRet["upload_url"])
		if err != nil {
			t.Error(err.Error())
			return
		}

		fmt.Println(assetRet["upload_url"])
		if !strings.HasSuffix(upload_url.Path, ".pdf") {
			t.Error("URL must end with pdf. Found: " + upload_url.Path)
			return
		}

	})
}
Exemplo n.º 6
0
func (r *Request) ConvertArgument(key string, f interface{}) {
	args := *r.GetArguments()
	val := args[key]
	utils.Convert(val, f)
}
Exemplo n.º 7
0
func (r *Request) ConvertArguments(f interface{}) {
	utils.Convert(r.GetArguments(), f)
}