How to use CreateTest method of client Package

Best Testkube code snippet using client.CreateTest

test_test.go

Source:test_test.go Github

copy

Full Screen

...4 "fmt"5 "testing"6 "time"7)8func TestCreateTest(t *testing.T) {9 testPreCheck(t)10 client := clientConfigure()11 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})12 defer client.DeleteBucket(bucket.Key) // nolint: errcheck13 if err != nil {14 t.Error(err)15 }16 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}17 test, err = client.CreateTest(test)18 defer client.DeleteTest(test) // nolint: errcheck19 if err != nil {20 t.Error(err)21 }22 if len(test.ID) == 0 {23 t.Error("Test id should not be empty")24 }25 if test.CreatedAt.Day() != time.Now().Day() {26 t.Errorf("Expected time %s js not correct", test.CreatedAt.String())27 }28}29func TestReadTest(t *testing.T) {30 testPreCheck(t)31 client := clientConfigure()32 bucket, err := client.CreateBucket(&Bucket{Name: "newTest", Team: &Team{ID: teamID}})33 defer client.DeleteBucket(bucket.Key) // nolint: errcheck34 if err != nil {35 t.Error(err)36 }37 newTest := &Test{Name: "tf_test", Description: "This is a tf newTest", Bucket: bucket}38 newTest, err = client.CreateTest(newTest)39 defer client.DeleteTest(newTest) // nolint: errcheck40 if err != nil {41 t.Error(err)42 }43 readTest, err := client.ReadTest(newTest)44 if err != nil {45 t.Error(err)46 }47 if readTest.Name != newTest.Name {48 t.Errorf("Expected name %s, actual %s", newTest.Name, readTest.Name)49 }50 if readTest.CreatedAt.Day() != time.Now().Day() {51 t.Errorf("Expected time %s js not correct", readTest.CreatedAt.String())52 }53}54func TestReadTestMetrics(t *testing.T) {55 testPreCheck(t)56 client := clientConfigure()57 bucket, err := client.CreateBucket(&Bucket{Name: "newTest", Team: &Team{ID: teamID}})58 defer client.DeleteBucket(bucket.Key) // nolint: errcheck59 if err != nil {60 t.Error(err)61 }62 newTest := &Test{Name: "tf_test", Description: "This is a tf newTest", Bucket: bucket}63 newTest, err = client.CreateTest(newTest)64 defer client.DeleteTest(newTest) // nolint: errcheck65 if err != nil {66 t.Error(err)67 }68 readTestMetrics, err := client.ReadTestMetrics(newTest, &ReadMetricsInput{})69 if err != nil {70 t.Error(err)71 }72 if readTestMetrics.Region != "all" {73 t.Errorf("Expected region all, actual %s", readTestMetrics.Region)74 }75 if readTestMetrics.Timeframe != "month" {76 t.Errorf("Expected timeframe month, actual %s", readTestMetrics.Timeframe)77 }78 if len(readTestMetrics.ResponseTimes) == 0 {79 t.Error("Expected response times but none found")80 }81}82func TestUpdateTest(t *testing.T) {83 testPreCheck(t)84 client := clientConfigure()85 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})86 defer client.DeleteBucket(bucket.Key) // nolint: errcheck87 if err != nil {88 t.Error(err)89 }90 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}91 test, err = client.CreateTest(test)92 defer client.DeleteTest(test) // nolint: errcheck93 if err != nil {94 t.Error(err)95 }96 test.Description = "New description"97 updatedTest, err := client.UpdateTest(test)98 if err != nil {99 t.Error(err)100 }101 if updatedTest.Description != test.Description {102 t.Errorf("Expected description %s, actual %s", test.Description, updatedTest.Description)103 }104}105func TestUpdateTestUsingPartiallyFilledOutObject(t *testing.T) {106 testPreCheck(t)107 client := clientConfigure()108 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})109 defer client.DeleteBucket(bucket.Key) // nolint: errcheck110 if err != nil {111 t.Error(err)112 }113 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}114 test, err = client.CreateTest(test)115 defer client.DeleteTest(test) // nolint: errcheck116 if err != nil {117 t.Error(err)118 }119 testUpdate := &Test{ID: test.ID, Description: "New description", Bucket: bucket}120 updatedTest, err := client.UpdateTest(testUpdate)121 if err != nil {122 t.Error(err)123 }124 if updatedTest.Description != testUpdate.Description {125 t.Errorf("Expected description %s, actual %s", testUpdate.Description, updatedTest.Description)126 }127}128func TestReadFromResponse(t *testing.T) {129 responseBody := `130{131 "meta": {132 "status": "success"133 },134 "data": {135 "trigger_url": "https://api.runscope.com/radar/235d992e-cb62-43b1-9983-dd5864b64d89/trigger",136 "name": "Sample Name",137 "created_at": 1494023235,138 "created_by": {139 "email": "edward.wilde@acme.com",140 "id": "8512774f-de31-433e-b068-ed76819b2842",141 "name": "Edward Wilde"142 },143 "default_environment_id": "8e7afae4-23b6-492a-b4b9-75d515b5082b",144 "version": "1.0",145 "exported_at": 1294023235,146 "environments": [147 {148 "script_library": [],149 "name": "Test Settings",150 "script": null,151 "preserve_cookies": false,152 "test_id": "e0699a4b-0141-4fa2-8007-e016acede2bf",153 "initial_variables": null,154 "integrations": [],155 "auth": null,156 "id": "7e7afae4-23b6-492a-b4b9-75d515b5082b",157 "regions": [158 "us1"159 ],160 "headers": null,161 "verify_ssl": true,162 "version": "1.0",163 "exported_at": 1494023235,164 "retry_on_failure": false,165 "remote_agents": [],166 "webhooks": null,167 "parent_environment_id": null,168 "stop_on_failure": false,169 "emails": {170 "notify_on": null,171 "notify_all": false,172 "recipients": [],173 "notify_threshold": 0174 },175 "client_certificate": null176 }177 ],178 "schedules": [179 {180 "environment_id": "d44fe112-74ea-4713-92fc-caa27ef8ce8a",181 "interval": "1m",182 "note": null,183 "version": "1.0",184 "exported_at": 1494623265,185 "id": "c4058b68-3493-44f0-b25e-c33db257e366"186 }187 ],188 "steps": [189 {190 "url": "{{base_url}}/v1/users",191 "variables": [192 {193 "name": "source_ip",194 "property": "origin",195 "source": "response_json"196 }197 ],198 "args": {},199 "step_type": "request",200 "auth": {},201 "id": "e4044178-3b78-43fd-b67c-3316bfe526a9",202 "note": "some note",203 "headers": {204 "Authorization": [205 "bearer {{token}}"206 ]207 },208 "request_id": "2dbfb5d2-3b5a-499c-9550-b06f9a475feb",209 "assertions": [210 {211 "comparison": "equal_number",212 "value": 200,213 "source": "response_status"214 }215 ],216 "scripts": [217 "log(\"This is a sample script\");"218 ],219 "before_scripts": ["log(\"This is a sample pre-request script\");"],220 "data": "",221 "method": "GET"222 }223 ],224 "last_run": {225 "remote_agent_uuid": null,226 "finished_at": 1494623241.385894,227 "error_count": 0,228 "message_success": 1,229 "test_uuid": "7aec8f16-8680-41fe-b0df-4c9be99b3a26",230 "id": "50ded770-f0b5-48ec-91ce-782a932d6b80",231 "extractor_success": 0,232 "uuid": "50ded770-f0b5-48ec-91ce-782a932d6b80",233 "environment_uuid": "d44fe112-74ea-4713-92fc-caa27ef8ce8a",234 "environment_name": "Test Settings",235 "source": "scheduled",236 "remote_agent_name": null,237 "remote_agent": null,238 "status": "completed",239 "bucket_key": "taank6ebawmk",240 "remote_agent_version": "unknown",241 "substitution_success": 0,242 "message_count": 1,243 "script_count": 0,244 "substitution_count": 0,245 "script_success": 0,246 "assertion_count": 1,247 "assertion_success": 1,248 "created_at": 1494623238.460797,249 "messages": [],250 "extractor_count": 0,251 "template_uuids": [252 "699db99e-8c7a-4922-9a0b-a73da87387fb",253 "e4044178-3b78-43fd-b67c-3316bfe526a9"254 ],255 "region": "us1"256 },257 "id": "f0699a4b-0141-4fa2-8007-e016acede2bf",258 "description": "My test description"259 },260 "error": null261}262`263 responseMap := new(response)264 if err := json.Unmarshal([]byte(responseBody), &responseMap); err != nil {265 t.Error(err)266 }267 test, err := getTestFromResponse(responseMap.Data)268 if err != nil {269 t.Error(err)270 }271 if test.Name != "Sample Name" {272 t.Errorf("Expected name %s, actual %s", "Sample Name", test.Name)273 }274 expectedTime := time.Unix(int64(1494023235), 0)275 if !test.CreatedAt.Equal(expectedTime) {276 t.Errorf("Expected time %s, actual %s", expectedTime.String(), test.CreatedAt)277 }278 if test.CreatedBy.Name != "Edward Wilde" {279 t.Errorf("Expected created by %s, actual %s", "Edward Wilde", test.CreatedBy.Name)280 }281 if test.CreatedBy.Email != "edward.wilde@acme.com" {282 t.Errorf("Expected created by %s, actual %s", "edward.wilde@acme.com", test.CreatedBy.Email)283 }284 if test.CreatedBy.ID != "8512774f-de31-433e-b068-ed76819b2842" {285 t.Errorf("Expected created by %s, actual %s", "8512774f-de31-433e-b068-ed76819b2842", test.CreatedBy.Email)286 }287 if test.DefaultEnvironmentID != "8e7afae4-23b6-492a-b4b9-75d515b5082b" {288 t.Errorf("Expected created by %s, actual %s", "8e7afae4-23b6-492a-b4b9-75d515b5082b", test.DefaultEnvironmentID)289 }290 expectedTime = time.Unix(int64(1294023235), 0)291 if !test.ExportedAt.Equal(expectedTime) {292 t.Errorf("Expected time %s, actual %s", expectedTime.String(), test.ExportedAt)293 }294 if len(test.Environments) != 1 {295 t.Errorf("Expected %d environments, actual %d", 1, len(test.Environments))296 }297 if test.Environments[0].ID != "7e7afae4-23b6-492a-b4b9-75d515b5082b" {298 t.Errorf("Expected environment id %s, actual %s", "7e7afae4-23b6-492a-b4b9-75d515b5082b", test.Environments[0].ID)299 }300 if test.LastRun == nil {301 t.Error("LastRun nil")302 }303 expectedTime = time.Unix(1494623241, 385894060)304 if !test.LastRun.FinishedAt.Equal(expectedTime) {305 t.Errorf("Expected last run finished at time %s, actual %s", expectedTime.String(), test.LastRun.FinishedAt)306 }307 if len(test.Steps) != 1 {308 t.Errorf("Expected %d steps, actual %d", 1, len(test.Steps))309 }310 step := test.Steps[0]311 if step.URL != "{{base_url}}/v1/users" {312 t.Errorf("Expected step url %s, actual %s", "{{base_url}}/v1/users", step.URL)313 }314 if len(step.Variables) != 1 {315 t.Errorf("Expected %d variables, actual %d", 1, len(step.Variables))316 }317 variable := step.Variables[0]318 if variable.Name != "source_ip" {319 t.Errorf("Expected variable name %s, actual %s", "source_ip", variable.Name)320 }321 if variable.Property != "origin" {322 t.Errorf("Expected variable property %s, actual %s", "origin", variable.Property)323 }324 if variable.Source != "response_json" {325 t.Errorf("Expected variable source %s, actual %s", "origin", variable.Source)326 }327 if step.StepType != "request" {328 t.Errorf("Expected step type %s, actual %s", "request", step.StepType)329 }330 if step.ID != "e4044178-3b78-43fd-b67c-3316bfe526a9" {331 t.Errorf("Expected step type %s, actual %s", "e4044178-3b78-43fd-b67c-3316bfe526a9", step.StepType)332 }333 if len(step.Headers) != 1 {334 t.Errorf("Expected %d headers, actual %d", 1, len(step.Headers))335 }336 header := step.Headers["Authorization"]337 if len(header) != 1 {338 t.Errorf("Expected %d authorization values, actual %d", 1, len(header))339 }340 if header[0] != "bearer {{token}}" {341 t.Errorf("Expected authorization header %s, actual %s", "bearer {{token}}", header[0])342 }343 if step.RequestID != "2dbfb5d2-3b5a-499c-9550-b06f9a475feb" {344 t.Errorf("Expected step request id %s, actual %s", "2dbfb5d2-3b5a-499c-9550-b06f9a475feb", step.StepType)345 }346 if len(step.Assertions) != 1 {347 t.Errorf("Expected %d assertions, actual %d", 1, len(step.Assertions))348 }349 assertion := step.Assertions[0]350 if assertion.Comparison != "equal_number" {351 t.Errorf("Expected assertion comparison %s, actual %s", "equal_number", assertion.Comparison)352 }353 if assertion.Value != float64(200) {354 t.Errorf("Expected assertion value %d, actual %d", 200, assertion.Value)355 }356 if assertion.Source != "response_status" {357 t.Errorf("Expected assertion source %s, actual %s", "response_status", assertion.Source)358 }359 if len(step.Scripts) != 1 {360 t.Errorf("Expected %d scripts, actual %d", 1, len(step.Scripts))361 }362 script := step.Scripts[0]363 if script != "log(\"This is a sample script\");" {364 t.Errorf("Expected script value %s, actual %s", "log(\"This is a sample script\");", script)365 }366 if len(step.BeforeScripts) != 1 {367 t.Errorf("Expected %d before scripts, actual %d", 1, len(step.Scripts))368 }369 beforeScript := step.BeforeScripts[0]370 if beforeScript != "log(\"This is a sample pre-request script\");" {371 t.Errorf("Expected script value %s, actual %s", "log(\"This is a sample pre-request script\");", beforeScript)372 }373}374func TestListsTests(t *testing.T) {375 testPreCheck(t)376 client := clientConfigure()377 bucket, err := client.CreateBucket(&Bucket{Name: "newTest", Team: &Team{ID: teamID}})378 defer client.DeleteBucket(bucket.Key) // nolint: errcheck379 if err != nil {380 t.Error(err)381 }382 newTest := &Test{Name: "tf_test1", Description: "This is a tf newTest", Bucket: bucket}383 newTest, err = client.CreateTest(newTest)384 if err != nil {385 t.Error(err)386 }387 defer client.DeleteTest(newTest) // nolint: errcheck388 newTest = &Test{Name: "tf_test2", Description: "This is a tf newTest", Bucket: bucket}389 newTest, err = client.CreateTest(newTest)390 defer client.DeleteTest(newTest) // nolint: errcheck391 if err != nil {392 t.Error(err)393 }394 tests, err := client.ListTests(&ListTestsInput{BucketKey: bucket.Key})395 if err != nil {396 t.Error(err)397 }398 if len(tests) != 2 {399 t.Errorf("Expected %d tests, actual no found %d", 2, len(tests))400 }401 if tests[0].Name != "tf_test2" {402 t.Errorf("Expected name to be %s, found %s", "tf_test2", tests[1].Name)403 }404}405func TestListsTestsMoreThan10(t *testing.T) {406 testPreCheck(t)407 client := clientConfigure()408 bucket, err := client.CreateBucket(&Bucket{Name: "newTest", Team: &Team{ID: teamID}})409 defer client.DeleteBucket(bucket.Key) // nolint: errcheck410 if err != nil {411 t.Error(err)412 }413 for i := 0; i < 15; i++ {414 newTest := &Test{Name: fmt.Sprintf("tf_test1-%d", i), Description: "This is a tf newTest", Bucket: bucket}415 newTest, err = client.CreateTest(newTest)416 //noinspection ALL417 defer client.DeleteTest(&Test{Bucket: newTest.Bucket, ID: newTest.ID}) // nolint: errcheck418 }419 if err != nil {420 t.Error(err)421 }422 tests, err := client.ListTests(&ListTestsInput{BucketKey: bucket.Key, Count: 20})423 if err != nil {424 t.Error(err)425 }426 if len(tests) != 15 {427 t.Errorf("Expected %d tests, actual no found %d", 15, len(tests))428 }429}...

Full Screen

Full Screen

test_step_test.go

Source:test_step_test.go Github

copy

Full Screen

2import (3 "strings"4 "testing"5)6func TestCreateTestStep(t *testing.T) {7 testPreCheck(t)8 client := clientConfigure()9 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})10 defer client.DeleteBucket(bucket.Key) // nolint: errcheck11 if err != nil {12 t.Error(err)13 }14 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}15 test, err = client.CreateTest(test)16 defer client.DeleteTest(test) // nolint: errcheck17 if err != nil {18 t.Error(err)19 }20 step := NewTestStep()21 step.StepType = "request"22 step.URL = "http://example.com"23 step.Method = "GET"24 step.Assertions = []*Assertion{{25 Source: "response_status",26 Comparison: "equal_number",27 Value: 200,28 }}29 step, err = client.CreateTestStep(step, bucket.Key, test.ID)30 defer client.DeleteTestStep(step, bucket.Key, test.ID) // nolint: errcheck31 if err != nil {32 t.Error(err)33 }34 if len(step.ID) == 0 {35 t.Error("Test step id should not be empty")36 }37 test2 := &Test{Name: "tf_test2", Description: "This is a tf test with a subtest step", Bucket: bucket}38 test2, err = client.CreateTest(test2)39 defer client.DeleteTest(test2) // nolint: errcheck40 if err != nil {41 t.Error(err)42 }43 step2 := NewTestStep()44 step2.StepType = "subtest"45 step2.TestUUID = test.ID46 step2.Assertions = []*Assertion{{47 Source: "response_json",48 Property: "result",49 Comparison: "equal",50 Value: "pass",51 }}52 step2, err = client.CreateTestStep(step2, bucket.Key, test2.ID)53 defer client.DeleteTestStep(step2, bucket.Key, test2.ID) // nolint: errcheck54 if err != nil {55 t.Error(err)56 }57 if len(step2.ID) == 0 {58 t.Error("Test step id should not be empty")59 }60}61func TestReadTestStep(t *testing.T) {62 testPreCheck(t)63 client := clientConfigure()64 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})65 defer client.DeleteBucket(bucket.Key) // nolint: errcheck66 if err != nil {67 t.Error(err)68 }69 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}70 test, err = client.CreateTest(test)71 defer client.DeleteTest(test) // nolint: errcheck72 if err != nil {73 t.Error(err)74 }75 step := NewTestStep()76 step.Scripts = []string{"log(\"This is a sample post-request script\");"}77 step.BeforeScripts = []string{"log(\"This is a sample pre-request script\");"}78 step.StepType = "request"79 step.URL = "http://example.com"80 step.Method = "GET"81 step.Assertions = []*Assertion{{82 Source: "response_status",83 Comparison: "equal_number",84 Value: 200,85 }}86 step, err = client.CreateTestStep(step, bucket.Key, test.ID)87 defer client.DeleteTestStep(step, bucket.Key, test.ID) // nolint: errcheck88 if err != nil {89 t.Error(err)90 }91 readStep, err := client.ReadTestStep(step, bucket.Key, test.ID)92 if err != nil {93 t.Error(err)94 }95 if len(readStep.ID) == 0 {96 t.Error("Test step id should not be empty")97 }98 if readStep.ID != step.ID {99 t.Errorf("Expected step ID %s, actual %s", step.ID, readStep.ID)100 }101 if readStep.Method != step.Method {102 t.Errorf("Expected step method %s, actual %s", step.Method, readStep.Method)103 }104 if readStep.BeforeScripts[0] != step.BeforeScripts[0] {105 t.Errorf("Expected before script %s, actual %s", step.BeforeScripts[0], readStep.BeforeScripts[0])106 }107 if readStep.Scripts[0] != step.Scripts[0] {108 t.Errorf("Expected script %s, actual %s", step.Scripts[0], readStep.Scripts[0])109 }110}111func TestUpdateTestStep(t *testing.T) {112 testPreCheck(t)113 client := clientConfigure()114 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})115 defer client.DeleteBucket(bucket.Key) // nolint: errcheck116 if err != nil {117 t.Error(err)118 }119 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}120 test, err = client.CreateTest(test)121 defer client.DeleteTest(test) // nolint: errcheck122 if err != nil {123 t.Error(err)124 }125 step := NewTestStep()126 step.StepType = "request"127 step.URL = "http://example.com"128 step.Method = "GET"129 step.Assertions = []*Assertion{{130 Source: "response_status",131 Comparison: "equal_number",132 Value: 200,133 }}134 step, err = client.CreateTestStep(step, bucket.Key, test.ID)135 defer client.DeleteTestStep(step, bucket.Key, test.ID) // nolint: errcheck136 if err != nil {137 t.Error(err)138 }139 step.Method = "POST"140 _, err = client.UpdateTestStep(step, bucket.Key, test.ID)141 if err != nil {142 t.Error(err)143 }144 readStep, err := client.ReadTestStep(step, bucket.Key, test.ID)145 if err != nil {146 t.Error(err)147 }148 if readStep.Method != "POST" {149 t.Errorf("Expected step method %s, actual %s", "POST", readStep.Method)150 }151}152func TestDeleteTestStep(t *testing.T) {153 testPreCheck(t)154 client := clientConfigure()155 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})156 defer client.DeleteBucket(bucket.Key) // nolint: errcheck157 if err != nil {158 t.Error(err)159 }160 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}161 test, err = client.CreateTest(test)162 defer client.DeleteTest(test) // nolint: errcheck163 if err != nil {164 t.Error(err)165 }166 step := NewTestStep()167 step.StepType = "request"168 step.URL = "http://example.com"169 step.Method = "GET"170 step.Assertions = []*Assertion{{171 Source: "response_status",172 Comparison: "equal_number",173 Value: 200,174 }}175 step, err = client.CreateTestStep(step, bucket.Key, test.ID)176 if err != nil {177 t.Error(err)178 }179 err = client.DeleteTestStep(step, bucket.Key, test.ID)180 if err != nil {181 t.Error(err)182 }183 _, err = client.ReadTestStep(step, bucket.Key, test.ID)184 if err == nil {185 t.Error("Should not have found test step after deleting it")186 }187 if !strings.Contains(err.Error(), "404 Not Found") {188 t.Errorf("Expected error to contain %s, actual %s", "404 Not Found", err.Error())189 }190}191func TestValidationRequestTypeMissingMethod(t *testing.T) {192 step := NewTestStep()193 step.StepType = "request"194 step.URL = "http://example.com"195 step.Assertions = []*Assertion{{196 Source: "response_status",197 Comparison: "equal_number",198 Value: 200,199 }}200 client := clientConfigure()201 _, err := client.CreateTestStep(step, "foo", "ba")202 if err == nil {203 t.Error("Expected validation error for missing method")204 }205 if !strings.Contains(err.Error(), "A request test step must specify 'Method' property") {206 t.Error("Expected validation error for missing method")207 }208}209func TestValidationRequestTypeGetIncludesBody(t *testing.T) {210 step := NewTestStep()211 step.StepType = "request"212 step.URL = "http://example.com"213 step.Assertions = []*Assertion{{214 Source: "response_status",215 Comparison: "equal_number",216 Value: 200,217 }}218 step.Method = "GET"219 step.Body = "foo"220 client := clientConfigure()221 _, err := client.CreateTestStep(step, "foo", "ba")222 if err == nil {223 t.Error("Expected validation error for request with GET method including body")224 }225 if !strings.Contains(err.Error(), "A request test step that specifies a 'GET' method can not include a body property") {226 t.Error("Expected validation error for request GET with included body")227 }228}...

Full Screen

Full Screen

schedule_test.go

Source:schedule_test.go Github

copy

Full Screen

...11 if err != nil {12 t.Error(err)13 }14 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}15 test, err = client.CreateTest(test)16 defer client.DeleteTest(test) // nolint: errcheck17 if err != nil {18 t.Error(err)19 }20 environment := &Environment{21 Name: "tf_environment",22 InitialVariables: map[string]string{23 "VarA": "ValB",24 },25 }26 environment, err = client.CreateTestEnvironment(environment, test)27 if err != nil {28 t.Error(err)29 }30 defer client.DeleteEnvironment(environment, bucket) // nolint: errcheck31 schedule := NewSchedule()32 schedule.Note = "Daily schedule"33 schedule.Interval = "1d"34 schedule.EnvironmentID = environment.ID35 schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)36 defer client.DeleteSchedule(schedule, bucket.Key, test.ID) // nolint: errcheck37 if err != nil {38 t.Error(err)39 }40 if len(schedule.ID) == 0 {41 t.Error("Test schedule id should not be empty")42 }43}44func TestReadSchedule(t *testing.T) {45 testPreCheck(t)46 client := clientConfigure()47 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})48 defer client.DeleteBucket(bucket.Key) // nolint: errcheck49 if err != nil {50 t.Error(err)51 }52 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}53 test, err = client.CreateTest(test)54 defer client.DeleteTest(test) // nolint: errcheck55 if err != nil {56 t.Error(err)57 }58 environment := &Environment{59 Name: "tf_environment",60 InitialVariables: map[string]string{61 "VarA": "ValB",62 },63 }64 environment, err = client.CreateTestEnvironment(environment, test)65 if err != nil {66 t.Error(err)67 }68 defer client.DeleteEnvironment(environment, bucket) // nolint: errcheck69 schedule := NewSchedule()70 schedule.Note = "Daily schedule"71 schedule.Interval = "1d"72 schedule.EnvironmentID = environment.ID73 schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)74 defer client.DeleteSchedule(schedule, bucket.Key, test.ID) // nolint: errcheck75 if err != nil {76 t.Error(err)77 }78 readSchedule, err := client.ReadSchedule(schedule, bucket.Key, test.ID)79 if err != nil {80 t.Error(err)81 }82 if len(readSchedule.ID) == 0 {83 t.Error("Test schedule id should not be empty")84 }85 if readSchedule.ID != schedule.ID {86 t.Errorf("Expected schedule ID %s, actual %s", schedule.ID, readSchedule.ID)87 }88 if readSchedule.Note != schedule.Note {89 t.Errorf("Expected schedule note %s, actual %s", schedule.Note, readSchedule.Note)90 }91}92func TestUpdateSchedule(t *testing.T) {93 testPreCheck(t)94 client := clientConfigure()95 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})96 defer client.DeleteBucket(bucket.Key) // nolint: errcheck97 if err != nil {98 t.Error(err)99 }100 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}101 test, err = client.CreateTest(test)102 defer client.DeleteTest(test) // nolint: errcheck103 if err != nil {104 t.Error(err)105 }106 environment := &Environment{107 Name: "tf_environment",108 InitialVariables: map[string]string{109 "VarA": "ValB",110 },111 }112 environment, err = client.CreateTestEnvironment(environment, test)113 if err != nil {114 t.Error(err)115 }116 defer client.DeleteEnvironment(environment, bucket) // nolint: errcheck117 schedule := NewSchedule()118 schedule.Note = "Daily schedule"119 schedule.Interval = "1d"120 schedule.EnvironmentID = environment.ID121 schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)122 defer client.DeleteSchedule(schedule, bucket.Key, test.ID) // nolint: errcheck123 if err != nil {124 t.Error(err)125 }126 schedule.Note = "Updated note field"127 _, err = client.UpdateSchedule(schedule, bucket.Key, test.ID)128 if err != nil {129 t.Error(err)130 }131 readSchedule, err := client.ReadSchedule(schedule, bucket.Key, test.ID)132 if err != nil {133 t.Error(err)134 }135 if readSchedule.Note != "Updated note field" {136 t.Errorf("Expected schedule note %s, actual %s", "Updated note field", readSchedule.Note)137 }138}139func TestDeleteSchedule(t *testing.T) {140 testPreCheck(t)141 client := clientConfigure()142 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})143 defer client.DeleteBucket(bucket.Key) // nolint: errcheck144 if err != nil {145 t.Error(err)146 }147 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}148 test, err = client.CreateTest(test)149 defer client.DeleteTest(test) // nolint: errcheck150 if err != nil {151 t.Error(err)152 }153 environment := &Environment{154 Name: "tf_environment",155 InitialVariables: map[string]string{156 "VarA": "ValB",157 },158 }159 environment, err = client.CreateTestEnvironment(environment, test)160 if err != nil {161 t.Error(err)162 }163 defer client.DeleteEnvironment(environment, bucket) // nolint: errcheck164 schedule := NewSchedule()165 schedule.Note = "Daily schedule"166 schedule.Interval = "1d"167 schedule.EnvironmentID = environment.ID168 schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)169 if err != nil {170 t.Error(err)171 }172 err = client.DeleteSchedule(schedule, bucket.Key, test.ID)173 if err != nil {174 t.Error(err)175 }176 _, err = client.ReadSchedule(schedule, bucket.Key, test.ID)177 if err == nil {178 t.Error("Should not have found test schedule after deleting it")179 }180 if !strings.Contains(err.Error(), "404 Not Found") {181 t.Errorf("Expected error to contain %s, actual %s", "404 Not Found", err.Error())182 }183}184func TestListSchedules(t *testing.T) {185 testPreCheck(t)186 client := clientConfigure()187 bucket, err := client.CreateBucket(&Bucket{Name: "test", Team: &Team{ID: teamID}})188 defer client.DeleteBucket(bucket.Key) // nolint: errcheck189 if err != nil {190 t.Error(err)191 }192 test := &Test{Name: "tf_test", Description: "This is a tf test", Bucket: bucket}193 test, err = client.CreateTest(test)194 defer client.DeleteTest(test) // nolint: errcheck195 if err != nil {196 t.Error(err)197 }198 environment := &Environment{199 Name: "tf_environment",200 InitialVariables: map[string]string{201 "VarA": "ValB",202 },203 }204 environment, err = client.CreateTestEnvironment(environment, test)205 if err != nil {206 t.Error(err)207 }208 defer client.DeleteEnvironment(environment, bucket) // nolint: errcheck209 schedule := NewSchedule()210 schedule.Note = "Hourly schedule"211 schedule.Interval = "1h"212 schedule.EnvironmentID = environment.ID213 schedule, err = client.CreateSchedule(schedule, bucket.Key, test.ID)214 defer client.DeleteSchedule(schedule, bucket.Key, test.ID) // nolint: errcheck215 if err != nil {216 t.Error(err)217 }218 schedules, err := client.ListSchedules(bucket.Key, test.ID)...

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello I'm a client")4 cc, err := grpc.Dial("localhost:50051", grpc.WithInsecure())5 if err != nil {6 log.Fatalf("could not connect: %v", err)7 }8 defer cc.Close()9 c := calculatorpb.NewCalculatorServiceClient(cc)10 doClientStreaming(c)11}12func doUnary(c calculatorpb.CalculatorServiceClient) {13 fmt.Println("Starting to do a Unary RPC...")14 req := &calculatorpb.SumRequest{15 }16 res, err := c.Sum(context.Background(), req)17 if err != nil {18 log.Fatalf("error while calling Sum RPC: %v", err)19 }20 log.Printf("Response from Sum: %v", res.SumResult)21}22func doServerStreaming(c calculatorpb.CalculatorServiceClient) {23 fmt.Println("Starting to do a Server Streaming RPC...")24 req := &calculatorpb.PrimeNumberDecompositionRequest{25 }26 resStream, err := c.PrimeNumberDecomposition(context.Background(), req)27 if err != nil {28 log.Fatalf("error while calling PrimeNumberDecomposition RPC: %v", err)29 }30 for {31 msg, err := resStream.Recv()32 if err == io.EOF {33 }34 if err != nil {35 log.Fatalf("error while reading stream: %v", err)36 }37 log.Printf("Response from PrimeNumberDecomposition: %v", msg.GetPrimeFactor())38 }39}40func doClientStreaming(c calculatorpb.CalculatorServiceClient) {41 fmt.Println("Starting to do a Client Streaming RPC...")42 requests := []*calculatorpb.ComputeAverageRequest{43 &calculatorpb.ComputeAverageRequest{44 },45 &calculatorpb.ComputeAverageRequest{46 },

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := test.CreateTest()4 fmt.Println(client)5}6import (7func main() {8 client := test.CreateTest()9 fmt.Println(client)10}11import (12func main() {13 client := test.CreateTest()14 fmt.Println(client)15}16import (17func main() {18 client := test.CreateTest()19 fmt.Println(client)20}21import (22func main() {23 client := test.CreateTest()24 fmt.Println(client)25}26import (27func main() {28 client := test.CreateTest()29 fmt.Println(client)30}31import (32func main() {33 client := test.CreateTest()34 fmt.Println(client)35}36import (37func main() {38 client := test.CreateTest()39 fmt.Println(client)40}41import (42func main() {43 client := test.CreateTest()44 fmt.Println(client)45}46import (47func main() {48 client := test.CreateTest()49 fmt.Println(client)50}51import (52func main() {53 client := test.CreateTest()54 fmt.Println(client)55}

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Client struct {3}4func (c *Client) CreateTest() {5 fmt.Println("Client: Create Test")6}7func main() {8 client := new(Client)9 client.CreateTest()10}11import "fmt"12type Client struct {13}14func (c *Client) CreateTest() {15 fmt.Println("Client: Create Test")16}17func main() {18 client := new(Client)19 client.CreateTest()20}21import "fmt"22type Client struct {23}24func (c *Client) CreateTest() {25 fmt.Println("Client: Create Test")26}27func main() {28 client := new(Client)29 client.CreateTest()30}31import "fmt"32type Client struct {33}34func (c *Client) CreateTest() {35 fmt.Println("Client: Create Test")36}37func main() {38 client := new(Client)39 client.CreateTest()40}41import "fmt"42type Client struct {43}44func (c *Client) CreateTest() {45 fmt.Println("Client: Create Test")46}47func main() {48 client := new(Client)49 client.CreateTest()50}51import "fmt"52type Client struct {53}54func (c *Client) CreateTest() {55 fmt.Println("Client: Create Test")56}57func main() {58 client := new(Client)59 client.CreateTest()60}61import "fmt"62type Client struct {63}64func (c *Client) CreateTest() {65 fmt.Println("Client: Create Test")66}67func main() {68 client := new(Client)69 client.CreateTest()70}71import "fmt"72type Client struct {73}74func (c *Client) CreateTest() {75 fmt.Println("Client: Create Test")76}77func main() {78 client := new(Client)79 client.CreateTest()80}

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c.CreateTest()4 fmt.Println("Hello World")5}6import (7func main() {8 c.CreateTest()9 fmt.Println("Hello World")10}11import (12func main() {13 c.CreateTest()14 fmt.Println("Hello World")15}16import (17func main() {18 c.CreateTest()19 fmt.Println("Hello World")20}21import (22func main() {23 c.CreateTest()24 fmt.Println("Hello World")25}26import (27func main() {28 c.CreateTest()29 fmt.Println("Hello World")30}31import (32func main() {33 c.CreateTest()34 fmt.Println("Hello World")35}36import (37func main() {38 c.CreateTest()39 fmt.Println("Hello World")40}41import (42func main() {43 c.CreateTest()44 fmt.Println("Hello World")45}46import (47func main() {48 c.CreateTest()49 fmt.Println("Hello World")50}

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client := grpcClient.Client{}4 client.CreateTest()5 fmt.Println("Created Test")6}7import (8func main() {9 client := grpcClient.Client{}10 client.GetTest()11 fmt.Println("Got Test")12}13import (14func main() {15 client := grpcClient.Client{}16 client.UpdateTest()17 fmt.Println("Updated Test")18}19import (20func main() {21 client := grpcClient.Client{}22 client.DeleteTest()23 fmt.Println("Deleted Test")24}25import (26func main() {27 client := grpcClient.Client{}28 client.ListTest()29 fmt.Println("Listed Test")30}31import (32func main() {33 client := grpcClient.Client{}34 client.WatchTest()35 fmt.Println("Watched Test")36}37import (38func main() {39 client := grpcClient.Client{}40 client.WatchTest()41 fmt.Println("Watched Test")42}43import (44func main() {45 client := grpcClient.Client{}46 client.WatchTest()47 fmt.Println("Watched Test")48}49import (50func main() {51 client := grpcClient.Client{}52 client.WatchTest()53 fmt.Println("Watched Test")54}55import (

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 client.CreateTest()4 fmt.Println("Hello World!")5}6import (7func main() {8 client.CreateTest()9 fmt.Println("Hello World!")10}11import (12func main() {13 client.CreateTest()14 fmt.Println("Hello World!")15}16import (17func main() {18 client.CreateTest()19 fmt.Println("Hello World!")20}21import (22func main() {23 client.CreateTest()24 fmt.Println("Hello World!")25}26import (27func main() {28 client.CreateTest()29 fmt.Println("Hello World!")30}31import (32func main() {33 client.CreateTest()34 fmt.Println("Hello World!")35}36import (37func main() {38 client.CreateTest()39 fmt.Println("Hello World!")40}41import (42func main() {43 client.CreateTest()

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var client = client.CreateTest()4 fmt.Println(client)5}6type Client struct {7}8func CreateTest() Client {9 var client = Client{Name: "test"}10}

Full Screen

Full Screen

CreateTest

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 c := Client.Client{}4 c.CreateTest()5 fmt.Println("Client created")6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful