github.com/yandex/pandora@v0.5.32/components/providers/scenario/config/hcl_test.go (about)

     1  package config
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/spf13/afero"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  	"github.com/yandex/pandora/lib/pointer"
    10  )
    11  
    12  func TestParseHCLFile(t *testing.T) {
    13  	fs := afero.NewOsFs()
    14  
    15  	t.Run("http", func(t *testing.T) {
    16  		file, err := fs.Open("../testdata/http_payload.hcl")
    17  		require.NoError(t, err)
    18  		defer file.Close()
    19  
    20  		ammoHCL, err := ParseHCLFile(file)
    21  		require.NoError(t, err)
    22  
    23  		assert.Len(t, ammoHCL.Scenarios, 2)
    24  		assert.Equal(t, ammoHCL.Scenarios[0], ScenarioHCL{
    25  			Name:           "scenario_name",
    26  			Weight:         pointer.ToInt64(50),
    27  			MinWaitingTime: pointer.ToInt64(10),
    28  			Requests:       []string{"auth_req(1)", "sleep(100)", "list_req(1)", "sleep(100)", "order_req(3)"},
    29  		})
    30  		assert.Equal(t, ammoHCL.Scenarios[1], ScenarioHCL{
    31  			Name:           "scenario_2",
    32  			Weight:         nil,
    33  			MinWaitingTime: nil,
    34  			Requests:       []string{"auth_req(1)", "sleep(100)", "list_req(1)", "sleep(100)", "order_req(2)"},
    35  		})
    36  		assert.Len(t, ammoHCL.VariableSources, 3)
    37  		assert.Equal(t, ammoHCL.VariableSources[2], SourceHCL{
    38  			Name:      "variables",
    39  			Type:      "variables",
    40  			Variables: &(map[string]string{"header": "yandex", "b": "s"})})
    41  	})
    42  
    43  	t.Run("grpc", func(t *testing.T) {
    44  		file, err := fs.Open("../testdata/grpc_payload.hcl")
    45  		require.NoError(t, err)
    46  		defer file.Close()
    47  
    48  		ammoHCL, err := ParseHCLFile(file)
    49  		require.NoError(t, err)
    50  
    51  		assert.Len(t, ammoHCL.Scenarios, 2)
    52  		assert.Equal(t, ammoHCL.Scenarios[0], ScenarioHCL{
    53  			Name:           "scenario_name",
    54  			Weight:         pointer.ToInt64(50),
    55  			MinWaitingTime: pointer.ToInt64(10),
    56  			Requests:       []string{"auth_req(1)", "sleep(100)", "list_req(1)", "sleep(100)", "order_req(3)"},
    57  		})
    58  		assert.Equal(t, ammoHCL.Scenarios[1], ScenarioHCL{
    59  			Name:           "scenario_2",
    60  			Weight:         nil,
    61  			MinWaitingTime: nil,
    62  			Requests:       []string{"auth_req(1)", "sleep(100)", "list_req(1)", "sleep(100)", "order_req(2)"},
    63  		})
    64  		assert.Len(t, ammoHCL.VariableSources, 3)
    65  		assert.Equal(t, ammoHCL.VariableSources[2], SourceHCL{
    66  			Name:      "variables",
    67  			Type:      "variables",
    68  			Variables: &(map[string]string{"header": "yandex", "b": "s"})})
    69  	})
    70  }