github.com/getgauge/gauge@v1.6.9/config/formatter_test.go (about) 1 /*---------------------------------------------------------------- 2 * Copyright (c) ThoughtWorks, Inc. 3 * Licensed under the Apache License, Version 2.0 4 * See LICENSE in the project root for license information. 5 *----------------------------------------------------------------*/ 6 7 package config 8 9 import ( 10 "sort" 11 "strings" 12 "testing" 13 ) 14 15 func TestJSONFormatter(t *testing.T) { 16 want := []string{ 17 "------------------------------------------------------------------", 18 "Key Value ", 19 "allow_insecure_download false ", 20 "check_updates true ", 21 "gauge_repository_url https://downloads.gauge.org/plugin ", 22 "ide_request_timeout 30000 ", 23 "plugin_connection_timeout 10000 ", 24 "plugin_kill_timeout 4000 ", 25 "runner_connection_timeout 30000 ", 26 "runner_request_timeout 30000 ", 27 } 28 p := defaults() 29 var properties []Property 30 for _, p := range p.p { 31 properties = append(properties, *p) 32 } 33 34 f := &TextFormatter{Headers: []string{"Key", "Value"}} 35 text, err := f.Format(properties) 36 37 if err != nil { 38 t.Errorf("Expected error == nil when using text formatter for properties, got %s", err.Error()) 39 } 40 got := strings.Split(text, "\n") 41 sort.Strings(got) 42 43 if len(got) != len(want) { 44 t.Errorf("Expected %d entries, got %d", len(want), len(got)) 45 } 46 for i, x := range want { 47 if got[i] != x { 48 t.Errorf("Properties text Format failed\nwant: `%s`\ngot: `%s`", x, got[i]) 49 } 50 } 51 }