github.com/goplus/yap@v0.8.1/ytest/demo/_example/gop_autogen_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/goplus/yap/ytest"
     6  	"testing"
     7  )
     8  
     9  type case_example struct {
    10  	ytest.Case
    11  }
    12  //line ytest/demo/_example/example_ytest.gox:1
    13  func (this *case_example) Main() {
    14  //line ytest/demo/_example/example_ytest.gox:1:1
    15  	this.Host("https://example.com", "http://localhost:8080")
    16  //line ytest/demo/_example/example_ytest.gox:2:1
    17  	testauth := ytest.Oauth2("...")
    18  //line ytest/demo/_example/example_ytest.gox:4:1
    19  	this.DefaultHeader.Set("User-Agent", "yaptest/0.7")
    20  //line ytest/demo/_example/example_ytest.gox:6:1
    21  	this.Run("urlWithVar", func() {
    22  //line ytest/demo/_example/example_ytest.gox:7:1
    23  		id := "123"
    24  //line ytest/demo/_example/example_ytest.gox:8:1
    25  		this.Get("https://example.com/p/" + id)
    26  //line ytest/demo/_example/example_ytest.gox:9:1
    27  		this.Send()
    28  //line ytest/demo/_example/example_ytest.gox:10:1
    29  		fmt.Println("code:", this.Resp().Code())
    30  //line ytest/demo/_example/example_ytest.gox:11:1
    31  		fmt.Println("body:", this.Resp().Body())
    32  	})
    33  //line ytest/demo/_example/example_ytest.gox:14:1
    34  	this.Run("matchWithVar", func() {
    35  //line ytest/demo/_example/example_ytest.gox:15:1
    36  		code := ytest.Gopx_Var_Cast__0[int]()
    37  //line ytest/demo/_example/example_ytest.gox:16:1
    38  		id := "123"
    39  //line ytest/demo/_example/example_ytest.gox:17:1
    40  		this.Get("https://example.com/p/" + id)
    41  //line ytest/demo/_example/example_ytest.gox:18:1
    42  		this.RetWith(code)
    43  //line ytest/demo/_example/example_ytest.gox:19:1
    44  		fmt.Println("code:", code)
    45  //line ytest/demo/_example/example_ytest.gox:20:1
    46  		ytest.Match__4(code, 200)
    47  	})
    48  //line ytest/demo/_example/example_ytest.gox:23:1
    49  	this.Run("postWithAuth", func() {
    50  //line ytest/demo/_example/example_ytest.gox:24:1
    51  		id := "123"
    52  //line ytest/demo/_example/example_ytest.gox:25:1
    53  		title := "title"
    54  //line ytest/demo/_example/example_ytest.gox:26:1
    55  		author := "author"
    56  //line ytest/demo/_example/example_ytest.gox:27:1
    57  		this.Post("https://example.com/p/" + id)
    58  //line ytest/demo/_example/example_ytest.gox:28:1
    59  		this.Auth(testauth)
    60  //line ytest/demo/_example/example_ytest.gox:29:1
    61  		this.Json(map[string]string{"title": title, "author": author})
    62  //line ytest/demo/_example/example_ytest.gox:33:1
    63  		this.RetWith(200)
    64  //line ytest/demo/_example/example_ytest.gox:34:1
    65  		fmt.Println("body:", this.Resp().Body())
    66  	})
    67  //line ytest/demo/_example/example_ytest.gox:37:1
    68  	this.Run("matchJsonObject", func() {
    69  //line ytest/demo/_example/example_ytest.gox:38:1
    70  		title := ytest.Gopx_Var_Cast__0[string]()
    71  //line ytest/demo/_example/example_ytest.gox:39:1
    72  		author := ytest.Gopx_Var_Cast__0[string]()
    73  //line ytest/demo/_example/example_ytest.gox:40:1
    74  		id := "123"
    75  //line ytest/demo/_example/example_ytest.gox:41:1
    76  		this.Get("https://example.com/p/" + id)
    77  //line ytest/demo/_example/example_ytest.gox:42:1
    78  		this.RetWith(200)
    79  //line ytest/demo/_example/example_ytest.gox:43:1
    80  		this.Json(map[string]*ytest.Var__0[string]{"title": title, "author": author})
    81  //line ytest/demo/_example/example_ytest.gox:47:1
    82  		fmt.Println("title:", title)
    83  //line ytest/demo/_example/example_ytest.gox:48:1
    84  		fmt.Println("author:", author)
    85  	})
    86  }
    87  func Test_example(t *testing.T) {
    88  	ytest.Gopt_Case_TestMain(new(case_example), t)
    89  }