...

Source file src/github.com/go-openapi/runtime/middleware/ui_options_test.go

Documentation: github.com/go-openapi/runtime/middleware

     1  package middleware
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestConvertOptions(t *testing.T) {
    10  	t.Run("from any UI options to uiOptions", func(t *testing.T) {
    11  		t.Run("from RedocOpts", func(t *testing.T) {
    12  			in := RedocOpts{
    13  				BasePath: "a",
    14  				Path:     "b",
    15  				SpecURL:  "c",
    16  				Template: "d",
    17  				Title:    "e",
    18  				RedocURL: "f",
    19  			}
    20  			out := toCommonUIOptions(in)
    21  
    22  			require.Equal(t, "a", out.BasePath)
    23  			require.Equal(t, "b", out.Path)
    24  			require.Equal(t, "c", out.SpecURL)
    25  			require.Equal(t, "d", out.Template)
    26  			require.Equal(t, "e", out.Title)
    27  		})
    28  
    29  		t.Run("from RapiDocOpts", func(t *testing.T) {
    30  			in := RapiDocOpts{
    31  				BasePath:   "a",
    32  				Path:       "b",
    33  				SpecURL:    "c",
    34  				Template:   "d",
    35  				Title:      "e",
    36  				RapiDocURL: "f",
    37  			}
    38  			out := toCommonUIOptions(in)
    39  
    40  			require.Equal(t, "a", out.BasePath)
    41  			require.Equal(t, "b", out.Path)
    42  			require.Equal(t, "c", out.SpecURL)
    43  			require.Equal(t, "d", out.Template)
    44  			require.Equal(t, "e", out.Title)
    45  		})
    46  
    47  		t.Run("from SwaggerUIOpts", func(t *testing.T) {
    48  			in := SwaggerUIOpts{
    49  				BasePath:   "a",
    50  				Path:       "b",
    51  				SpecURL:    "c",
    52  				Template:   "d",
    53  				Title:      "e",
    54  				SwaggerURL: "f",
    55  			}
    56  			out := toCommonUIOptions(in)
    57  
    58  			require.Equal(t, "a", out.BasePath)
    59  			require.Equal(t, "b", out.Path)
    60  			require.Equal(t, "c", out.SpecURL)
    61  			require.Equal(t, "d", out.Template)
    62  			require.Equal(t, "e", out.Title)
    63  		})
    64  	})
    65  
    66  	t.Run("from uiOptions to any UI options", func(t *testing.T) {
    67  		in := uiOptions{
    68  			BasePath: "a",
    69  			Path:     "b",
    70  			SpecURL:  "c",
    71  			Template: "d",
    72  			Title:    "e",
    73  		}
    74  
    75  		t.Run("to RedocOpts", func(t *testing.T) {
    76  			var out RedocOpts
    77  			fromCommonToAnyOptions(in, &out)
    78  			require.Equal(t, "a", out.BasePath)
    79  			require.Equal(t, "b", out.Path)
    80  			require.Equal(t, "c", out.SpecURL)
    81  			require.Equal(t, "d", out.Template)
    82  			require.Equal(t, "e", out.Title)
    83  		})
    84  
    85  		t.Run("to RapiDocOpts", func(t *testing.T) {
    86  			var out RapiDocOpts
    87  			fromCommonToAnyOptions(in, &out)
    88  			require.Equal(t, "a", out.BasePath)
    89  			require.Equal(t, "b", out.Path)
    90  			require.Equal(t, "c", out.SpecURL)
    91  			require.Equal(t, "d", out.Template)
    92  			require.Equal(t, "e", out.Title)
    93  		})
    94  
    95  		t.Run("to SwaggerUIOpts", func(t *testing.T) {
    96  			var out SwaggerUIOpts
    97  			fromCommonToAnyOptions(in, &out)
    98  			require.Equal(t, "a", out.BasePath)
    99  			require.Equal(t, "b", out.Path)
   100  			require.Equal(t, "c", out.SpecURL)
   101  			require.Equal(t, "d", out.Template)
   102  			require.Equal(t, "e", out.Title)
   103  		})
   104  	})
   105  }
   106  

View as plain text