github.com/go-spring/spring-base@v1.1.3/log/log_reader_test.go (about)

     1  /*
     2   * Copyright 2012-2019 the original author or authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *      https://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package log_test
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/go-spring/spring-base/assert"
    23  	"github.com/go-spring/spring-base/log"
    24  )
    25  
    26  func TestXMLReader(t *testing.T) {
    27  	r := &log.XMLReader{}
    28  	b := `<Configuration>
    29  		<Appenders>
    30  			<Console name="Console">
    31  				<LevelFilter level="warn"/>
    32  			</Console>
    33  		</Appenders>
    34  		<Loggers>
    35  			<Logger name="spring/spring-base/log_test" level="debug">
    36  				<AppenderRef ref="Console">
    37  					<Filters>
    38  						<LevelFilter level="info"/>
    39  					</Filters>
    40  				</AppenderRef>
    41  			</Logger>
    42  			<Root level="debug">
    43  				<LevelFilter level="info"/>
    44  				<AppenderRef ref="Console"/>
    45  			</Root>
    46  		</Loggers>
    47  	</Configuration>`
    48  	node, err := r.Read([]byte(b))
    49  	if err != nil {
    50  		t.Fatal(err)
    51  	}
    52  	assert.Equal(t, node, &log.Node{
    53  		Label:      "Configuration",
    54  		Attributes: map[string]string{},
    55  		Children: []*log.Node{
    56  			{
    57  				Label:      "Appenders",
    58  				Attributes: map[string]string{},
    59  				Children: []*log.Node{
    60  					{
    61  						Label: "Console",
    62  						Attributes: map[string]string{
    63  							"name": "Console",
    64  						},
    65  						Children: []*log.Node{
    66  							{
    67  								Label: "LevelFilter",
    68  								Attributes: map[string]string{
    69  									"level": "warn",
    70  								},
    71  							},
    72  						},
    73  					},
    74  				},
    75  			},
    76  			{
    77  				Label:      "Loggers",
    78  				Attributes: map[string]string{},
    79  				Children: []*log.Node{
    80  					{
    81  						Label: "Logger",
    82  						Attributes: map[string]string{
    83  							"name":  "spring/spring-base/log_test",
    84  							"level": "debug",
    85  						},
    86  						Children: []*log.Node{
    87  							{
    88  								Label: "AppenderRef",
    89  								Attributes: map[string]string{
    90  									"ref": "Console",
    91  								},
    92  								Children: []*log.Node{
    93  									{
    94  										Label:      "Filters",
    95  										Attributes: map[string]string{},
    96  										Children: []*log.Node{
    97  											{
    98  												Label: "LevelFilter",
    99  												Attributes: map[string]string{
   100  													"level": "info",
   101  												},
   102  											},
   103  										},
   104  									},
   105  								},
   106  							},
   107  						},
   108  					},
   109  					{
   110  						Label: "Root",
   111  						Attributes: map[string]string{
   112  							"level": "debug",
   113  						},
   114  						Children: []*log.Node{
   115  							{
   116  								Label: "LevelFilter",
   117  								Attributes: map[string]string{
   118  									"level": "info",
   119  								},
   120  							},
   121  							{
   122  								Label: "AppenderRef",
   123  								Attributes: map[string]string{
   124  									"ref": "Console",
   125  								},
   126  							},
   127  						},
   128  					},
   129  				},
   130  			},
   131  		},
   132  	})
   133  }