Ejemplo n.º 1
0
func TestT(t *testing.T) {

	b, err := ioutil.ReadFile("main.go")
	if checkerr(err) {
		return
	}
	req := httplib.Put("http://localhost:8989/upload/123")
	req.Body(b)
	resp, err := req.Response()
	if checkerr(err) {
		return
	}
	b2, err := ioutil.ReadAll(resp.Body)
	if checkerr(err) {
		return
	}
	fmt.Println(string(b2))
}
Ejemplo n.º 2
0
func TestT(t *testing.T) {

	b, err := ioutil.ReadFile("Third.java")
	if checkerr(err) {
		return
	}
	req := httplib.Put("http://localhost:8080/upload/tests/upload_test.go")
	// req := httplib.Put("http://upload.daoapp.io/upload/第一题/First.java")
	// req := httplib.Put("http://upload.daoapp.io/upload/第二题/Second.java")
	// req := httplib.Put("http://upload.daoapp.io/upload/小易打怪/Third.java")
	req.Body(b)
	resp, err := req.Response()
	if checkerr(err) {
		return
	}
	b2, err := ioutil.ReadAll(resp.Body)
	if checkerr(err) {
		return
	}
	fmt.Println(string(b2))
}
Ejemplo n.º 3
0
func TestAPIServer(t *testing.T) {

	objs := []string{"cluster", "network", "node", "service", "software", "storage/san", "storage/san/rg", "storage/nas"}
	//objs := []string{"cluster"}

	var req *httplib.BeegoHTTPRequest
	var b []byte
	for _, obj := range objs {
		if obj != "service" && obj != "software" {
			if strings.Contains(obj, "storage/san") == false {
				//GetTest
				req = httplib.Get("http://localhost:8080/v1.0/" + obj + "/" + "1001")
				actionTestTemplate(t, req, obj, "Get")

				if obj != "storage/nas" {
					//GetAllTest
					req = httplib.Get("http://localhost:8080/v1.0/" + obj)
					actionTestTemplate(t, req, obj, "GetAll")
				}
			}

			if obj != "storage/nas" {
				//ListTrueTest
				listBody := models.CommonRequestBody{
					All: true,
					ID:  []string{"1001", "9999"},
				}
				req = httplib.Post("http://localhost:8080/v1.0/" + obj + "/list")
				b, _ = json.Marshal(listBody)
				req.Body(b)
				actionTestTemplate(t, req, obj, "ListTrue")

				//ListFalseTest
				listBody.All = false
				req = httplib.Post("http://localhost:8080/v1.0/" + obj + "/list")
				b, _ = json.Marshal(listBody)
				req.Body(b)
				actionTestTemplate(t, req, obj, "ListFalse")
			}
		}

		//PostTest
		req = httplib.Post("http://localhost:8080/v1.0/" + obj)
		switch obj {
		case "cluster":
			postBody := models.PostCluster{
				Name:              "ClusterPostName",
				Type:              "PostType",
				StorageType:       "StoragePostType",
				StorageSystemID:   "storage_" + utils.Generate32UUID(),
				MaxNodeUsageLimit: 100,
				MaxNodeNum:        200,
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "network":
			postBody := models.IPtable{
				Type:      "PostType",
				IPAddress: "0.0.0.2",
				Netmask:   "255.255.255.2",
				//Gateway   "" //miss property,
				Total: 10,
				Used:  2,
				//Status
				//Error
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "node":
			postBodyList := make([]models.PostNode, 2)
			postBodyList[0] = models.PostNode{
				NodeID:      "node_9001",
				ClusterID:   "cluster_1001",
				SoftwareID:  "software_1001",
				MaxInstance: 11,
			}
			postBodyList[1] = models.PostNode{
				NodeID:      "node_9002",
				ClusterID:   "cluster_1002",
				SoftwareID:  "software_1002",
				MaxInstance: 12,
			}
			b, _ = json.Marshal(postBodyList)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "service":
			postBody := models.PostService{}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "software":
			postBody := models.Software{
				ID:       "software_9999",
				Name:     "software_name_9999",
				Version:  "V999",
				Type:     "999",
				StoreURL: "Z:\\",
				MD5:      "",
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/san":
			san := new(models.SAN)
			san.ID = "san_1001"
			san.Name = "san_name_1001"
			san.Vender = "san_vender_1001"
			lc := new(models.LoginConfig)
			lc.Name = "lc_name_1001"
			lc.Type = "A"
			lc.IPAddress = "0.0.0.1"
			lc.UserName = "******"
			lc.Password = "******"
			san.Login = lc
			san.LUNRange = "a1"
			san.HLURange = "b1"
			san.TotalMB = 100
			san.FreeMB = 50
			san.Error = "NONE1"
			postBody := san
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/rg":
			postBody := models.PostRaidGroup{
				SANID:  "PostRaidGroup_9999",
				Number: 111,
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		case "storage/nas":
			postBody := models.NAS{
				ID:           "NAS_9999",
				ServerIPAddr: "0.0.0.9",
				ShareDir:     "Z:\\",
			}
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Post")
		}

		//PostRollbackTest
		if obj == "cluster" {
			postBody := models.PostCluster{
				Name:              "ClusterPostName",
				Type:              "PostType",
				StorageType:       "StoragePostType",
				StorageSystemID:   "",
				MaxNodeUsageLimit: 100,
				MaxNodeNum:        200,
			}
			req = httplib.Post("http://localhost:8080/v1.0/" + obj)
			b, _ = json.Marshal(postBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "PostRollback")
		}

		//PutTest
		if obj == "node" {
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001")
			putBody := models.Node{
				Status:      models.Enable,
				MaxInstance: 99,
			}
			b, _ = json.Marshal(putBody)
			req.Body(b)
			actionTestTemplate(t, req, obj, "Put")
		}
		if obj != "software" && obj != "storage/san" && obj != "storage/nas" {
			//EnableTest
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001/enable")
			actionTestTemplate(t, req, obj, "Enable")
			//DisableTest
			req = httplib.Put("http://localhost:8080/v1.0/" + obj + "/" + "1001/disable")
			actionTestTemplate(t, req, obj, "Disable")
		}

		//DeleteTest
		if obj != "storage/nas" {
			req = httplib.Delete("http://localhost:8080/v1.0/" + obj + "/" + "1001")
			actionTestTemplate(t, req, obj, "Delete")
		}

	}
}