1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License. See License.txt in the project root for license information.
3
4package model_test
5
6import (
7	"reflect"
8	"strings"
9	"testing"
10
11	"github.com/Azure/azure-sdk-for-go/tools/generator/autorest/model"
12)
13
14func TestNewGenerateOptionsFrom(t *testing.T) {
15	testdata := []struct {
16		input    string
17		expected *model.GenerateOptions
18	}{
19		{
20			input: `{
21  "autorestArguments": [
22    "--use=@microsoft.azure/autorest.go@2.1.178",
23    "--go",
24    "--verbose",
25    "--go-sdk-folder=.",
26    "--multiapi",
27    "--use-onever",
28    "--version=V2",
29    "--go.license-header=MICROSOFT_MIT_NO_VERSION"
30  ],
31  "additionalOptions": [
32    "--enum-prefix"
33  ]
34}`,
35			expected: &model.GenerateOptions{
36				AutorestArguments: []string{
37					"--use=@microsoft.azure/autorest.go@2.1.178",
38					"--go",
39					"--verbose",
40					"--go-sdk-folder=.",
41					"--multiapi",
42					"--use-onever",
43					"--version=V2",
44					"--go.license-header=MICROSOFT_MIT_NO_VERSION",
45				},
46				AdditionalOptions: []string{
47					"--enum-prefix",
48				},
49			},
50		},
51	}
52
53	for _, c := range testdata {
54		options, err := model.NewGenerateOptionsFrom(strings.NewReader(c.input))
55		if err != nil {
56			t.Fatalf("unexpected error: %+v", err)
57		}
58		if !reflect.DeepEqual(*options, *c.expected) {
59			t.Fatalf("expected %+v, but got %+v", *c.expected, *options)
60		}
61	}
62}
63