github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dli/v2/batches/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/chnsz/golangsdk"
     9  	"github.com/chnsz/golangsdk/openstack/dli/v2/batches"
    10  	th "github.com/chnsz/golangsdk/testhelper"
    11  	"github.com/chnsz/golangsdk/testhelper/client"
    12  )
    13  
    14  const (
    15  	expectedCreateResponse = `
    16  {
    17  	"cluster_name": "driver_behavior",
    18  	"create_time": 1634285547245,
    19  	"id": "6145a791-81a4-4edb-b2d2-ea599caf6550",
    20  	"name": "terraform_spark_job",
    21  	"owner": "terraform",
    22  	"queue": "terraform_test",
    23  	"sc_type": "CUSTOMIZED",
    24  	"state": "starting",
    25  	"update_time": 1634285547245
    26  }`
    27  
    28  	expectedGetStateResponse = `
    29  {
    30  	"id": "6145a791-81a4-4edb-b2d2-ea599caf6550",
    31  	"state": "starting"
    32  }`
    33  )
    34  
    35  var (
    36  	createOpts = batches.CreateOpts{
    37  		ClassName: golangsdk.MaybeString("driver_behavior"),
    38  		Queue:     "terraform_test",
    39  		Name:      "terraform_spark_job",
    40  		Configurations: map[string]interface{}{
    41  			"spark.dli.metaAccess.enable": "true",
    42  		},
    43  		File: "driver_package/driver_behavior.jar",
    44  		Jars: []string{"jar_package/jackson-core-2.13.0-javadoc.jar"},
    45  		Groups: []batches.Group{
    46  			{
    47  				Name: "driver_package",
    48  			},
    49  		},
    50  		MaxRetryTimes:  20,
    51  		Specification:  "A",
    52  		DriverMemory:   "5G",
    53  		DriverCores:    2,
    54  		ExecutorMemory: "8G",
    55  		ExecutorCores:  2,
    56  		NumExecutors:   12,
    57  	}
    58  
    59  	expectedCreateResponseData = &batches.CreateResp{
    60  		ClusterName: "driver_behavior",
    61  		ID:          "6145a791-81a4-4edb-b2d2-ea599caf6550",
    62  		Name:        "terraform_spark_job",
    63  		Owner:       "terraform",
    64  		Queue:       "terraform_test",
    65  		ScType:      "CUSTOMIZED",
    66  		State:       "starting",
    67  		CreateTime:  1634285547245,
    68  		UpdateTime:  1634285547245,
    69  	}
    70  
    71  	expectedGetStateResponseData = &batches.StateResp{
    72  		ID:    "6145a791-81a4-4edb-b2d2-ea599caf6550",
    73  		State: "starting",
    74  	}
    75  )
    76  
    77  func handleV2SparkJobCreate(t *testing.T) {
    78  	th.Mux.HandleFunc("/batches", func(w http.ResponseWriter, r *http.Request) {
    79  		th.TestMethod(t, r, "POST")
    80  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    81  		w.Header().Add("Content-Type", "application/json")
    82  		w.WriteHeader(http.StatusOK)
    83  		_, _ = fmt.Fprint(w, expectedCreateResponse)
    84  	})
    85  }
    86  
    87  func handleV2SparkJobGet(t *testing.T) {
    88  	th.Mux.HandleFunc("/batches/6145a791-81a4-4edb-b2d2-ea599caf6550", func(w http.ResponseWriter, r *http.Request) {
    89  		th.TestMethod(t, r, "GET")
    90  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
    91  		w.Header().Add("Content-Type", "application/json")
    92  		w.WriteHeader(http.StatusOK)
    93  		_, _ = fmt.Fprint(w, expectedCreateResponse)
    94  	})
    95  }
    96  
    97  func handleV2SparkJobGetState(t *testing.T) {
    98  	th.Mux.HandleFunc("/batches/6145a791-81a4-4edb-b2d2-ea599caf6550/state",
    99  		func(w http.ResponseWriter, r *http.Request) {
   100  			th.TestMethod(t, r, "GET")
   101  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   102  			w.Header().Add("Content-Type", "application/json")
   103  			w.WriteHeader(http.StatusOK)
   104  			_, _ = fmt.Fprint(w, expectedGetStateResponse)
   105  		})
   106  }
   107  
   108  func handleV2SparkJobDelete(t *testing.T) {
   109  	th.Mux.HandleFunc("/batches/6145a791-81a4-4edb-b2d2-ea599caf6550", func(w http.ResponseWriter, r *http.Request) {
   110  		th.TestMethod(t, r, "DELETE")
   111  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   112  		w.Header().Add("Content-Type", "application/json")
   113  		w.WriteHeader(http.StatusOK)
   114  	})
   115  }