github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/imageservice/v2/imageimport/testing/requests_test.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/imageservice/v2/imageimport"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	fakeclient "github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  func TestGet(t *testing.T) {
    14  	th.SetupHTTP()
    15  	defer th.TeardownHTTP()
    16  
    17  	th.Mux.HandleFunc("/info/import", func(w http.ResponseWriter, r *http.Request) {
    18  		th.TestMethod(t, r, "GET")
    19  		th.TestHeader(t, r, "X-Auth-Token", fakeclient.TokenID)
    20  
    21  		w.Header().Add("Content-Type", "application/json")
    22  		w.WriteHeader(http.StatusOK)
    23  
    24  		fmt.Fprintf(w, ImportGetResult)
    25  	})
    26  
    27  	validImportMethods := []string{
    28  		string(imageimport.GlanceDirectMethod),
    29  		string(imageimport.WebDownloadMethod),
    30  	}
    31  
    32  	s, err := imageimport.Get(fakeclient.ServiceClient()).Extract()
    33  	th.AssertNoErr(t, err)
    34  
    35  	th.AssertEquals(t, s.ImportMethods.Description, "Import methods available.")
    36  	th.AssertEquals(t, s.ImportMethods.Type, "array")
    37  	th.AssertDeepEquals(t, s.ImportMethods.Value, validImportMethods)
    38  }