|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestRequest_GetBase(t *testing.T) { |
| 8 | + type fields struct { |
| 9 | + baseUrl string |
| 10 | + } |
| 11 | + tests := []struct { |
| 12 | + name string |
| 13 | + fields fields |
| 14 | + path string |
| 15 | + want string |
| 16 | + }{ |
| 17 | + { |
| 18 | + name: "Test base url ends with /, path starts with /", |
| 19 | + fields: fields{ |
| 20 | + baseUrl: "https://api.example.com/", |
| 21 | + }, |
| 22 | + path: "/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 23 | + want: "https://api.example.com/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 24 | + }, |
| 25 | + { |
| 26 | + name: "Test only base url ends with /", |
| 27 | + fields: fields{ |
| 28 | + baseUrl: "https://api.example.com/", |
| 29 | + }, |
| 30 | + path: "v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 31 | + want: "https://api.example.com/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "Test only path starts with /", |
| 35 | + fields: fields{ |
| 36 | + baseUrl: "https://api.example.com", |
| 37 | + }, |
| 38 | + path: "/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 39 | + want: "https://api.example.com/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 40 | + }, |
| 41 | + { |
| 42 | + name: "Test none /", |
| 43 | + fields: fields{ |
| 44 | + baseUrl: "https://api.example.com", |
| 45 | + }, |
| 46 | + path: "v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 47 | + want: "https://api.example.com/v1/account/0x32Be343B94f860124dC4fEe278FDCBD38C102D88", |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "Test empty path", |
| 51 | + fields: fields{ |
| 52 | + baseUrl: "https://api.example.com/", |
| 53 | + }, |
| 54 | + path: "", |
| 55 | + want: "https://api.example.com", |
| 56 | + }, |
| 57 | + } |
| 58 | + for _, tt := range tests { |
| 59 | + t.Run(tt.name, func(t *testing.T) { |
| 60 | + r := InitClient(tt.fields.baseUrl) |
| 61 | + if got := r.GetBase(tt.path); got != tt.want { |
| 62 | + t.Errorf("Request.GetBase() = %v, want %v", got, tt.want) |
| 63 | + } |
| 64 | + }) |
| 65 | + } |
| 66 | +} |
0 commit comments