github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/app_copyServer_test.go (about)

     1  // Copyright 2017-present Kirill Danshin and Gramework contributors
     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  
    10  package gramework
    11  
    12  import (
    13  	"reflect"
    14  	"testing"
    15  )
    16  
    17  var fieldList = []string{
    18  	"Handler",
    19  	"Name",
    20  	"Concurrency",
    21  	"DisableKeepalive",
    22  	"ReadBufferSize",
    23  	"WriteBufferSize",
    24  	"ReadTimeout",
    25  	"WriteTimeout",
    26  	"MaxConnsPerIP",
    27  	"MaxRequestsPerConn",
    28  	"MaxKeepaliveDuration",
    29  	"MaxRequestBodySize",
    30  	"ReduceMemoryUsage",
    31  	"GetOnly",
    32  	"LogAllErrors",
    33  	"DisableHeaderNamesNormalizing",
    34  	"Logger",
    35  }
    36  
    37  func compareField(t *testing.T, act, exp interface{}, field string) {
    38  	actVal := reflect.Indirect(reflect.ValueOf(act)).FieldByName(field)
    39  	expVal := reflect.Indirect(reflect.ValueOf(act)).FieldByName(field)
    40  	if actVal != expVal {
    41  		t.Errorf("field %s of app copy has value %v, but expected %v", field, actVal, expVal)
    42  	}
    43  }
    44  
    45  func TestAppCopyServer(t *testing.T) {
    46  	app := New()
    47  
    48  	serverCopy := app.copyServer()
    49  
    50  	for _, field := range fieldList {
    51  		compareField(t, serverCopy, app.serverBase, field)
    52  	}
    53  }