github.com/optim-corp/cios-golang-sdk@v0.5.1/sdk/service_device_monitoring_test.go (about)

     1  package ciossdk
     2  
     3  import (
     4  	"context"
     5  	"io/ioutil"
     6  	"net/http"
     7  	"net/http/httptest"
     8  	"testing"
     9  
    10  	"github.com/optim-corp/cios-golang-sdk/cios"
    11  
    12  	cnv "github.com/fcfcqloow/go-advance/convert"
    13  
    14  	sdkmodel "github.com/optim-corp/cios-golang-sdk/model"
    15  )
    16  
    17  func TestDeviceManagement_GetMonitoringLatestList(t *testing.T) {
    18  	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    19  		w.Header().Set("Content-Type", "application/json")
    20  		var body cios.DeviceMonitoringIDsRequest
    21  		byts, _ := ioutil.ReadAll(r.Body)
    22  		cnv.UnMarshalJson(byts, &body)
    23  		if body.DeviceIds[0] != "1" || body.DeviceIds[1] != "2" || body.DeviceIds[2] != "3" {
    24  			t.Fatal(body)
    25  		}
    26  		if r.URL.Path != "/v2/devices/monitoring/latest" {
    27  			t.Fatal(r.URL.Path)
    28  		}
    29  		if r.Method != "POST" {
    30  			t.Fatal(r.Method)
    31  		}
    32  	}))
    33  	defer ts.Close()
    34  	client := NewCiosClient(CiosClientConfig{Urls: sdkmodel.CIOSUrl{DeviceManagementUrl: ts.URL}})
    35  
    36  	_, _, err := client.DeviceManagement().GetMonitoringLatestList(context.Background(), []string{"1", "2", "3"})
    37  	if err != nil {
    38  		t.Fatal(err.Error())
    39  	}
    40  }
    41  
    42  func TestDeviceManagement_GetMonitoring(t *testing.T) {
    43  	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    44  		w.Header().Set("Content-Type", "application/json")
    45  		if r.URL.Path != "/v2/devices/id/monitoring/latest" {
    46  			t.Fatal(r.URL.Path)
    47  		}
    48  		if r.Method != "GET" {
    49  			t.Fatal(r.Method)
    50  		}
    51  	}))
    52  	defer ts.Close()
    53  	client := NewCiosClient(CiosClientConfig{Urls: sdkmodel.CIOSUrl{DeviceManagementUrl: ts.URL}})
    54  
    55  	_, _, err := client.DeviceManagement().GetMonitoring(context.Background(), "id")
    56  	if err != nil {
    57  		t.Fatal(err.Error())
    58  	}
    59  }