Commit 4dd75e3c authored by M. Rehan Abbasi's avatar M. Rehan Abbasi
Browse files

add test case for PUT /mts_sessions

parent acd9692e
Loading
Loading
Loading
Loading
+81 −7
Original line number Diff line number Diff line
@@ -496,9 +496,7 @@ func testMtsSessionPost(t *testing.T) (string, string) {
	/******************************
	 * expected response section
	 ******************************/
	// Initialize the data structure for the expected response to the POST request
	// MEC-015 Clause 6.2.7
	// MEC-015 Clause 9.5.3.2

	expectedRequestType := uint32(0) // Application specific MTS Session
	expectedAppInsId := "ue1-iperf"
	expectedMtsMode := uint32(0)
@@ -517,9 +515,7 @@ func testMtsSessionPost(t *testing.T) (string, string) {
	/******************************
	 * request body section
	 ******************************/
	// Initialize the data structure for the POST request
	// MEC-015 Clause 6.2.7
	// MEC-015 Clause 9.5.3.2

	requestType := uint32(0) // Application specific MTS Session
	mtsMode := uint32(0)
	requestedMtsSessionInfo := mts.MtsSessionInfo{
@@ -670,6 +666,82 @@ func testMtsSessionsGet(t *testing.T, sessionId string, expectedResponse string)
	}
}

func testMtsSessionPut(t *testing.T, sessionId string, expectSuccess bool) string {
	/******************************
	 * expected response section
	 ******************************/

	expectedRequestType := uint32(0) // Application specific MTS Session
	expectedAppInsId := "ue1-iperf"
	expectedMtsMode := uint32(0)
	expectedTrafficDirection := "00"
	expectedMtsSessionInfo := mts.MtsSessionInfo{
		AppInsId:         expectedAppInsId,
		RequestType:      &expectedRequestType,
		MtsMode:          &expectedMtsMode,
		TrafficDirection: expectedTrafficDirection,
	}
	expectedResponseStr, err := json.Marshal(expectedMtsSessionInfo)
	if err != nil {
		t.Fatalf(err.Error())
	}

	/******************************
	 * request vars section
	 ******************************/
	vars := make(map[string]string)
	vars["sessionId"] = sessionId

	/******************************
	 * request body section
	 ******************************/

	requestType := uint32(0) // Application specific MTS Session
	mtsMode := uint32(1)
	requestedMtsSessionInfo := mts.MtsSessionInfo{
		AppInsId:         "ue1-iperf",
		RequestType:      &requestType,
		MtsMode:          &mtsMode,
		TrafficDirection: "00",
	}
	body, err := json.Marshal(requestedMtsSessionInfo)
	if err != nil {
		t.Fatalf(err.Error())
	}
	fmt.Println("body: ", string(body))

	/******************************
	 * request queries section
	 ******************************/

	/******************************
	 * request execution section
	 ******************************/

	if expectSuccess {
		rr, err := sendRequest(http.MethodPost, "/mts/v1/mts_sessions", bytes.NewBuffer(body), vars, nil, http.StatusOK, mts.MtsSessionPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}

		var respBody mts.MtsSessionInfo
		err = json.Unmarshal([]byte(rr), &respBody)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		if rr != string(expectedResponseStr) {
			t.Fatalf("Failed to get expected response")
		}
		return string(expectedResponseStr)
	} else {
		_, err = sendRequest(http.MethodPost, "/mts/v1/mts_sessions", bytes.NewBuffer(body), vars, nil, http.StatusNotFound, mts.MtsSessionPUT)
		if err != nil {
			t.Fatalf("Failed to get expected response")
		}
		return ""
	}
}

func testMtsSessionDelete(t *testing.T, sessionId string, expectSuccess bool) {

	/******************************
@@ -721,7 +793,9 @@ func TestSuccessMtsSession(t *testing.T) {
	// GET
	testMtsSessionsGet(t, sessionId, expectedGetResp)
	// PUT
	// TODO
	expectedGetResp = testMtsSessionPut(t, sessionId, true)
	// GET
	testMtsSessionsGet(t, sessionId, expectedGetResp)
	// DELETE
	testMtsSessionDelete(t, sessionId, true)