github.com/greenpau/go-authcrunch@v1.1.4/pkg/authn/icons/icon_test.go (about)

     1  // Copyright 2022 Paul Greenberg greenpau@outlook.com
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package icons
    16  
    17  import (
    18  	"fmt"
    19  	"github.com/greenpau/go-authcrunch/internal/tests"
    20  	// "github.com/greenpau/go-authcrunch/pkg/errors"
    21  	"testing"
    22  )
    23  
    24  func TestParse(t *testing.T) {
    25  	testcases := []struct {
    26  		name      string
    27  		input     []string
    28  		want      map[string]interface{}
    29  		shouldErr bool
    30  		err       error
    31  	}{
    32  		{
    33  			name:  "text only",
    34  			input: []string{"Okta"},
    35  			want: map[string]interface{}{
    36  				"text": "Okta",
    37  			},
    38  		},
    39  		{
    40  			name:  "text with priority",
    41  			input: []string{"Okta", "priority", "100"},
    42  			want: map[string]interface{}{
    43  				"text":     "Okta",
    44  				"priority": float64(100),
    45  			},
    46  		},
    47  
    48  		{
    49  			name:  "text with priority and icon class name",
    50  			input: []string{"Okta", "lab la-gitlab la-2x", "priority", "100"},
    51  			want: map[string]interface{}{
    52  				"text":       "Okta",
    53  				"priority":   float64(100),
    54  				"class_name": "lab la-gitlab la-2x",
    55  			},
    56  		},
    57  		{
    58  			name:  "text with priority and icon class name, color",
    59  			input: []string{"Okta", "lab la-gitlab la-2x", "green", "priority", "100"},
    60  			want: map[string]interface{}{
    61  				"text":       "Okta",
    62  				"priority":   float64(100),
    63  				"class_name": "lab la-gitlab la-2x",
    64  				"color":      "green",
    65  			},
    66  		},
    67  		{
    68  			name:  "text with priority and icon class name, color, background color",
    69  			input: []string{"Okta", "lab la-gitlab la-2x", "green", "brown", "priority", "100"},
    70  			want: map[string]interface{}{
    71  				"text":             "Okta",
    72  				"priority":         float64(100),
    73  				"class_name":       "lab la-gitlab la-2x",
    74  				"color":            "green",
    75  				"background_color": "brown",
    76  			},
    77  		},
    78  		{
    79  			name:  "text with priority, icon class name/color/background color, text color",
    80  			input: []string{"Okta", "lab la-gitlab la-2x", "green", "brown", "priority", "100", "text", "white", "blue"},
    81  			want: map[string]interface{}{
    82  				"text":                  "Okta",
    83  				"priority":              float64(100),
    84  				"class_name":            "lab la-gitlab la-2x",
    85  				"color":                 "green",
    86  				"background_color":      "brown",
    87  				"text_color":            "white",
    88  				"text_background_color": "blue",
    89  			},
    90  		},
    91  		/*
    92  			{
    93  				name: "test invalid config",
    94  				shouldErr: true,
    95  				err:       fmt.Errorf("TBD"),
    96  			},
    97  		*/
    98  	}
    99  	for _, tc := range testcases {
   100  		t.Run(tc.name, func(t *testing.T) {
   101  			got := make(map[string]interface{})
   102  			msgs := []string{fmt.Sprintf("test name: %s", tc.name)}
   103  			msgs = append(msgs, fmt.Sprintf("input:\n%v", tc.input))
   104  
   105  			got, err := Parse(tc.input)
   106  			if tests.EvalErrWithLog(t, err, "Parse", tc.shouldErr, tc.err, msgs) {
   107  				return
   108  			}
   109  
   110  			tests.EvalObjectsWithLog(t, "Icon", tc.want, got, msgs)
   111  		})
   112  	}
   113  }