...

Source file src/github.com/growthbook/growthbook-golang/feature_api_response_test.go

Documentation: github.com/growthbook/growthbook-golang

     1  package growthbook
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  )
     7  
     8  const jsonData = `{
     9    "status": 200,
    10    "features": {
    11      "banner_text": {
    12        "defaultValue": "Welcome to Acme Donuts!",
    13        "rules": [
    14          {
    15            "condition": {
    16              "country": "france"
    17            },
    18            "force": "Bienvenue au Beignets Acme !"
    19          },
    20          {
    21            "condition": {
    22              "country": "spain"
    23            },
    24            "force": "¡Bienvenidos y bienvenidas a Donas Acme!"
    25          }
    26        ]
    27      },
    28      "dark_mode": {
    29        "defaultValue": false,
    30        "rules": [
    31          {
    32            "condition": {
    33              "loggedIn": true
    34            },
    35            "force": true,
    36            "coverage": 0.5,
    37            "hashAttribute": "id"
    38          }
    39        ]
    40      },
    41      "donut_price": {
    42        "defaultValue": 2.5,
    43        "rules": [
    44          {
    45            "condition": {
    46              "employee": true
    47            },
    48            "force": 0
    49          }
    50        ]
    51      },
    52      "meal_overrides_gluten_free": {
    53        "defaultValue": {
    54          "meal_type": "standard",
    55          "dessert": "Strawberry Cheesecake"
    56        },
    57        "rules": [
    58          {
    59            "condition": {
    60              "dietaryRestrictions": {
    61                "$elemMatch": {
    62                  "$eq": "gluten_free"
    63                }
    64              }
    65            },
    66            "force": {
    67              "meal_type": "gf",
    68              "dessert": "French Vanilla Ice Cream"
    69            }
    70          }
    71        ]
    72      },
    73      "app_name": {
    74        "defaultValue": "(unknown)",
    75        "rules": [
    76          {
    77            "condition": {
    78              "version": {
    79                "$vgte": "1.0.0",
    80                "$vlt": "2.0.0"
    81              }
    82            },
    83            "force": "Albatross"
    84          },
    85          {
    86            "condition": {
    87              "version": {
    88                "$vgte": "2.0.0",
    89                "$vlt": "3.0.0"
    90              }
    91            },
    92            "force": "Badger"
    93          },
    94          {
    95            "condition": {
    96              "version": {
    97                "$vgte": "3.0.0",
    98                "$vlt": "4.0.0"
    99              }
   100            },
   101            "force": "Capybara"
   102          }
   103        ]
   104      }
   105    },
   106    "dateUpdated": "2023-06-27T18:10:13.378Z"
   107  }`
   108  
   109  func TestAPIResponseParsing(t *testing.T) {
   110  	apiResponse := FeatureAPIResponse{}
   111  	err := json.Unmarshal([]byte(jsonData), &apiResponse)
   112  	if err != nil {
   113  		t.Errorf("failed to parse API response data")
   114  	}
   115  }
   116  

View as plain text