github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/mrs/v2/jobs/testing/fixtures.go (about)

     1  package testing
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"testing"
     7  
     8  	"github.com/huaweicloud/golangsdk/openstack/mrs/v2/jobs"
     9  	th "github.com/huaweicloud/golangsdk/testhelper"
    10  	"github.com/huaweicloud/golangsdk/testhelper/client"
    11  )
    12  
    13  const (
    14  	expectedCreateResponse = `
    15  {
    16  	"job_submit_result": {
    17  		"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
    18  		"state": "COMPLETE"
    19  	}
    20  }`
    21  
    22  	expectedGetResponse = `
    23  {
    24  	"job_detail": {
    25  		"app_id": "application_1627718181153_0003",
    26  		"arguments": "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
    27  		"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
    28  		"job_name": "terraform_test",
    29  		"job_progress": 100,
    30  		"job_result": "FAILED",
    31  		"job_state": "FINISHED",
    32  		"job_type": "SparkSubmit",
    33  		"launcher_id": "application_1627718181153_0002",
    34  		"started_time": 1627719118083,
    35  		"submitted_time": 1627719066265,
    36  		"user": "terraform"
    37  	}
    38  }`
    39  
    40  	expectedListResponse = `
    41  {
    42  	"total_record":1,
    43  	"job_list":[
    44  		{
    45  			"app_id": "application_1627718181153_0003",
    46  			"arguments": "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
    47  			"job_id": "3c0cf394-5da2-46a7-92df-795d998edea7",
    48  			"job_name": "terraform_test",
    49  			"job_progress": 100,
    50  			"job_result": "FAILED",
    51  			"job_state": "FINISHED",
    52  			"job_type": "SparkSubmit",
    53  			"launcher_id": "application_1627718181153_0002",
    54  			"started_time": 1627719118083,
    55  			"submitted_time": 1627719066265,
    56  			"user": "terraform"
    57  		}
    58  	]
    59  }`
    60  )
    61  
    62  var (
    63  	createOpts = &jobs.CreateOpts{
    64  		JobName: "terraform_test",
    65  		JobType: "SparkSubmit",
    66  		Arguments: []string{
    67  			"--class",
    68  			"com.huawei.bigdata.spark.examples.DriverBehavior",
    69  			"--master",
    70  			"yarn-cluster",
    71  			"obs://obs-demo-analysis-tf/program/driver_behavior.jar",
    72  			"ACCESS_KEY",
    73  			"SECRET_KEY",
    74  			"1",
    75  			"obs://obs-demo-analysis-tf/input",
    76  			"obs://obs-demo-analysis-tf/output",
    77  		},
    78  	}
    79  
    80  	expectedCreateResponseData = &jobs.CreateResp{
    81  		JobSubmitResult: jobs.JobResp{
    82  			JobId: "3c0cf394-5da2-46a7-92df-795d998edea7",
    83  			State: "COMPLETE",
    84  		},
    85  	}
    86  
    87  	expectedGetResponseData = &jobs.Job{
    88  		AppId:         "application_1627718181153_0003",
    89  		Arguments:     "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
    90  		JobId:         "3c0cf394-5da2-46a7-92df-795d998edea7",
    91  		JobName:       "terraform_test",
    92  		JobProgress:   100,
    93  		JobResult:     "FAILED",
    94  		JobState:      "FINISHED",
    95  		JobType:       "SparkSubmit",
    96  		LauncherId:    "application_1627718181153_0002",
    97  		StartedTime:   1627719118083,
    98  		SubmittedTime: 1627719066265,
    99  		User:          "terraform",
   100  	}
   101  
   102  	expectedListResponseData = []jobs.Job{
   103  		{
   104  			AppId:         "application_1627718181153_0003",
   105  			Arguments:     "[--class, com.huawei.bigdata.spark.examples.DriverBehavior, --master, yarn-cluster, obs://obs-demo-analysis-tf/program/driver_behavior.jar, ACCESS_KEY, SECRET_KEY, 1, obs://obs-demo-analysis-tf/input, obs://obs-demo-analysis-tf/output]",
   106  			JobId:         "3c0cf394-5da2-46a7-92df-795d998edea7",
   107  			JobName:       "terraform_test",
   108  			JobProgress:   100,
   109  			JobResult:     "FAILED",
   110  			JobState:      "FINISHED",
   111  			JobType:       "SparkSubmit",
   112  			LauncherId:    "application_1627718181153_0002",
   113  			StartedTime:   1627719118083,
   114  			SubmittedTime: 1627719066265,
   115  			User:          "terraform",
   116  		},
   117  	}
   118  
   119  	deleteOpts = jobs.DeleteOpts{
   120  		JobIds: []string{
   121  			"3c0cf394-5da2-46a7-92df-795d998edea7",
   122  		},
   123  	}
   124  )
   125  
   126  func handleV2JobCreate(t *testing.T) {
   127  	th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions",
   128  		func(w http.ResponseWriter, r *http.Request) {
   129  			th.TestMethod(t, r, "POST")
   130  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   131  			w.Header().Add("Content-Type", "application/json")
   132  			w.WriteHeader(http.StatusOK)
   133  			_, _ = fmt.Fprint(w, expectedCreateResponse)
   134  		})
   135  }
   136  
   137  func handleV2JobGet(t *testing.T) {
   138  	th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions"+
   139  		"/3c0cf394-5da2-46a7-92df-795d998edea7", func(w http.ResponseWriter, r *http.Request) {
   140  		th.TestMethod(t, r, "GET")
   141  		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   142  		w.Header().Add("Content-Type", "application/json")
   143  		w.WriteHeader(http.StatusOK)
   144  		_, _ = fmt.Fprint(w, expectedGetResponse)
   145  	})
   146  }
   147  
   148  func handleV2JobList(t *testing.T) {
   149  	th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions",
   150  		func(w http.ResponseWriter, r *http.Request) {
   151  			th.TestMethod(t, r, "GET")
   152  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   153  			w.Header().Add("Content-Type", "application/json")
   154  			w.WriteHeader(http.StatusOK)
   155  			_, _ = fmt.Fprint(w, expectedListResponse)
   156  		})
   157  }
   158  
   159  func handleV2JobDelete(t *testing.T) {
   160  	th.Mux.HandleFunc("/clusters/986416ea-e26b-40f1-b371-cd7be87376a2/job-executions/batch-delete",
   161  		func(w http.ResponseWriter, r *http.Request) {
   162  			th.TestMethod(t, r, "POST")
   163  			th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
   164  			w.Header().Add("Content-Type", "application/json")
   165  			w.WriteHeader(http.StatusAccepted)
   166  		})
   167  }