github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/core/admin_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     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  		 http://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 core
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/golang/protobuf/ptypes/empty"
    24  	"github.com/hyperledger/fabric/common/flogging"
    25  	"github.com/hyperledger/fabric/core/testutil"
    26  	pb "github.com/hyperledger/fabric/protos/peer"
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  var adminServer *ServerAdmin
    31  
    32  func init() {
    33  	adminServer = NewAdminServer()
    34  	testutil.SetupTestConfig()
    35  }
    36  
    37  func TestGetStatus(t *testing.T) {
    38  	response, err := adminServer.GetStatus(context.Background(), &empty.Empty{})
    39  	assert.NotNil(t, response, "Response should have been set")
    40  	assert.Nil(t, err, "Error should have been nil")
    41  }
    42  
    43  func TestStartServer(t *testing.T) {
    44  	response, err := adminServer.StartServer(context.Background(), &empty.Empty{})
    45  	assert.NotNil(t, response, "Response should have been set")
    46  	assert.Nil(t, err, "Error should have been nil")
    47  }
    48  
    49  func TestLoggingCalls(t *testing.T) {
    50  	flogging.MustGetLogger("test")
    51  	flogging.SetPeerStartupModulesMap()
    52  
    53  	logResponse, err := adminServer.GetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test"})
    54  	assert.NotNil(t, logResponse, "logResponse should have been set")
    55  	assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "log level should have been the default")
    56  	assert.Nil(t, err, "Error should have been nil")
    57  
    58  	logResponse, err = adminServer.SetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test", LogLevel: "debug"})
    59  	assert.NotNil(t, logResponse, "logResponse should have been set")
    60  	assert.Equal(t, "DEBUG", logResponse.LogLevel, "log level should have been set to debug")
    61  	assert.Nil(t, err, "Error should have been nil")
    62  
    63  	_, err = adminServer.RevertLogLevels(context.Background(), &empty.Empty{})
    64  	assert.Nil(t, err, "Error should have been nil")
    65  
    66  	logResponse, err = adminServer.GetModuleLogLevel(context.Background(), &pb.LogLevelRequest{LogModule: "test"})
    67  	assert.NotNil(t, logResponse, "logResponse should have been set")
    68  	assert.Equal(t, flogging.DefaultLevel(), logResponse.LogLevel, "log level should have been the default")
    69  	assert.Nil(t, err, "Error should have been nil")
    70  }